-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[beam] VeniceChangelogConsumerIO for Apache Beam integration (#1300)
Introduced new VeniceChangelogConsumerIO and related classes so that Apache Beam stream processing jobs can consume the Venice changelog. This code is added in a new integrations:venice-beam module.
- Loading branch information
Showing
12 changed files
with
913 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
dependencies { | ||
implementation(project(':internal:venice-common')) { | ||
exclude module: 'kafka_2.10' | ||
exclude group: 'org.scala-lang' | ||
} | ||
implementation project(':clients:da-vinci-client') | ||
implementation project(':clients:venice-thin-client') | ||
implementation project(':clients:venice-client') | ||
|
||
implementation libraries.log4j2api | ||
implementation libraries.log4j2core | ||
|
||
implementation libraries.beamSdk | ||
implementation libraries.beamExtensionAvro | ||
} | ||
|
||
ext { | ||
// to be tested in integration test | ||
jacocoCoverageThreshold = 0.00 | ||
} |
34 changes: 34 additions & 0 deletions
34
...ons/venice-beam/src/main/java/com/linkedin/venice/beam/consumer/CheckPointProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.linkedin.venice.beam.consumer; | ||
|
||
import com.linkedin.davinci.consumer.VeniceChangeCoordinate; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
|
||
/** | ||
* Properties used by {@link com.linkedin.davinci.consumer.VeniceChangelogConsumer} to seek | ||
* checkpoints. | ||
*/ | ||
public class CheckPointProperties { | ||
private Set<VeniceChangeCoordinate> coordinates; | ||
private long seekTimestamp; | ||
private String store; | ||
|
||
public CheckPointProperties(Set<VeniceChangeCoordinate> coordinates, long seekTimestamp, String store) { | ||
this.coordinates = coordinates; | ||
this.seekTimestamp = seekTimestamp; | ||
this.store = Objects.requireNonNull(store); | ||
} | ||
|
||
public Set<VeniceChangeCoordinate> getCoordinates() { | ||
return coordinates; | ||
} | ||
|
||
public long getSeekTimestamp() { | ||
return seekTimestamp; | ||
} | ||
|
||
public String getStore() { | ||
return store; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...src/main/java/com/linkedin/venice/beam/consumer/LocalVeniceChangelogConsumerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.linkedin.venice.beam.consumer; | ||
|
||
import com.linkedin.davinci.consumer.VeniceChangelogConsumer; | ||
import com.linkedin.davinci.consumer.VeniceChangelogConsumerClientFactory; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
||
|
||
/** Provides a configured {@link VeniceChangelogConsumer} instance. */ | ||
public class LocalVeniceChangelogConsumerProvider<K, V> implements VeniceChangelogConsumerProvider<K, V> { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final Class<? extends VeniceChangelogConsumerClientFactory> _veniceChangelogConsumerClientFactoryClass; | ||
|
||
public LocalVeniceChangelogConsumerProvider( | ||
Class<? extends VeniceChangelogConsumerClientFactory> veniceChangelogConsumerClientFactoryClass) { | ||
_veniceChangelogConsumerClientFactoryClass = veniceChangelogConsumerClientFactoryClass; | ||
} | ||
|
||
@Override | ||
public VeniceChangelogConsumer<K, V> getVeniceChangelogConsumer(String storeName) | ||
throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { | ||
VeniceChangelogConsumerClientFactory veniceChangelogConsumerClientFactory = | ||
this._veniceChangelogConsumerClientFactoryClass.getDeclaredConstructor().newInstance(); | ||
return veniceChangelogConsumerClientFactory.getChangelogConsumer(storeName); | ||
} | ||
|
||
@Override | ||
public VeniceChangelogConsumer<K, V> getVeniceChangelogConsumer(String storeName, String consumerId) | ||
throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { | ||
VeniceChangelogConsumerClientFactory veniceChangelogConsumerClientFactory = | ||
this._veniceChangelogConsumerClientFactoryClass.getDeclaredConstructor().newInstance(); | ||
return veniceChangelogConsumerClientFactory.getChangelogConsumer(storeName, consumerId); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...tions/venice-beam/src/main/java/com/linkedin/venice/beam/consumer/PubSubMessageCoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.linkedin.venice.beam.consumer; | ||
|
||
import com.linkedin.davinci.consumer.ChangeEvent; | ||
import com.linkedin.davinci.consumer.VeniceChangeCoordinate; | ||
import com.linkedin.venice.pubsub.api.PubSubMessage; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import javax.annotation.Nonnull; | ||
import org.apache.beam.sdk.coders.Coder; | ||
import org.apache.beam.sdk.coders.StructuredCoder; | ||
import org.apache.beam.sdk.extensions.avro.coders.AvroCoder; | ||
import org.apache.beam.sdk.values.TypeDescriptor; | ||
|
||
|
||
/** Uses {@link AvroCoder} to encode/decode {@link PubSubMessage}s. */ | ||
public class PubSubMessageCoder<K, V> | ||
extends StructuredCoder<PubSubMessage<K, ChangeEvent<V>, VeniceChangeCoordinate>> { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final AvroCoder<PubSubMessage<K, ChangeEvent<V>, VeniceChangeCoordinate>> pubSubMessageAvroCoder = | ||
AvroCoder.of(new TypeDescriptor<PubSubMessage<K, ChangeEvent<V>, VeniceChangeCoordinate>>() { | ||
}); | ||
|
||
public static <K, V> PubSubMessageCoder<K, V> of() { | ||
return new PubSubMessageCoder<>(); | ||
} | ||
|
||
@Override | ||
public void encode(PubSubMessage<K, ChangeEvent<V>, VeniceChangeCoordinate> value, @Nonnull OutputStream outStream) | ||
throws IOException { | ||
pubSubMessageAvroCoder.encode(value, outStream); | ||
} | ||
|
||
@Override | ||
public PubSubMessage<K, ChangeEvent<V>, VeniceChangeCoordinate> decode(@Nonnull InputStream inStream) | ||
throws IOException { | ||
return pubSubMessageAvroCoder.decode(inStream); | ||
} | ||
|
||
@Override | ||
public @Nonnull List<? extends Coder<?>> getCoderArguments() { | ||
return Collections.singletonList(pubSubMessageAvroCoder); | ||
} | ||
|
||
@Override | ||
public void verifyDeterministic() { | ||
} | ||
} |
Oops, something went wrong.