-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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-5363: KIP-167 implementing bulk load, restoration event notification #3325
KAFKA-5363: KIP-167 implementing bulk load, restoration event notification #3325
Conversation
ping @mjsax @guozhangwang @enothereska @dguy for initial review This still need more test coverage, but I wanted to submit the PR to move the discussion forward. EDIT: The batch restoration benchmark will undergo some refactoring as well. EDIT round 2: Batch restoration benchmark will be in a follow in PR |
Refer to this link for build results (access rights to CI server needed): |
Fixing checkstyle errors |
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
addressing errors |
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
Error seems unrelated to this PR |
Refer to this link for build results (access rights to CI server needed): |
retest this please. |
I think the restore callbacks etc look good. My main question will be around the bulk loading part, i.e., if we go with batch loading, will we still be able to look into KAFKA-4868 or are they mutually exclusive? Thanks @bbejeck . |
Refer to this link for build results (access rights to CI server needed): |
@enothereska current plan is to have KAFKA-4868 be part of the bulk/batch loading in this PR |
Refer to this link for build results (access rights to CI server needed): |
retest this please. |
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
9170d0a
to
0f3b947
Compare
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
@enothereska - updated code to handle KAFKA-4868 EDIT: Still owe tests on this PR |
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
7bc4575
to
41a21af
Compare
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
Still owe tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more comments...
* across all {@link org.apache.kafka.streams.processor.internals.StreamThread} instances. | ||
* | ||
* Users desiring stateful operations will need to provide synchronization internally in | ||
* the StateRestorerListener implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit {@code StateRestorerListener}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
} | ||
|
||
|
||
private static final class NoOpStateRestoreListener implements StateRestoreListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this extend AbstractNotifyingRestoreCallback
to save all the boiler plate from below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will still have one no-op method, but I guess it's worth it as it does reduce the boilerplate some.
* or {@link StateRestoreCallback} instead for single action restores. | ||
*/ | ||
@Override | ||
public void restore(byte[] key, byte[] value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we introduce a global "one parameter per line" code style? I think it would help to make diffs cleaner. We can do this incrementally. If yes, please do for all newly introduced code of this PR.
Also, should be add final
all over the place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, can you add to the Steams guidelines?
/** | ||
* Method called at the very beginning of {@link StateStore} restoration. | ||
* | ||
* @param topicPartition the TopicPartition containing the values to restore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: parameter descriptions are no sentences, thus no .
at the end (on many other places, too). If we say they are sentences, they it should start with upper case [T]he TopicPartition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
} | ||
} | ||
|
||
private static final class NoOpStateRestoreCallback implements StateRestoreCallback { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this class won't be used anymore, so removed.
@@ -135,6 +140,10 @@ public void openDB(ProcessorContext context) { | |||
// (this could be a bug in the RocksDB code and their devs have been contacted). | |||
options.setIncreaseParallelism(Math.max(Runtime.getRuntime().availableProcessors(), 2)); | |||
|
|||
if (prepareForBulkload) { | |||
options.prepareForBulkLoad(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate?
@@ -254,6 +255,19 @@ public void testCannotStartTwice() throws Exception { | |||
} | |||
} | |||
|
|||
@Test(expected = IllegalStateException.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not expect
here and use fail
within try-catch
@@ -305,4 +327,24 @@ public ProcessorNode currentNode() { | |||
public void close() { | |||
metrics.close(); | |||
} | |||
|
|||
private static final class NoOpRestoreListener implements StateRestoreListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
rebasing now |
…es, adding state restore listener KAFKA-5363: updates per comments on KIP
…start and update end, updated RocksDB to be closed and opened during restores. Added adapter class for abstracting the callback implementations.
…and StateRestoreCallback
00d98c0
to
9b60972
Compare
@guozhangwang @mjsax |
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
ping @guozhangwang for final review and merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bbejeck Some more minor comments about code styles.
@@ -51,14 +57,30 @@ long checkpoint() { | |||
return checkpoint == null ? NO_CHECKPOINT : checkpoint; | |||
} | |||
|
|||
void restore(final byte[] key, final byte[] value) { | |||
stateRestoreCallback.restore(key, value); | |||
void notifyRestoreStarted(long startingOffset, long endingOffset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename this function to restoreStarted
to be consistent with other names. Such will help other code readers to understand these functions are for the same code granularity and semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
if (stateRestoreCallback instanceof StateRestoreListener) { | ||
storeRestoreListener = (StateRestoreListener) stateRestoreCallback; | ||
} else { | ||
storeRestoreListener = new NoOpStateRestoreListener(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment missed somehow? I think line 42 above could be storeRestoreListener = NO_OP_STATE_RESTORE_LISTENER
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, must have overlooked
|
||
public class MockStateRestoreListener extends AbstractNotifyingRestoreCallback { | ||
|
||
//Verifies store name called for each state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space after //
and we do not need capitalize the in-function comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
@@ -198,6 +220,11 @@ private RocksDB openDB(File dir, Options options, int ttl) throws IOException { | |||
} | |||
} | |||
|
|||
//Visible for testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto for in-function and simple top function comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
private final MockConsumer<byte[], byte[]> consumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST); | ||
private final StateRestoreListener stateRestoreListener = new MockStateRestoreListener(); | ||
private final StoreChangelogReader | ||
changelogReader = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: new lines are generally not recommended to break object type declaration with object name. For this specific line I think we can still make them in one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, need to adjust Intellij settings
@@ -56,7 +71,8 @@ public void shouldThrowStreamsExceptionWhenTimeoutExceptionThrown() throws Excep | |||
throw new TimeoutException("KABOOM!"); | |||
} | |||
}; | |||
final StoreChangelogReader changelogReader = new StoreChangelogReader(consumer, new MockTime(), 0); | |||
final StoreChangelogReader changelogReader = new StoreChangelogReader(consumer, new | |||
MockTime(), 0, stateRestoreListener); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: newline after keywords are generally not recommended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, same as above
private final byte[] value = "value".getBytes(Charset.forName("UTF-8")); | ||
private final Collection<KeyValue<byte[], byte[]>> records = Collections.singletonList(KeyValue.pair(key, value)); | ||
private final BatchingStateRestoreCallback wrappedBatchingStateRestoreCallback = new | ||
WrappedBatchingStateRestoreCallback(mockRestoreCallback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto for new line rules. Could you make a pass over all the newlines and see if they can be improved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
final StateRestoreCallback restoreCallback = restoreFuncs.get(storeName); | ||
for (final KeyValue<byte[], byte[]> entry : changeLog) { | ||
restoreCallback.restore(entry.key, entry.value); | ||
final StateRestoreListener restoreListener = (restoreCallback instanceof StateRestoreListener) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use the WrappedBatchingStateRestoreCallback
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
@@ -305,4 +328,12 @@ public ProcessorNode currentNode() { | |||
public void close() { | |||
metrics.close(); | |||
} | |||
|
|||
private static final class NoOpRestoreListener extends AbstractNotifyingBatchingRestoreCallback { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.apache.kafka.streams.processor.internals.NoOpStateRestoreListener
can be used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
@guozhangwang @mjsax updates per comments |
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
Merged to trunk. THanks @bbejeck ! |
No description provided.