jt2594838 commented on code in PR #18399:
URL: https://github.com/apache/iotdb/pull/18399#discussion_r3746024627
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java:
##########
@@ -3128,6 +3139,108 @@ private void applySeekResetUnderWriteLock(final
PendingSeekRequest request) {
seekGeneration.get());
}
+ private boolean commitAndRefreshWalRetention(
+ final WriterId writerId, final WriterProgress writerProgress) {
+ final boolean committed =
+ commitManager.commit(
+ consumerGroupId, topicName, consensusGroupId, writerId,
writerProgress);
+ if (committed) {
+ refreshCommittedWalRetentionBoundAndNotify();
+ }
+ return committed;
+ }
+
+ private boolean commitWithoutOutstandingAndRefreshWalRetention(
+ final WriterId writerId, final WriterProgress writerProgress) {
+ final boolean committed =
+ commitManager.commitWithoutOutstanding(
+ consumerGroupId, topicName, consensusGroupId, writerId,
writerProgress);
+ if (committed) {
+ refreshCommittedWalRetentionBoundAndNotify();
+ }
+ return committed;
+ }
+
+ private long getCommittedRetainedMinVersionId() {
+ refreshCommittedWalRetentionBound();
+ return committedRetainedMinVersionId;
+ }
+
+ private void refreshCommittedWalRetentionBoundAndNotify() {
+ if (refreshCommittedWalRetentionBound()) {
+ serverImpl.checkAndUpdateSafeDeletedSearchIndex();
+ }
+ }
+
+ private boolean refreshCommittedWalRetentionBound() {
+ final RegionProgress committedRegionProgress =
+ commitManager.getCommittedRegionProgress(consumerGroupId, topicName,
consensusGroupId);
+ final long currentWalVersion =
consensusReqReader.getCurrentWALFileVersion();
+
+ synchronized (committedRetentionLock) {
+ if (Objects.equals(lastCommittedProgressForRetention,
committedRegionProgress)
+ && lastCurrentWalVersionForRetention == currentWalVersion) {
+ return false;
+ }
+
+ final long newRetainedMinVersionId =
+ computeCommittedRetainedMinVersionId(committedRegionProgress,
currentWalVersion);
+ final boolean changed = committedRetainedMinVersionId !=
newRetainedMinVersionId;
+ committedRetainedMinVersionId = newRetainedMinVersionId;
+ lastCommittedProgressForRetention = committedRegionProgress;
+ lastCurrentWalVersionForRetention = currentWalVersion;
+ walFileCommitRequirements.keySet().removeIf(versionId -> versionId <
newRetainedMinVersionId);
+ return changed;
+ }
+ }
+
+ private long computeCommittedRetainedMinVersionId(
+ final RegionProgress committedRegionProgress, final long
currentWalVersion) {
+ if (!(consensusReqReader instanceof WALNode)) {
+ return 0L;
+ }
+
+ 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);
Review Comment:
A new WAL file does not seem to have an impact on the current one.
And WAL cleanup may be tested by the existence of the current file, which
should be much cheaper than listing all files.
--
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]