Skip to content

Commit 4aadc09

Browse files
Fix IoTConsensus safe deleted index again (apache#14897)
* ? * spotless
1 parent 4e0ecc2 commit 4aadc09

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ 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);
215210
stateMachineMap.values().forEach(IoTConsensusServerImpl::start);
216211
}
217212

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,19 @@ public IoTConsensusServerImpl(
146146
this.backgroundTaskService = backgroundTaskService;
147147
this.config = config;
148148
this.consensusGroupId = thisNode.getGroupId().toString();
149-
consensusReqReader = (ConsensusReqReader) stateMachine.read(new GetConsensusReqReaderPlan());
149+
this.consensusReqReader =
150+
(ConsensusReqReader) stateMachine.read(new GetConsensusReqReaderPlan());
150151
this.searchIndex = new AtomicLong(consensusReqReader.getCurrentSearchIndex());
151152
this.ioTConsensusServerMetrics = new IoTConsensusServerMetrics(this);
152153
this.logDispatcher = new LogDispatcher(this, clientManager);
153-
// see message in logs for details
154-
checkAndUpdateSearchIndex();
155154
}
156155

157156
public IStateMachine getStateMachine() {
158157
return stateMachine;
159158
}
160159

161160
public void start() {
161+
checkAndUpdateIndex();
162162
MetricService.getInstance().addMetricSet(this.ioTConsensusServerMetrics);
163163
stateMachine.start();
164164
logDispatcher.start();
@@ -830,9 +830,19 @@ public void cleanupLocalSnapshot() {
830830
}
831831
}
832832

833+
void checkAndUpdateIndex() {
834+
// Since the underlying wal does not persist safelyDeletedSearchIndex, IoTConsensus needs to
835+
// update wal with its syncIndex recovered from the consensus layer when initializing.
836+
// This prevents wal from being piled up if the safelyDeletedSearchIndex is not updated after
837+
// the restart and Leader migration occurs
838+
checkAndUpdateSafeDeletedSearchIndex();
839+
// see message in logs for details
840+
checkAndUpdateSearchIndex();
841+
}
842+
833843
/**
834-
* If there is only one replica, set it to Long.MAX_VALUE. If there are multiple replicas, get
835-
* the latest SafelyDeletedSearchIndex again. This enables wal to be deleted in a timely manner.
844+
* If there is only one replica, set it to Long.MAX_VALUE. If there are multiple replicas, get the
845+
* latest SafelyDeletedSearchIndex again. This enables wal to be deleted in a timely manner.
836846
*/
837847
void checkAndUpdateSafeDeletedSearchIndex() {
838848
if (configuration.isEmpty()) {

0 commit comments

Comments
 (0)