Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -254,7 +254,7 @@ void testReaderRecovery() throws Exception {
assertAndClearSourceReaderFinishedEvent(readerContext, -1);
reader.handleSourceEvents(new SwitchSourceEvent(0, source, false));

MockSourceSplit mockSplit = new MockSourceSplit(0, 0, 2147483647);
MockSourceSplit mockSplit = new MockSourceSplit(0, 0, Integer.MAX_VALUE);

SwitchedSources switchedSources = new SwitchedSources();
switchedSources.put(0, source);
Expand Down 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, Integer.MAX_VALUE);
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 All @@ -293,7 +323,7 @@ void testReaderRecoveryInitializationOrder() throws Exception {
assertAndClearSourceReaderFinishedEvent(readerContext, -1);
reader.handleSourceEvents(new SwitchSourceEvent(0, source, false));

MockSourceSplit mockSplit = new MockSourceSplit(0, 0, 2147483647);
MockSourceSplit mockSplit = new MockSourceSplit(0, 0, Integer.MAX_VALUE);
SwitchedSources switchedSources = new SwitchedSources();
switchedSources.put(0, source);
HybridSourceSplit hybridSplit = HybridSourceSplit.wrapSplit(mockSplit, 0, switchedSources);
Expand Down