Package com.linkedin.davinci.consumer
Class VeniceChangelogConsumerDaVinciRecordTransformerImpl<K,V>
java.lang.Object
com.linkedin.davinci.consumer.VeniceChangelogConsumerDaVinciRecordTransformerImpl<K,V>
- All Implemented Interfaces:
StatefulVeniceChangelogConsumer<K,,V> VeniceChangelogConsumer<K,,V> AutoCloseable
public class VeniceChangelogConsumerDaVinciRecordTransformerImpl<K,V>
extends Object
implements StatefulVeniceChangelogConsumer<K,V>, VeniceChangelogConsumer<K,V>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass -
Constructor Summary
ConstructorsConstructorDescriptionVeniceChangelogConsumerDaVinciRecordTransformerImpl(ChangelogClientConfig changelogClientConfig, VeniceChangelogConsumerClientFactory veniceChangelogConsumerClientFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidclearPartitionState(Set<Integer> partitions) voidclose()Release the internal resources.Returns the timestamp of the last heartbeat received for each subscribed partition.intbooleanIndicates whether all subscribed partitions have caught up to the latest offset at the time of subscription.booleanvoidpause()Pause the client on all subscriptions.voidPause the client on all or subset of partitions this client is subscribed to.poll(long timeoutInMs) Polls for the next batch of change events.voidresume()Pause the client on all subscriptions.voidResume the client on all or a subset of partitions this client is subscribed to and has paused.Seek to the beginning of the push for subscribed partitions.seekToBeginningOfPush(Set<Integer> partitions) Seek to the beginning of the push for a set of partitions.seekToCheckpoint(Set<VeniceChangeCoordinate> checkpoints) Seek the provided checkpoints for the specified partitions.Seek to the end of the push for all subscribed partitions.seekToEndOfPush(Set<Integer> partitions) Seek to the end of the last push for a given set of partitions.Seek to the end of events which have been transmitted to Venice for all subscribed partitions.seekToTail(Set<Integer> partitions) Seek to the end of events which have been transmitted to Venice and start consuming new events.seekToTimestamp(Long timestamp) Seek to the specified timestamp for all subscribed partitions.seekToTimestamps(Map<Integer, Long> timestamps) Seek to the provided timestamps for the specified partitions based on wall clock time for when this message was processed by Venice and produced to change capture.protected voidsetBackgroundReporterThreadSleepIntervalSeconds(long interval) voidsetStartTimeout(long seconds) start()Subscribes to every partition for the Venice store.Starts the consumer by subscribing to the specified partitions.voidstop()Subscribe a set of partitions for a store to this VeniceChangelogConsumer, with the earliest position in the topic for each partition.Subscribe all partitions belonging to a specific store, with the earliest position in the topic for each partition.voidunsubscribe(Set<Integer> partitions) Stop ingesting messages from a set of partitions for a specific store.voidStop ingesting messages from all partitions.
-
Constructor Details
-
VeniceChangelogConsumerDaVinciRecordTransformerImpl
public VeniceChangelogConsumerDaVinciRecordTransformerImpl(ChangelogClientConfig changelogClientConfig, VeniceChangelogConsumerClientFactory veniceChangelogConsumerClientFactory)
-
-
Method Details
-
start
Description copied from interface:StatefulVeniceChangelogConsumerStarts the consumer by subscribing to the specified partitions. On restart, the client automatically resumes from the last checkpoint. On fresh start, it begins from the beginning of the topic or leverages blob transfer if available. The returned future completes when there is at least one message available to be polled. UseStatefulVeniceChangelogConsumer.isCaughtUp()to determine when all subscribed partitions have caught up to the latest offset.- Specified by:
startin interfaceStatefulVeniceChangelogConsumer<K,V> - Parameters:
partitions- Set of partition IDs to subscribe to. Pass empty set to subscribe to all partitions.- Returns:
- A future that completes when at least one message is available to poll.
-
start
Description copied from interface:StatefulVeniceChangelogConsumerSubscribes to every partition for the Venice store. SeeStatefulVeniceChangelogConsumer.start(Set)for more information.- Specified by:
startin interfaceStatefulVeniceChangelogConsumer<K,V>
-
stop
- Specified by:
stopin interfaceStatefulVeniceChangelogConsumer<K,V> - Throws:
Exception
-
getPartitionCount
public int getPartitionCount()- Specified by:
getPartitionCountin interfaceVeniceChangelogConsumer<K,V> - Returns:
- total number of store partitions
-
subscribe
Description copied from interface:VeniceChangelogConsumerSubscribe a set of partitions for a store to this VeniceChangelogConsumer, with the earliest position in the topic for each partition. The VeniceChangelogConsumer should try to consume messages from all partitions that are subscribed to it.- Specified by:
subscribein interfaceVeniceChangelogConsumer<K,V> - Parameters:
partitions- the set of partition to subscribe and consume- Returns:
- a future which completes when data from the partitions are ready to be consumed
-
subscribeAll
Description copied from interface:VeniceChangelogConsumerSubscribe all partitions belonging to a specific store, with the earliest position in the topic for each partition.- Specified by:
subscribeAllin interfaceVeniceChangelogConsumer<K,V> - Returns:
- a future which completes when all partitions are ready to be consumed data
-
unsubscribe
Description copied from interface:VeniceChangelogConsumerStop ingesting messages from a set of partitions for a specific store.- Specified by:
unsubscribein interfaceVeniceChangelogConsumer<K,V> - Parameters:
partitions- The set of topic partitions to unsubscribe
-
unsubscribeAll
public void unsubscribeAll()Description copied from interface:VeniceChangelogConsumerStop ingesting messages from all partitions.- Specified by:
unsubscribeAllin interfaceVeniceChangelogConsumer<K,V>
-
seekToBeginningOfPush
Description copied from interface:VeniceChangelogConsumerSeek to the beginning of the push for a set of partitions. This is analogous to doing a bootstrap of data for the consumer. This seek will ONLY seek to the beginning of the version which is currently serving data, and the consumer will switch to reading data from a new version (should one get created) once it has read up to the point in the change capture stream that indicates the version swap (which can only occur after consuming all the data in the last push). This instructs the consumer to consume data from the batch push.- Specified by:
seekToBeginningOfPushin interfaceVeniceChangelogConsumer<K,V> - Parameters:
partitions- the set of partitions to seek with- Returns:
- a future which completes when the operation has succeeded for all partitions.
-
seekToBeginningOfPush
Description copied from interface:VeniceChangelogConsumerSeek to the beginning of the push for subscribed partitions. SeeVeniceChangelogConsumer.seekToBeginningOfPush(Set)for more information.- Specified by:
seekToBeginningOfPushin interfaceVeniceChangelogConsumer<K,V> - Returns:
- a future which completes when the partitions are ready to be consumed data
-
seekToEndOfPush
Description copied from interface:VeniceChangelogConsumerSeek to the end of the last push for a given set of partitions. This instructs the consumer to begin consuming events which are transmitted to Venice following the last batch push.- Specified by:
seekToEndOfPushin interfaceVeniceChangelogConsumer<K,V> - Parameters:
partitions- the set of partitions to seek with- Returns:
- a future which completes when the operation has succeeded for all partitions.
-
seekToEndOfPush
Description copied from interface:VeniceChangelogConsumerSeek to the end of the push for all subscribed partitions. SeeVeniceChangelogConsumer.seekToEndOfPush(Set)for more information.- Specified by:
seekToEndOfPushin interfaceVeniceChangelogConsumer<K,V> - Returns:
- a future which completes when the operation has succeeded for all partitions.
-
seekToTail
Description copied from interface:VeniceChangelogConsumerSeek to the end of events which have been transmitted to Venice and start consuming new events. This will ONLY consume events transmitted via nearline and incremental push. It will not read batch push data.- Specified by:
seekToTailin interfaceVeniceChangelogConsumer<K,V> - Parameters:
partitions- the set of partitions to seek with- Returns:
- a future which completes when the operation has succeeded for all partitions.
-
seekToTail
Description copied from interface:VeniceChangelogConsumerSeek to the end of events which have been transmitted to Venice for all subscribed partitions. SeeVeniceChangelogConsumer.seekToTail(Set)for more information.- Specified by:
seekToTailin interfaceVeniceChangelogConsumer<K,V> - Returns:
- a future which completes when the operation has succeeded for all partitions.
-
seekToCheckpoint
Description copied from interface:VeniceChangelogConsumerSeek the provided checkpoints for the specified partitions. Note about checkpoints: Checkpoints have the following properties and should be considered: - Checkpoints are NOT comparable or valid across partitions. - Checkpoints are NOT comparable or valid across regions - Checkpoints are NOT comparable across store versions - It is not possible to determine the number of events between two checkpoints - It is possible that a checkpoint is no longer on retention. In such case, we will return an exception to the caller.- Specified by:
seekToCheckpointin interfaceVeniceChangelogConsumer<K,V> - Returns:
- a future which completes when seek has completed for all partitions
-
seekToTimestamps
Description copied from interface:VeniceChangelogConsumerSeek to the provided timestamps for the specified partitions based on wall clock time for when this message was processed by Venice and produced to change capture. Note, this API can only be used to seek on nearline data applied to the current serving version in Venice. This will not seek on data transmitted via Batch Push. If the provided timestamp is lower than the earliest timestamp on a given stream, the earliest event will be returned. THIS WILL NOT SEEK TO DATA WHICH WAS APPLIED ON A PREVIOUS VERSION. You should never seek back in time to a timestamp which is smaller than the current time - rewindTimeInSeconds configured in the hybrid settings for this Venice store. The timestamp passed to this function should be associated to timestamps processed by this interface. The timestamp returned byPubSubMessage.getPubSubMessageTime()refers to the time when Venice processed the event, and calls to this method will seek based on that sequence of events. Note: it bears no relation to timestamps provided by upstream producers when writing to Venice where a user may optionally provide a timestamp at time of producing a record.- Specified by:
seekToTimestampsin interfaceVeniceChangelogConsumer<K,V> - Parameters:
timestamps- a map keyed by a partition ID, and the timestamp checkpoints to seek for each partition.- Returns:
-
seekToTimestamp
Description copied from interface:VeniceChangelogConsumerSeek to the specified timestamp for all subscribed partitions. SeeVeniceChangelogConsumer.seekToTimestamps(Map)for more information.- Specified by:
seekToTimestampin interfaceVeniceChangelogConsumer<K,V> - Returns:
- a future which completes when the operation has succeeded for all partitions.
-
pause
Description copied from interface:VeniceChangelogConsumerPause the client on all or subset of partitions this client is subscribed to. Calls toVeniceChangelogConsumer.poll(long)will not return results from paused partitions untilVeniceChangelogConsumer.resume(Set)is called again later for those partitions.- Specified by:
pausein interfaceVeniceChangelogConsumer<K,V>
-
pause
public void pause()Description copied from interface:VeniceChangelogConsumerPause the client on all subscriptions. SeeVeniceChangelogConsumer.pause(Set)for more information.- Specified by:
pausein interfaceVeniceChangelogConsumer<K,V>
-
resume
Description copied from interface:VeniceChangelogConsumerResume the client on all or a subset of partitions this client is subscribed to and has paused.- Specified by:
resumein interfaceVeniceChangelogConsumer<K,V>
-
resume
public void resume()Description copied from interface:VeniceChangelogConsumerPause the client on all subscriptions. SeeVeniceChangelogConsumer.resume(Set)for more information.- Specified by:
resumein interfaceVeniceChangelogConsumer<K,V>
-
close
public void close()Description copied from interface:VeniceChangelogConsumerRelease the internal resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceVeniceChangelogConsumer<K,V>
-
poll
Description copied from interface:StatefulVeniceChangelogConsumerPolls for the next batch of change events. The first records returned after callingStatefulVeniceChangelogConsumer.start(Set)will be from the local compacted state. Once the local state is fully consumed, subsequent calls will return real-time updates made to the Venice store. Records are returned in batches up to the configured MAX_BUFFER_SIZE. This method will return immediately if: 1. The buffer reaches MAX_BUFFER_SIZE before the timeout expires, OR 2. The timeout is reached NOTE: If the PubSubMessage came from disk (after restart), the following fields will be set to sentinel values since record metadata information is not persisted to reduce disk utilization: - PubSubMessageTime - Position- Specified by:
pollin interfaceStatefulVeniceChangelogConsumer<K,V> - Specified by:
pollin interfaceVeniceChangelogConsumer<K,V> - Parameters:
timeoutInMs- Maximum timeout of the poll invocation in milliseconds- Returns:
- A collection of Venice PubSubMessages containing change events
-
isCaughtUp
public boolean isCaughtUp()Description copied from interface:StatefulVeniceChangelogConsumerIndicates whether all subscribed partitions have caught up to the latest offset at the time of subscription. Once this becomes true, it will remain true even if the consumer begins to lag later on. This is for determining when the initial bootstrap phase has completed and the consumer has transitioned to consuming real-time events.- Specified by:
isCaughtUpin interfaceStatefulVeniceChangelogConsumer<K,V> - Specified by:
isCaughtUpin interfaceVeniceChangelogConsumer<K,V> - Returns:
- True if all subscribed partitions have caught up to their target offsets.
-
getRecordTransformerConfig
-
getLastHeartbeatPerPartition
Description copied from interface:StatefulVeniceChangelogConsumerReturns the timestamp of the last heartbeat received for each subscribed partition. Heartbeats are messages sent every minute by Venice servers to measure lag.- Specified by:
getLastHeartbeatPerPartitionin interfaceStatefulVeniceChangelogConsumer<K,V> - Specified by:
getLastHeartbeatPerPartitionin interfaceVeniceChangelogConsumer<K,V> - Returns:
- a map of partition number to the timestamp, in milliseconds, of the last heartbeat received for that partition.
-
setBackgroundReporterThreadSleepIntervalSeconds
protected void setBackgroundReporterThreadSleepIntervalSeconds(long interval) -
clearPartitionState
-
isStarted
public boolean isStarted() -
getSubscribedPartitions
-
setStartTimeout
public void setStartTimeout(long seconds)
-