Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -107,10 +106,11 @@ public InputStatus pollNext(ReaderOutput output) throws Exception {

@Override
public List<HybridSourceSplit> snapshotState(long checkpointId) {
List<? extends SourceSplit> state =
currentReader != null
? currentReader.snapshotState(checkpointId)
: Collections.emptyList();
if (currentReader == null) {
return new ArrayList<>(restoredSplits);
}

List<? extends SourceSplit> state = currentReader.snapshotState(checkpointId);
return HybridSourceSplit.wrapSplits(state, currentSourceIndex, switchedSources);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,36 @@ void testReaderRecovery() throws Exception {
reader.close();
}

@Test
void testReaderRecoverySnapshotBeforeSwitchSourceEvent() throws Exception {
TestingReaderContext readerContext = new TestingReaderContext();
MockBaseSource source = new MockBaseSource(1, 1, Boundedness.BOUNDED);

HybridSourceReader<Integer> reader = new HybridSourceReader<>(readerContext);
reader.start();
assertAndClearSourceReaderFinishedEvent(readerContext, -1);
reader.handleSourceEvents(new SwitchSourceEvent(0, source, false));

MockSourceSplit mockSplit = new MockSourceSplit(0, 0, 2147483647);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Use Integer.MAX_VALUE rather than the magic literal 2147483647

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks. I switched this to Integer.MAX_VALUE and reran the focused HybridSourceReader test:

./mvnw -pl flink-connectors/flink-connector-base -DskipITs -Dtest=HybridSourceReaderTest#testReaderRecoverySnapshotBeforeSwitchSourceEvent -Dsurefire.failIfNoSpecifiedTests=false test

SwitchedSources switchedSources = new SwitchedSources();
switchedSources.put(0, source);
HybridSourceSplit hybridSplit = HybridSourceSplit.wrapSplit(mockSplit, 0, switchedSources);
reader.addSplits(Collections.singletonList(hybridSplit));
List<HybridSourceSplit> snapshot = reader.snapshotState(0);
reader.close();

readerContext.clearSentEvents();
HybridSourceReader<Integer> recoveredReader = new HybridSourceReader<>(readerContext);
recoveredReader.addSplits(snapshot);
recoveredReader.start();
assertThat(currentReader(recoveredReader)).isNull();

List<HybridSourceSplit> recoverySnapshot = recoveredReader.snapshotState(1);
assertThat(recoverySnapshot).containsExactly(hybridSplit);

recoveredReader.close();
}

@Test
void testReaderRecoveryInitializationOrder() throws Exception {
TestingReaderContext readerContext = new TestingReaderContext();
Expand Down