Skip to content

Commit 9e973b7

Browse files
Fix IoTConsensus safe deleted index (apache#14883)
* done * move
1 parent dc84182 commit 9e973b7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ private void initAndRecover() throws IOException {
207207
consensusGroupId ->
208208
resetPeerListWithoutThrow.accept(consensusGroupId, Collections.emptyList()));
209209
}
210+
// Since the underlying wal does not persist safelyDeletedSearchIndex, IoTConsensus needs to
211+
// update wal with its syncIndex recovered from the consensus layer when initializing.
212+
// This prevents wal from being piled up if the safelyDeletedSearchIndex is not updated after
213+
// the restart and Leader migration occurs
214+
stateMachineMap.values().forEach(IoTConsensusServerImpl::checkAndUpdateSafeDeletedSearchIndex);
210215
stateMachineMap.values().forEach(IoTConsensusServerImpl::start);
211216
}
212217

iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ public IoTConsensusServerImpl(
150150
this.searchIndex = new AtomicLong(consensusReqReader.getCurrentSearchIndex());
151151
this.ioTConsensusServerMetrics = new IoTConsensusServerMetrics(this);
152152
this.logDispatcher = new LogDispatcher(this, clientManager);
153-
// Since the underlying wal does not persist safelyDeletedSearchIndex, IoTConsensus needs to
154-
// update wal with its syncIndex recovered from the consensus layer when initializing.
155-
// This prevents wal from being piled up if the safelyDeletedSearchIndex is not updated after
156-
// the restart and Leader migration occurs
157-
checkAndUpdateSafeDeletedSearchIndex();
158153
// see message in logs for details
159154
checkAndUpdateSearchIndex();
160155
}
@@ -839,8 +834,11 @@ public void cleanupLocalSnapshot() {
839834
* If there is only one replica, set it to Long.MAX_VALUE.、 If there are multiple replicas, get
840835
* the latest SafelyDeletedSearchIndex again. This enables wal to be deleted in a timely manner.
841836
*/
842-
public void checkAndUpdateSafeDeletedSearchIndex() {
843-
if (configuration.size() == 1) {
837+
void checkAndUpdateSafeDeletedSearchIndex() {
838+
if (configuration.isEmpty()) {
839+
logger.error(
840+
"Configuration is empty, which is unexpected. Safe deleted search index won't be updated this time.");
841+
} else if (configuration.size() == 1) {
844842
consensusReqReader.setSafelyDeletedSearchIndex(Long.MAX_VALUE);
845843
} else {
846844
consensusReqReader.setSafelyDeletedSearchIndex(getMinFlushedSyncIndex());

0 commit comments

Comments
 (0)