Caideyipi commented on code in PR #18399:
URL: https://github.com/apache/iotdb/pull/18399#discussion_r3734762179
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java:
##########
@@ -3192,6 +3305,84 @@ private LiveWALMetaDataSnapshot(final long versionId,
final WALMetaData metadata
}
}
+ static final class WalFileCommitRequirement {
+
+ private final Map<WriterId, WriterProgress> requiredWriterProgress;
+ private final boolean containsUnsupportedProgress;
+
+ private WalFileCommitRequirement(
+ final Map<WriterId, WriterProgress> requiredWriterProgress,
+ final boolean containsUnsupportedProgress) {
+ this.requiredWriterProgress = requiredWriterProgress;
+ this.containsUnsupportedProgress = containsUnsupportedProgress;
+ }
+
+ static WalFileCommitRequirement fromMetadata(
+ final String regionId, final WALMetaData metadata) {
+ if (Objects.isNull(metadata)) {
+ return new WalFileCommitRequirement(Collections.emptyMap(), true);
+ }
+
+ final List<Integer> buffersSize = metadata.getBuffersSize();
+ final List<Long> physicalTimes = metadata.getPhysicalTimes();
+ final List<Short> nodeIds = metadata.getNodeIds();
+ final List<Long> localSeqs = metadata.getLocalSeqs();
+ if (physicalTimes.size() < buffersSize.size()
+ || nodeIds.size() < buffersSize.size()
+ || localSeqs.size() < buffersSize.size()) {
+ return new WalFileCommitRequirement(Collections.emptyMap(), true);
+ }
+
+ final Map<WriterId, WriterProgress> requiredWriterProgress = new
LinkedHashMap<>();
+ for (int i = 0; i < buffersSize.size(); i++) {
+ final int writerNodeId = nodeIds.get(i);
+ final long physicalTime = physicalTimes.get(i);
+ final long localSeq = localSeqs.get(i);
+ if (writerNodeId < 0 && physicalTime == 0L && localSeq < 0L) {
+ // Non-search WAL entries do not participate in subscription
progress.
+ continue;
+ }
+ if (writerNodeId < 0 || physicalTime < 0L || localSeq < 0L) {
+ // Legacy or incomplete writer metadata cannot be compared safely
with RegionProgress.
+ return new WalFileCommitRequirement(Collections.emptyMap(), true);
+ }
+
+ final WriterId writerId = new WriterId(regionId, writerNodeId);
+ final WriterProgress candidateProgress = new
WriterProgress(physicalTime, localSeq);
+ requiredWriterProgress.merge(
+ writerId,
+ candidateProgress,
+ (currentProgress, candidate) ->
+ compareProgress(candidate, currentProgress) > 0 ? candidate :
currentProgress);
+ }
+ return new WalFileCommitRequirement(requiredWriterProgress, false);
+ }
+
+ boolean isCoveredBy(final RegionProgress committedRegionProgress) {
+ if (containsUnsupportedProgress ||
Objects.isNull(committedRegionProgress)) {
+ return false;
+ }
+ for (final Map.Entry<WriterId, WriterProgress> entry :
requiredWriterProgress.entrySet()) {
+ final WriterProgress committedWriterProgress =
+ committedRegionProgress.getWriterPositions().get(entry.getKey());
+ if (Objects.isNull(committedWriterProgress)
+ || compareProgress(committedWriterProgress, entry.getValue()) < 0)
{
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static int compareProgress(
+ final WriterProgress leftProgress, final WriterProgress rightProgress)
{
+ final int physicalTimeComparison =
+ Long.compare(leftProgress.getPhysicalTime(),
rightProgress.getPhysicalTime());
+ return physicalTimeComparison != 0
+ ? physicalTimeComparison
+ : Long.compare(leftProgress.getLocalSeq(),
rightProgress.getLocalSeq());
+ }
+ }
Review Comment:
WriterProgress is a payload value class and does not expose compareTo. The
queue intentionally keeps compareProgress local so the ordering (physical time,
then local sequence) is explicit and is shared by all retention checks. No
behavior change is needed here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]