-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding retries to update the metadata store instead of failure #15141
Changes from 12 commits
f7220c1
31ae856
c428ada
5664dc1
adeec9b
da0731e
fbbcf47
5d2a34a
345bcb1
bda2b16
c3c0f71
8e4b2b1
53378dd
eca84d9
2a1ced1
484d654
3423ec7
b639e7d
88b8043
c0deff7
cafac9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,12 @@ | |
import org.apache.druid.java.util.common.IAE; | ||
|
||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
/** | ||
* Represents the end sequenceNumber per partition of a sequence. Note that end sequenceNumbers are always | ||
|
@@ -147,6 +149,37 @@ public SeekableStreamSequenceNumbers<PartitionIdType, SequenceOffsetType> plus( | |
} | ||
} | ||
|
||
@Override | ||
public int compareTo(SeekableStreamSequenceNumbers<PartitionIdType, SequenceOffsetType> other, Comparator<SequenceOffsetType> comparator) | ||
{ | ||
if (this.getClass() != other.getClass()) { | ||
throw new IAE( | ||
"Expected instance of %s, got %s", | ||
this.getClass().getName(), | ||
other.getClass().getName() | ||
); | ||
} | ||
|
||
final SeekableStreamEndSequenceNumbers<PartitionIdType, SequenceOffsetType> otherStart = | ||
(SeekableStreamEndSequenceNumbers<PartitionIdType, SequenceOffsetType>) other; | ||
|
||
if (stream.equals(otherStart.stream)) { | ||
//Same stream, compare the offset | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also please add a check to compare the partitions to account for repartitioning? |
||
AtomicReference<Boolean> res = new AtomicReference<>(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to change slightly according to https://github.com/apache/druid/pull/15141/files#r1375643913? |
||
partitionSequenceNumberMap.forEach( | ||
(partitionId, sequenceOffset) -> { | ||
if (otherStart.partitionSequenceNumberMap.get(partitionId) != null && comparator.compare(sequenceOffset, otherStart.partitionSequenceNumberMap.get(partitionId)) > 0) { | ||
res.set(true); | ||
} | ||
} | ||
); | ||
Pankaj260100 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (res.get()) { | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
@Override | ||
public SeekableStreamSequenceNumbers<PartitionIdType, SequenceOffsetType> minus( | ||
SeekableStreamSequenceNumbers<PartitionIdType, SequenceOffsetType> other | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; | ||
import org.apache.druid.indexing.overlord.DataSourceMetadata; | ||
|
||
import java.util.Comparator; | ||
import java.util.Map; | ||
|
||
@JsonTypeInfo(use = Id.NAME, property = "type", defaultImpl = SeekableStreamEndSequenceNumbers.class) | ||
|
@@ -61,4 +62,11 @@ SeekableStreamSequenceNumbers<PartitionIdType, SequenceOffsetType> plus( | |
SeekableStreamSequenceNumbers<PartitionIdType, SequenceOffsetType> minus( | ||
SeekableStreamSequenceNumbers<PartitionIdType, SequenceOffsetType> other | ||
); | ||
|
||
/** | ||
* Compare this and the other sequence offsets using comparator. | ||
* Returns 1, if this sequence is ahead of the other. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please elaborate what a sequence being ahead of the other means? I think that it means that the partition-wise sequence number of the first is greater than or equal to the other's with a strict greater than condition for at least one of the partitions. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AmatyaAvadhanula, We will only retry when the first is greater than the other's; in case both are equal, this will not fail to publish, So no point in retry, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it possible that when there are 10 partitions, 6 have strictly greater sequence numbers while the remaining 4 have equal sequence numbers because no new data was added to them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AmatyaAvadhanula, This case is covered. We will retry when atleast one partition sequence number is strictly greater than the other. We will compare all partition offsets, and if we find one of the partition offsets greater than the other offset, we update the res variable as true. And retry in that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering if it's possible that one partition is strictly greater but the other is strictly lower There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @AmatyaAvadhanula, as per our discussion I have added a check to verify task partitions are contained within the set in the metadata total set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have reverted this: the test case where a new kafka partition gets added and wants to publish for the first time will fail as it's not in the old committed offset. |
||
* otherwise, Return 0 | ||
*/ | ||
int compareTo(SeekableStreamSequenceNumbers<PartitionIdType, SequenceOffsetType> seekableStreamSequenceNumbers, Comparator<SequenceOffsetType> comparator); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2054,18 +2054,37 @@ protected DataStoreMetadataUpdateResult updateDataSourceMetadataWithHandle( | |
} | ||
|
||
final boolean startMetadataMatchesExisting; | ||
int startMetadataGreaterThanExisting = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be a boolean instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we can have a boolean. I have implemented the Comparable for compareTo() method and it returns int. so, I didn't change it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if (oldCommitMetadataFromDb == null) { | ||
startMetadataMatchesExisting = startMetadata.isValidStart(); | ||
startMetadataGreaterThanExisting = 1; | ||
} else { | ||
// Checking against the last committed metadata. | ||
// If the new start sequence number is greater than the end sequence number of last commit compareTo() function will return 1, | ||
// 0 in all other cases. It might be because multiple tasks are publishing the sequence at around same time. | ||
if (startMetadata instanceof Comparable) { | ||
startMetadataGreaterThanExisting = ((Comparable) startMetadata.asStartMetadata()).compareTo(oldCommitMetadataFromDb.asStartMetadata()); | ||
} | ||
|
||
// Converting the last one into start metadata for checking since only the same type of metadata can be matched. | ||
// Even though kafka/kinesis indexing services use different sequenceNumber types for representing | ||
// start and end sequenceNumbers, the below conversion is fine because the new start sequenceNumbers are supposed | ||
// to be same with end sequenceNumbers of the last commit. | ||
startMetadataMatchesExisting = startMetadata.asStartMetadata().matches(oldCommitMetadataFromDb.asStartMetadata()); | ||
} | ||
|
||
if (startMetadataGreaterThanExisting == 1 && !startMetadataMatchesExisting) { | ||
// Offset stored in StartMetadata is Greater than the last commited metadata, | ||
// Then retry multiple task might be trying to publish the segment for same partitions. | ||
|
||
return new DataStoreMetadataUpdateResult(true, true, StringUtils.format( | ||
"Failed to update the metadata Store. The new start metadata: [%s] is ahead of last commited end state: [%s].", | ||
startMetadata, | ||
oldCommitMetadataFromDb | ||
)); | ||
} | ||
|
||
if (!startMetadataMatchesExisting) { | ||
// Not in the desired start state. | ||
return new DataStoreMetadataUpdateResult(true, false, StringUtils.format( | ||
|
Check warning
Code scanning / CodeQL
Inconsistent compareTo Warning