Skip to content

Commit 32c03ba

Browse files
authored
[changelog] Make changes for venice view consumption (#1497)
* [changelog] Make changes for venice view consumption These changes make it so that the venice after image consumer is able to now consume view topics. View topics internally very much resemble version topics, which the after image consumer understands today. So the logic is largely the same. The only difference we add here is that we now have to consult store repositories which are view aware, and we have to chnage how we maintain local highwatermark information. highwatermarks are meant to be compared on RT partitions, and new view types map 1:N and N:N RT partitions to view partitions. This means we need to add an additional dimensionality to highwatermark filtering where instead of keeping a single map of topic partitions to offsets, but a map of topic partitions to maps of RT partitions to highwatermarks. There's still some pending work here, we need to figure out chunk assembly (as the current implementation of chunk assembly doesn't account for interleaving writes) and we need to put a bow on how we articulate to the consumers what the upstream RT partition is (right now we're just hardcoding the 1:1 pairing).
1 parent bb092b9 commit 32c03ba

File tree

16 files changed

+380
-144
lines changed

16 files changed

+380
-144
lines changed

clients/da-vinci-client/src/main/java/com/linkedin/davinci/consumer/ChangelogClientConfig.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class ChangelogClientConfig<T extends SpecificRecord> {
1212
private Properties consumerProperties;
1313
private SchemaReader schemaReader;
1414
private String viewName;
15+
private Boolean isBeforeImageView = false;
1516

1617
private String consumerName = "";
1718

@@ -219,7 +220,17 @@ public static <V extends SpecificRecord> ChangelogClientConfig<V> cloneConfig(Ch
219220
.setRocksDBBlockCacheSizeInBytes(config.getRocksDBBlockCacheSizeInBytes())
220221
.setConsumerName(config.consumerName)
221222
.setDatabaseSyncBytesInterval(config.getDatabaseSyncBytesInterval())
222-
.setShouldCompactMessages(config.shouldCompactMessages());
223+
.setShouldCompactMessages(config.shouldCompactMessages())
224+
.setIsBeforeImageView(config.isBeforeImageView());
223225
return newConfig;
224226
}
227+
228+
protected Boolean isBeforeImageView() {
229+
return isBeforeImageView;
230+
}
231+
232+
public ChangelogClientConfig setIsBeforeImageView(Boolean beforeImageView) {
233+
isBeforeImageView = beforeImageView;
234+
return this;
235+
}
225236
}

clients/da-vinci-client/src/main/java/com/linkedin/davinci/consumer/InternalLocalBootstrappingVeniceChangelogConsumer.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.linkedin.venice.kafka.protocol.state.PartitionState;
3232
import com.linkedin.venice.kafka.protocol.state.StoreVersionState;
3333
import com.linkedin.venice.meta.PersistenceType;
34+
import com.linkedin.venice.meta.Store;
3435
import com.linkedin.venice.offsets.OffsetRecord;
3536
import com.linkedin.venice.pubsub.adapter.kafka.ApacheKafkaOffsetPosition;
3637
import com.linkedin.venice.pubsub.api.PubSubConsumerAdapter;
@@ -93,7 +94,8 @@ public InternalLocalBootstrappingVeniceChangelogConsumer(
9394
bootstrapStateMap = new VeniceConcurrentHashMap<>();
9495
syncBytesInterval = changelogClientConfig.getDatabaseSyncBytesInterval();
9596
metricsRepository = changelogClientConfig.getInnerClientConfig().getMetricsRepository();
96-
String localStateTopicNameTemp = changelogClientConfig.getStoreName() + LOCAL_STATE_TOPIC_SUFFIX;
97+
String viewNamePath = changelogClientConfig.getViewName() == null ? "" : "-" + changelogClientConfig.getViewName();
98+
String localStateTopicNameTemp = changelogClientConfig.getStoreName() + viewNamePath + LOCAL_STATE_TOPIC_SUFFIX;
9799
String bootstrapFileSystemPath = changelogClientConfig.getBootstrapFileSystemPath();
98100
if (StringUtils.isNotEmpty(consumerId)) {
99101
localStateTopicNameTemp += "-" + consumerId;
@@ -183,7 +185,8 @@ private Function<String, Boolean> functionToCheckWhetherStorageEngineShouldBeKep
183185
protected boolean handleVersionSwapControlMessage(
184186
ControlMessage controlMessage,
185187
PubSubTopicPartition pubSubTopicPartition,
186-
String topicSuffix) {
188+
String topicSuffix,
189+
Integer upstreamPartition) {
187190
ControlMessageType controlMessageType = ControlMessageType.valueOf(controlMessage);
188191
if (controlMessageType.equals(ControlMessageType.VERSION_SWAP)) {
189192
VersionSwap versionSwap = (VersionSwap) controlMessage.controlMessageUnion;
@@ -506,10 +509,9 @@ public CompletableFuture<Void> start(Set<Integer> partitions) {
506509

507510
storageService.start();
508511
try {
509-
storeRepository.start();
510512
storeRepository.subscribe(storeName);
511513
} catch (InterruptedException e) {
512-
throw new RuntimeException(e);
514+
throw new VeniceException("Failed to start bootstrapping changelog consumer with error:", e);
513515
}
514516

515517
return seekWithBootStrap(partitions);
@@ -518,7 +520,13 @@ public CompletableFuture<Void> start(Set<Integer> partitions) {
518520
@Override
519521
public CompletableFuture<Void> start() {
520522
Set<Integer> allPartitions = new HashSet<>();
521-
for (int partition = 0; partition < partitionCount; partition++) {
523+
try {
524+
storeRepository.subscribe(storeName);
525+
} catch (InterruptedException e) {
526+
throw new VeniceException("Failed to start bootstrapping changelog consumer with error:", e);
527+
}
528+
Store store = storeRepository.getStore(storeName);
529+
for (int partition = 0; partition < store.getVersion(store.getCurrentVersion()).getPartitionCount(); partition++) {
522530
allPartitions.add(partition);
523531
}
524532
return this.start(allPartitions);

clients/da-vinci-client/src/main/java/com/linkedin/davinci/consumer/VeniceAfterImageConsumerImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.linkedin.alpini.base.concurrency.Executors;
44
import com.linkedin.alpini.base.concurrency.ScheduledExecutorService;
5+
import com.linkedin.davinci.repository.NativeMetadataRepositoryViewAdapter;
56
import com.linkedin.venice.exceptions.VeniceException;
67
import com.linkedin.venice.kafka.protocol.ControlMessage;
78
import com.linkedin.venice.kafka.protocol.KafkaMessageEnvelope;
@@ -92,6 +93,11 @@ public CompletableFuture<Void> subscribe(Set<Integer> partitions) {
9293
if (partitions.isEmpty()) {
9394
return CompletableFuture.completedFuture(null);
9495
}
96+
try {
97+
storeRepository.subscribe(storeName);
98+
} catch (InterruptedException e) {
99+
throw new VeniceException("Failed to start bootstrapping changelog consumer with error:", e);
100+
}
95101
if (!versionSwapThreadScheduled.get()) {
96102
// schedule the version swap thread and set up the callback listener
97103
this.storeRepository.registerStoreDataChangedListener(versionSwapListener);
@@ -208,4 +214,10 @@ public void run() {
208214
versionSwapListener.handleStoreChanged(null);
209215
}
210216
}
217+
218+
@Override
219+
public void setStoreRepository(NativeMetadataRepositoryViewAdapter repository) {
220+
super.setStoreRepository(repository);
221+
versionSwapListener.setStoreRepository(repository);
222+
}
211223
}

clients/da-vinci-client/src/main/java/com/linkedin/davinci/consumer/VeniceChangelogConsumerClientFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public <K, V> VeniceChangelogConsumer<K, V> getChangelogConsumer(String storeNam
7878
String viewClass = getViewClass(newStoreChangelogClientConfig, storeName);
7979
String consumerName = suffixConsumerIdToStore(storeName + "-" + viewClass.getClass().getSimpleName(), consumerId);
8080
if (viewClass.equals(ChangeCaptureView.class.getCanonicalName())) {
81+
// TODO: This is a little bit of a hack. This is to deal with the an issue where the before image change
82+
// capture topic doesn't follow the same naming convention as view topics.
83+
newStoreChangelogClientConfig.setIsBeforeImageView(true);
8184
return new VeniceChangelogConsumerImpl(
8285
newStoreChangelogClientConfig,
8386
consumer != null

0 commit comments

Comments
 (0)