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

MINOR: Remove 1 minute minimum segment interval #5323

Merged
merged 3 commits into from
Aug 1, 2018
Merged

MINOR: Remove 1 minute minimum segment interval #5323

merged 3 commits into from
Aug 1, 2018

Conversation

vvcephei
Copy link
Contributor

@vvcephei vvcephei commented Jul 3, 2018

  • new minimum is 0, just like window size
  • refactor tests to use smaller segment sizes as well

Committer Checklist (excluded from commit message)

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

Copy link
Contributor Author

@vvcephei vvcephei left a comment

Choose a reason for hiding this comment

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

Since the code change here is not too complicated, I've taken the liberty of additionally reformatting the tests for readability. I hope that's ok.

throw new IllegalArgumentException("windowSize cannot be negative");
}
if (segmentInterval < 60_000) {
throw new IllegalArgumentException("segmentInterval must be at least one minute");
if (segmentInterval < 0L) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I set the min to 0, following the other two bounds, but wouldn't 0 cause problems in practice? Should we instead set all three minima to 1?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest setting the min to 0 other than 1, because interval maybe used as denominator in some use cases?

@@ -38,6 +38,7 @@ public void shouldThrowIfPersistentKeyValueStoreStoreNameIsNull() {

@Test(expected = NullPointerException.class)
public void shouldThrowIfIMemoryKeyValueStoreStoreNameIsNull() {
//noinspection ResultOfMethodCallIgnored
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've also included some general cleanup of warnings.

public class CachingSessionStoreTest {

private static final int MAX_CACHE_SIZE_BYTES = 600;
private InternalMockProcessorContext context;
private static final Long DEFAULT_TIMESTAMP = 10L;
private static final long SEGMENT_INTERVAL = 100L;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I searched through the code base to find all the spots where we set the segment interval to 1 minute just because it was the min. I've set them all lower (typically to 100ms, because it's a nice round number) mostly to avoid implying that there's anything special about 60s anymore.

final Windowed<Bytes> a3 = new Windowed<>(keyA, new SessionWindow(120_000, 120_000));
final Windowed<Bytes> a1 = new Windowed<>(keyA, new SessionWindow(SEGMENT_INTERVAL * 0, SEGMENT_INTERVAL * 0));
final Windowed<Bytes> a2 = new Windowed<>(keyA, new SessionWindow(SEGMENT_INTERVAL * 1, SEGMENT_INTERVAL * 1));
final Windowed<Bytes> a3 = new Windowed<>(keyA, new SessionWindow(SEGMENT_INTERVAL * 2, SEGMENT_INTERVAL * 2));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In all the places where the test logic actually depends on the segment interval, I've expanded the expressions to include it. Theoretically, we should be able to plug in any number for the segment interval, and the tests should still pass.

@vvcephei
Copy link
Contributor Author

vvcephei commented Jul 3, 2018

@mjsax @guozhangwang

Here's the follow-up I promised in #5257 to de-magicify the minimum segment interval.

-John

Copy link
Contributor

@guozhangwang guozhangwang left a comment

Choose a reason for hiding this comment

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

@vvcephei is this PR complete already? The only non-test class included is Stores, but we have other classes to be considered, like minimumSegmentInterval in Windows, right?

@vvcephei
Copy link
Contributor Author

Hey @guozhangwang, Sorry about the slow reply.

I left that occurrence on purpose, as well as the one in RocksDbSessionBytesStoreSupplier.

The reasoning is that this change only lifts the restriction. It shouldn't change the actual segment size for any existing application.

If upgrading to 2.1 (no code change) caused a change in segment size, we would:
#1 have a compatibility problem, since Streams would interpret the segments it loads incorrectly
#2 potentially cause performance regressions, since we don't know if smaller segments will perform better or worse. It's safer just to leave it exactly as-is.

Stores is the only thing that changed because I only wanted to lift the restriction, and Stores was the only location that actually enforced the restriction.

@vvcephei
Copy link
Contributor Author

Also, about the minimum segmentInterval being 0 or 1 in stores, you were right: segmentInterval is used in the denominator, to determine the segmentId.

Maybe I misunderstood, but this seems like another good reason not to allow 0. Otherwise, it would throw a mysterious arithmetic exception instead of a nice(r) IllegalArgumentException.

Plus, it's evidence that no application could use a segmentInterval of 0.

I've updated the PR to set it to 1.

@vvcephei
Copy link
Contributor Author

@mjsax @guozhangwang : just renewing my request for reviews, since I let this PR rot for a week.

oldSegment.createNewFile();
}

segments.openExisting(context);

for (int segmentId = 0; segmentId < NUM_SEGMENTS; ++segmentId) {
final File newSegment = new File(storeDirectoryPath + File.separator + storeName + "." + segmentId * (retentionPeriod / (NUM_SEGMENTS - 1)));
final File newSegment = new File(storeDirectoryPath + File.separator + segments.segmentName(segmentId));
Copy link
Member

Choose a reason for hiding this comment

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

We should assemble the new format manually -- otherwise, if segmentName() is change accidentally, we would not notice.

* new minimum is 1ms
* refactor tests to use smaller segment sizes as well
@vvcephei
Copy link
Contributor Author

vvcephei commented Aug 1, 2018

@guozhangwang @mjsax : I believe I've addressed all your comments.

Copy link
Contributor

@guozhangwang guozhangwang left a comment

Choose a reason for hiding this comment

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

LGTM, waiting for jenkins to complete.

@guozhangwang guozhangwang merged commit 814fbe0 into apache:trunk Aug 1, 2018
@vvcephei vvcephei deleted the KAFKA-7080-2-refactor-min-segment-interval branch August 1, 2018 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants