Skip to content

[Subscription] Protect retained WAL by committed progress - #18399

Open
Caideyipi wants to merge 1 commit into
apache:masterfrom
Caideyipi:fix/subscription-wal-retention-committed-progress
Open

[Subscription] Protect retained WAL by committed progress#18399
Caideyipi wants to merge 1 commit into
apache:masterfrom
Caideyipi:fix/subscription-wal-retention-committed-progress

Conversation

@Caideyipi

Copy link
Copy Markdown
Collaborator

Description

Retain WAL required by uncommitted consumers

Previously, subscription WAL reclamation only considered replication progress and Topic retention policies. Consumer-group committed progress was not part of the deletion boundary, so retention could reclaim WAL still required by a lagging consumer.

This PR derives a file-level retained WAL version for each (consumerGroup, topic, region) queue from its per-writer committed RegionProgress. IoTConsensus combines these boundaries with Topic size/time retention and uses the most conservative boundary.

Multi-writer and leader migration handling

Committed progress remains represented by (physicalTime, writerNodeId, localSeq) rather than local searchIndex. Rolled WAL V3 metadata is summarized per writer, allowing follower WAL records and records produced before leader migration to be protected correctly.

WAL files with incomplete or unsupported writer metadata are conservatively retained.

Boundary refresh and caching

The committed WAL boundary is refreshed after ACK, direct commit, initialization, seek, committed-progress broadcast, or WAL roll. Per-file writer-progress requirements are cached so repeated safe-delete checks do not repeatedly scan unchanged WAL metadata.


This PR has:

  • been self-reviewed.
    • concurrent read
    • concurrent write
    • concurrent read and write
  • added Javadocs for non-trivial behavior.
  • added comments explaining intent.
  • added unit tests covering new code paths.

Tests

  • mvn spotless:apply -pl iotdb-core/consensus,iotdb-core/datanode
  • mvn test -pl iotdb-core/consensus -Dtest=SubscriptionWalRetentionCalculatorTest
  • mvn test -pl iotdb-core/consensus,iotdb-core/datanode -Dtest=ConsensusPrefetchingQueueTest#testWalFileCommitRequirementUsesPerWriterMaximum+testWalFileCommitRequirementRejectsUnsupportedWriterMetadata -Dsurefire.failIfNoSpecifiedTests=false
  • mvn test-compile -pl iotdb-core/consensus,iotdb-core/datanode -P with-zh-locale -DskipTests

Key changed/added classes
  • SubscriptionWalRetentionCalculator
  • SubscriptionQueueRegistry
  • IoTConsensusServerImpl
  • ConsensusPrefetchingQueue

Comment on lines +3203 to +3219
final WALNode walNode = (WALNode) consensusReqReader;
final File[] walFiles = WALFileUtils.listAllWALFiles(walNode.getLogDirectory());
if (Objects.isNull(walFiles) || walFiles.length == 0) {
return Math.max(0L, currentWalVersion);
}

WALFileUtils.ascSortByVersionId(walFiles);
for (final File walFile : walFiles) {
final long versionId = WALFileUtils.parseVersionId(walFile.getName());
if (versionId >= currentWalVersion) {
return Math.max(0L, currentWalVersion);
}
if (ProgressWALIterator.isHeaderOnlyWalFile(walFile)) {
continue;
}

WalFileCommitRequirement requirement = walFileCommitRequirements.get(versionId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to record the last visited WalFileCommitRequirement, and avoid listing files when it cannot still be covered by the committed progress.

The overhead of computing the id after each commit concerns me.

Comment on lines +3376 to +3384
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());
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WriterProgress does not implement compareTo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants