showuon commented on a change in pull request #10894:
URL: https://github.com/apache/kafka/pull/10894#discussion_r654384769



##########
File path: 
streams/src/main/java/org/apache/kafka/streams/processor/internals/GlobalStateManagerImpl.java
##########
@@ -288,6 +288,22 @@ private void restoreState(final StateRestoreCallback 
stateRestoreCallback,
                 //  -> don't pass in `task.timeout.ms` to stay responsive if 
`KafkaStreams#close` gets called
                 final ConsumerRecords<byte[], byte[]> records = 
globalConsumer.poll(requestTimeoutPlusTaskTimeout);
                 if (records.isEmpty()) {
+                    // get consumer position to step over potential TX markers
+                    offset = retryUntilSuccessOrThrowOnTaskTimeout(
+                        () -> globalConsumer.position(topicPartition),
+                        String.format(

Review comment:
       I saw this `retryUntilSuccessOrThrowOnTaskTimeout` to get 
globalConsumer.position appear 3 times in this `restoreState` method. Could we 
extract them into a separate method? 

##########
File path: 
streams/src/test/java/org/apache/kafka/streams/integration/GlobalKTableEOSIntegrationTest.java
##########
@@ -314,13 +323,111 @@ public void shouldRestoreTransactionalMessages() throws 
Exception {
                 }
                 return result.equals(expected);
             },
-            30000L,
+            30_000L,
             () -> "waiting for initial values" +
                 "\n  expected: " + expected +
-                "\n  received: " + results
+                "\n  received: " + result
         );
     }
-    
+
+    @Test
+    public void shouldSkipOverTxMarkersOnRestore() throws Exception {
+        shouldSkipOverTxMarkersAndAbortedMessagesOnRestore(false);
+    }
+
+    @Test
+    public void shouldSkipOverAbortedMessagesOnRestore() throws Exception {
+        shouldSkipOverTxMarkersAndAbortedMessagesOnRestore(true);
+    }
+
+    private void shouldSkipOverTxMarkersAndAbortedMessagesOnRestore(final 
boolean appendAbortedMessages) throws Exception {
+        // records with key 1L, 2L, and 4L are written into partition-0
+        // record with key 3L is written into partition-1
+        produceInitialGlobalTableValues();
+
+        final String stateDir = 
streamsConfiguration.getProperty(StreamsConfig.STATE_DIR_CONFIG);
+        final File globalStateDir = new File(
+            stateDir
+                + File.separator
+                + 
streamsConfiguration.getProperty(StreamsConfig.APPLICATION_ID_CONFIG)
+                + File.separator
+                + "global");
+        assertTrue(globalStateDir.mkdirs());
+        final OffsetCheckpoint checkpoint = new OffsetCheckpoint(new 
File(globalStateDir, ".checkpoint"));
+
+        // set the checkpointed offset to the commit marker of partition-1
+        // even if `poll()` won't return any data for partition-1, we should 
still finish the restore
+        checkpoint.write(Collections.singletonMap(new 
TopicPartition(globalTableTopic, 1), 1L));
+
+        if (appendAbortedMessages) {
+            final AtomicReference<Exception> error = new AtomicReference<>();
+            startStreams(new StateRestoreListener() {
+                @Override
+                public void onRestoreStart(final TopicPartition topicPartition,
+                                           final String storeName,
+                                           final long startingOffset,
+                                           final long endingOffset) {
+                    // we need to write aborted messages only after we init 
the `highWatermark`
+                    // to move the `endOffset` beyond the `highWatermark
+                    //
+                    // we cannot write committed messages because we want to 
test the cast that
+                    // poll() returns no records

Review comment:
       typo: we want to test the **case** that poll() returns no records.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to