Skip to content

Commit

Permalink
add protection to eager swap before consumer is fully subscribed
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacAttack committed Dec 5, 2024
1 parent 2020430 commit be888fb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ public CompletableFuture<Void> seekToEndOfPush(Set<Integer> partitions) {
});
}

public boolean subscribed() {
return isSubscribed.get();
}

@Override
protected CompletableFuture<Void> internalSeek(
Set<Integer> partitions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -106,6 +107,8 @@ public class VeniceChangelogConsumerImpl<K, V> implements VeniceChangelogConsume
protected final Map<Integer, Boolean> partitionToBootstrapState = new VeniceConcurrentHashMap<>();
protected final long startTimestamp;

protected final AtomicBoolean isSubscribed = new AtomicBoolean(false);

protected final RecordDeserializer<K> keyDeserializer;
private final D2ControllerClient d2ControllerClient;
private final RecordDeserializer<RecordChangeEvent> recordChangeDeserializer =
Expand Down Expand Up @@ -260,8 +263,9 @@ protected CompletableFuture<Void> internalSubscribe(Set<Integer> partitions, Pub
pubSubConsumer.subscribe(topicPartition, OffsetRecord.LOWEST_OFFSET);
currentVersionLastHeartbeat.put(topicPartition.getPartitionNumber(), System.currentTimeMillis());
}
return null;
}
isSubscribed.set(true);
return null;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class VersionSwapDataChangeListener<K, V> implements StoreDataChangedListener {
@Override
public void handleStoreChanged(Store store) {
// store may be null as this is called by other repair tasks
if (!consumer.subscribed()) {
// skip this for now as the consumer hasn't even been set up yet
return;
}
synchronized (this) {
Set<Integer> partitions = new HashSet<>();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ public void testAAIngestionWithStoreView() throws Exception {
.setControllerD2ServiceName(D2_SERVICE_NAME)
.setD2ServiceName(VeniceRouterWrapper.CLUSTER_DISCOVERY_D2_SERVICE_NAME)
.setLocalD2ZkHosts(localZkServer.getAddress())
.setControllerRequestRetryCount(3)
.setVersionSwapDetectionIntervalTimeInMs(10L);
.setControllerRequestRetryCount(3);
VeniceChangelogConsumerClientFactory veniceChangelogConsumerClientFactory =
new VeniceChangelogConsumerClientFactory(globalChangelogClientConfig, metricsRepository);

Expand Down

0 comments on commit be888fb

Please sign in to comment.