Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-17668: Clean-up LogCleaner#maxOverCleanerThreads and LogCleanerManager#maintainUncleanablePartitions #17390

Merged
merged 14 commits into from
Jan 19, 2025

Conversation

frankvicky
Copy link
Contributor

@frankvicky frankvicky commented Oct 7, 2024

JIRA: KAFKA-17668

Both methods can be rewrite by scala 2.13 methods

Since maxOverCleanerThreads does not have a corresponding unit test, I have added a unit test for it.
maintainUncleanablePartitions has been thoroughly tested in tests, so I simply replaced the old implementation with the new one.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@github-actions github-actions bot added core Kafka Broker small Small PRs labels Oct 7, 2024
@frankvicky frankvicky marked this pull request as draft November 14, 2024 14:23
@frankvicky frankvicky marked this pull request as ready for review November 14, 2024 14:23
@frankvicky
Copy link
Contributor Author

Hi @chia7712
Could you please take a look ?

Copy link
Member

@ijuma ijuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@ijuma
Copy link
Member

ijuma commented Jan 3, 2025

Since maxOverCleanerThreads does not have a corresponding unit test, I have added a unit test to ensure the result remains the same after replacing it with the new implementation.

I don't see a unit test in this PR.

@frankvicky
Copy link
Contributor Author

Hi @ijuma,
I previously wrote some unit tests for this PR (see ec74070).

However, I later decided to remove these tests as I realized they might not add much value.
The code being replaced is used by helper methods that are already well covered by existing test cases, which should provide sufficient testing coverage.
WDYT ?

@ijuma
Copy link
Member

ijuma commented Jan 15, 2025

Yes, that's reasonable.

@ijuma
Copy link
Member

ijuma commented Jan 15, 2025

Since maxOverCleanerThreads does not have a corresponding unit test, I have added a unit test to ensure the result remains the same after replacing it with the new implementation.

Please update this description then.

@ijuma
Copy link
Member

ijuma commented Jan 15, 2025

Ah, we do have a new unit test now - I'll review that.

import scala.collection.mutable


class ScalaCompatibilityTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test name isn't right. This is not about testing scala compatibility, it's about testing the relevant log cleaner method. Is there a test class where this test makes sense? If not, it's ok to add one, but the name should be about the thing being tested.

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankvicky thanks for this patch. Those classes have ut file already, so it would be better to add unit test for the changed methods as there are many existent help methods in the test file.

@@ -116,12 +116,11 @@ class LogCleaner(initialConfig: CleanerConfig,
private[log] val cleaners = mutable.ArrayBuffer[CleanerThread]()

/**
* scala 2.12 does not support maxOption so we handle the empty manually.
* @param f to compute the result
* @return the max value (int value) or 0 if there is no cleaner
*/
private def maxOverCleanerThreads(f: CleanerThread => Double): Int =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a unit test to LogCleanerTest?

@@ -533,21 +533,15 @@ private[log] class LogCleanerManager(val logDirs: Seq[File],
def maintainUncleanablePartitions(): Unit = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto. LogCleanerManagerTest is a good place :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maintainUncleanablePartitions is invoked by CleanerThread#doWork, which is a daemon thread. It has been ㄎwidely tested through integration tests and unit tests related to LogCleaner. IMHO, we can leverage these existing tests and don't need to write new ones.

@github-actions github-actions bot removed the small Small PRs label Jan 16, 2025
@github-actions github-actions bot added the small Small PRs label Jan 16, 2025
cleaner3.lastStats.bufferUtilization = 0.65d
cleaners += cleaner3

assertEquals(0, logCleaner.maxOverCleanerThreads(_.lastStats.bufferUtilization))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, can we also assert a non zero value?

Copy link
Contributor Author

@frankvicky frankvicky Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!
I have just added it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In reviewing this test, I noticed that I introduced a bug in #8783 that I round down the double value when updating metrics max-buffer-utilization-percent

I open https://issues.apache.org/jira/browse/KAFKA-18597 to fix it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I'll backport this one to 4.0 to make it easier to backport the bug fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, given the fix, perhaps we don't need the case where we set the bufferUtilization to larger numbers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, given the fix, perhaps we don't need the case where we set the bufferUtilization to larger numbers.

you are right. I copy your comment to #18627


val cleaner1 = new logCleaner.CleanerThread(1)
cleaner1.lastStats = new CleanerStats(time)
cleaner1.lastStats.bufferUtilization = 0.75d
Copy link
Member

@ijuma ijuma Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: d is not needed, 0.75 is already a double. Same for a few more cases below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 😸
I have removed the redundant d but still keep it for the integer.

Copy link
Member

@ijuma ijuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@ijuma ijuma merged commit 697cf64 into apache:trunk Jan 19, 2025
9 checks passed
@ijuma ijuma changed the title KAFKA-17668: Rewrite LogCleaner#maxOverCleanerThreads and LogCleanerManager#maintainUncleanablePartitions KAFKA-17668: Clean-up LogCleaner#maxOverCleanerThreads and LogCleanerManager#maintainUncleanablePartitions Jan 19, 2025
ijuma pushed a commit that referenced this pull request Jan 19, 2025
…Manager#maintainUncleanablePartitions (#17390)

Since maxOverCleanerThreads does not have a corresponding unit test,
I have added a unit test for it. maintainUncleanablePartitions has been
thoroughly tested in tests, so I simply replaced the old implementation
with the new one.

Reviewers: Ismael Juma <[email protected]>, Chia-Ping Tsai <[email protected]>
pranavt84 pushed a commit to pranavt84/kafka that referenced this pull request Jan 27, 2025
…Manager#maintainUncleanablePartitions (apache#17390)

Since maxOverCleanerThreads does not have a corresponding unit test,
I have added a unit test for it. maintainUncleanablePartitions has been
thoroughly tested in tests, so I simply replaced the old implementation
with the new one.

Reviewers: Ismael Juma <[email protected]>, Chia-Ping Tsai <[email protected]>
airlock-confluentinc bot pushed a commit to confluentinc/kafka that referenced this pull request Jan 27, 2025
…Manager#maintainUncleanablePartitions (apache#17390)

Since maxOverCleanerThreads does not have a corresponding unit test,
I have added a unit test for it. maintainUncleanablePartitions has been
thoroughly tested in tests, so I simply replaced the old implementation
with the new one.

Reviewers: Ismael Juma <[email protected]>, Chia-Ping Tsai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-approved core Kafka Broker small Small PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants