Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IoTConsensus safe deleted index #14883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading