Skip to content

Commit

Permalink
Fix IoTConsensus safe deleted index (#14883)
Browse files Browse the repository at this point in the history
* done

* move
  • Loading branch information
liyuheng55555 authored Feb 18, 2025
1 parent dc84182 commit 9e973b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ private void initAndRecover() throws IOException {
consensusGroupId ->
resetPeerListWithoutThrow.accept(consensusGroupId, Collections.emptyList()));
}
// Since the underlying wal does not persist safelyDeletedSearchIndex, IoTConsensus needs to
// update wal with its syncIndex recovered from the consensus layer when initializing.
// This prevents wal from being piled up if the safelyDeletedSearchIndex is not updated after
// the restart and Leader migration occurs
stateMachineMap.values().forEach(IoTConsensusServerImpl::checkAndUpdateSafeDeletedSearchIndex);
stateMachineMap.values().forEach(IoTConsensusServerImpl::start);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ public IoTConsensusServerImpl(
this.searchIndex = new AtomicLong(consensusReqReader.getCurrentSearchIndex());
this.ioTConsensusServerMetrics = new IoTConsensusServerMetrics(this);
this.logDispatcher = new LogDispatcher(this, clientManager);
// Since the underlying wal does not persist safelyDeletedSearchIndex, IoTConsensus needs to
// update wal with its syncIndex recovered from the consensus layer when initializing.
// This prevents wal from being piled up if the safelyDeletedSearchIndex is not updated after
// the restart and Leader migration occurs
checkAndUpdateSafeDeletedSearchIndex();
// see message in logs for details
checkAndUpdateSearchIndex();
}
Expand Down Expand Up @@ -839,8 +834,11 @@ public void cleanupLocalSnapshot() {
* If there is only one replica, set it to Long.MAX_VALUE.、 If there are multiple replicas, get
* the latest SafelyDeletedSearchIndex again. This enables wal to be deleted in a timely manner.
*/
public void checkAndUpdateSafeDeletedSearchIndex() {
if (configuration.size() == 1) {
void checkAndUpdateSafeDeletedSearchIndex() {
if (configuration.isEmpty()) {
logger.error(
"Configuration is empty, which is unexpected. Safe deleted search index won't be updated this time.");
} else if (configuration.size() == 1) {
consensusReqReader.setSafelyDeletedSearchIndex(Long.MAX_VALUE);
} else {
consensusReqReader.setSafelyDeletedSearchIndex(getMinFlushedSyncIndex());
Expand Down

0 comments on commit 9e973b7

Please sign in to comment.