Package com.linkedin.davinci.validation
Class DataIntegrityValidator
java.lang.Object
com.linkedin.davinci.validation.DataIntegrityValidator
Colloquially known as DIV (Data Integrity Validator).
This class is a library that can validate the topic message during consumption, which can be used in
Venice-Server/Da-Vinci and ETL. In high level, it keeps track of messages produced by different producers,
and validates data integrity in 4 perspectives:
1. Whether a segment starts from a non-zero sequence number (UNREGISTERED_PRODUCER);
2. Whether there is a gap between segments or within a segment (MISSING);
3. Whether data within a segment is corrupted (CORRUPT);
4. Whether producers have produced duplicate messages, which is fine and expected due to producer retries (DUPLICATE).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
protected final IntFunction<PartitionTracker>
protected final SparseConcurrentList<PartitionTracker>
Keeps track of every upstream producer this consumer task has seen so far for each partition. -
Constructor Summary
ConstructorsConstructorDescriptionDataIntegrityValidator
(String topicName) DataIntegrityValidator
(String topicName, long logCompactionDelayInMs) This constructor is used by a proprietary ETL project.DataIntegrityValidator
(String topicName, long logCompactionDelayInMs, long maxAgeInMs) -
Method Summary
Modifier and TypeMethodDescriptionvoid
checkMissingMessage
(DefaultPubSubMessage consumerRecord, Optional<PartitionTracker.DIVErrorMetricCallback> errorMetricCallback) Only check for missing sequence number; segment starting from a positive sequence number is acceptable considering real-time buffer replay would start in the middle of a segment; checksum is also ignored for the same reason.void
clearPartition
(int partition) In some cases, such as when resetting offsets or unsubscribing from a partition, thePartitionTracker
should forget about the state that it accumulated for a given partition.cloneRtProducerStates
(int partition, String brokerUrl) Returns the RT DIV state for a given partition and broker URL pair.cloneVtProducerStates
(int partition) Returns the VT DIV state and latest consumed vt offset for a given partition.void
cloneVtProducerStates
(int partition, DataIntegrityValidator newValidator) void
setPartitionState
(PartitionTracker.TopicType type, int partition, OffsetRecord offsetRecord) void
setPartitionState
(PartitionTracker.TopicType type, int partition, Map<CharSequence, ProducerPartitionState> producerPartitionStateMap) void
updateLatestConsumedVtOffset
(int partition, long offset) void
updateOffsetRecordForPartition
(PartitionTracker.TopicType type, int partition, OffsetRecord offsetRecord) For a given partition, find all the producers that has written to this partition and update the offsetRecord using segment information.void
validateMessage
(PartitionTracker.TopicType type, DefaultPubSubMessage consumerRecord, boolean endOfPushReceived, Lazy<Boolean> tolerateMissingMsgs) Run a thorough DIV check on the message, including UNREGISTERED_PRODUCER, MISSING, CORRUPT and DUPLICATE.
-
Field Details
-
DISABLED
public static final long DISABLED- See Also:
-
partitionTrackers
Keeps track of every upstream producer this consumer task has seen so far for each partition. -
partitionTrackerCreator
-
-
Constructor Details
-
DataIntegrityValidator
-
DataIntegrityValidator
This constructor is used by a proprietary ETL project. Do not clean up (yet)! TODO: Open source the ETL or make it stop depending on an exotic open source API -
DataIntegrityValidator
-
-
Method Details
-
clearPartition
public void clearPartition(int partition) In some cases, such as when resetting offsets or unsubscribing from a partition, thePartitionTracker
should forget about the state that it accumulated for a given partition.- Parameters:
partition
- to clear state for
-
setPartitionState
public void setPartitionState(PartitionTracker.TopicType type, int partition, OffsetRecord offsetRecord) -
setPartitionState
public void setPartitionState(PartitionTracker.TopicType type, int partition, Map<CharSequence, ProducerPartitionState> producerPartitionStateMap) -
validateMessage
public void validateMessage(PartitionTracker.TopicType type, DefaultPubSubMessage consumerRecord, boolean endOfPushReceived, Lazy<Boolean> tolerateMissingMsgs) throws DataValidationException Run a thorough DIV check on the message, including UNREGISTERED_PRODUCER, MISSING, CORRUPT and DUPLICATE.- Throws:
DataValidationException
-
updateOffsetRecordForPartition
public void updateOffsetRecordForPartition(PartitionTracker.TopicType type, int partition, OffsetRecord offsetRecord) For a given partition, find all the producers that has written to this partition and update the offsetRecord using segment information. Prior to this, the state which is expired according tomaxAgeInMs
will be cleared.- Parameters:
partition
- to extract info foroffsetRecord
- to modify
-
cloneVtProducerStates
-
cloneRtProducerStates
Returns the RT DIV state for a given partition and broker URL pair. -
cloneVtProducerStates
Returns the VT DIV state and latest consumed vt offset for a given partition. -
checkMissingMessage
public void checkMissingMessage(DefaultPubSubMessage consumerRecord, Optional<PartitionTracker.DIVErrorMetricCallback> errorMetricCallback) throws DataValidationException Only check for missing sequence number; segment starting from a positive sequence number is acceptable considering real-time buffer replay would start in the middle of a segment; checksum is also ignored for the same reason. If missing message happens for an old message that is older than the log compaction lag threshold, MISSING exception will not be thrown because it's expected that log compaction would compact old messages. However, if data are fresh and missing message is detected, MISSING exception will be thrown. This API is used by a proprietary ETL project. Do not clean up (yet)! TODO: Open source the ETL or make it stop depending on an exotic open source API- Throws:
DataValidationException
-
updateLatestConsumedVtOffset
public void updateLatestConsumedVtOffset(int partition, long offset)
-