Skip to content

Commit

Permalink
Clean up local snapshot after add region peer #12602
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuheng55555 authored May 28, 2024
1 parent baf37c3 commit 231910e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,13 @@ public void addRemotePeer(ConsensusGroupId groupId, Peer peer) throws ConsensusE
logger.info("[IoTConsensus] activate new peer...");
impl.activePeer(peer);

// step 7: spot clean
logger.info("[IoTConsensus] do spot clean...");
doSpotClean(peer, impl);
// step 7: notify remote peer to clean up transferred snapshot
logger.info("[IoTConsensus] clean up remote snapshot...");
try {
impl.cleanupRemoteSnapshot(peer);
} catch (ConsensusGroupModifyPeerException e) {
logger.warn("[IoTConsensus] failed to cleanup remote snapshot", e);
}
KillPoint.setKillPoint(DataNodeKillPoints.COORDINATOR_ADD_PEER_DONE);

} catch (ConsensusGroupModifyPeerException e) {
Expand All @@ -343,14 +347,8 @@ public void addRemotePeer(ConsensusGroupId groupId, Peer peer) throws ConsensusE
throw new ConsensusException(e);
} finally {
impl.checkAndUnlockSafeDeletedSearchIndex();
}
}

private void doSpotClean(Peer peer, IoTConsensusServerImpl impl) {
try {
impl.cleanupRemoteSnapshot(peer);
} catch (ConsensusGroupModifyPeerException e) {
logger.warn("[IoTConsensus] failed to cleanup remote snapshot", e);
logger.info("[IoTConsensus] clean up local snapshot...");
impl.cleanupLocalSnapshot();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,15 +874,25 @@ public void cleanupRemoteSnapshot(Peer targetPeer) throws ConsensusGroupModifyPe
}
}

public void cleanupTransferredSnapshot(String snapshotId)
throws ConsensusGroupModifyPeerException {
public void cleanupSnapshot(String snapshotId) throws ConsensusGroupModifyPeerException {
File snapshotDir = new File(storageDir, snapshotId);
if (snapshotDir.exists()) {
try {
FileUtils.deleteDirectory(snapshotDir);
} catch (IOException e) {
throw new ConsensusGroupModifyPeerException(e);
}
} else {
logger.info("File not exist: {}", snapshotDir);
}
}

public void cleanupLocalSnapshot() {
try {
cleanupSnapshot(newSnapshotDirName);
} catch (ConsensusGroupModifyPeerException e) {
logger.warn(
"Cleanup local snapshot fail. You may manually delete {}.", newSnapshotDirName, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void cleanupTransferredSnapshot(
}
TSStatus responseStatus;
try {
impl.cleanupTransferredSnapshot(req.snapshotId);
impl.cleanupSnapshot(req.snapshotId);
responseStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
} catch (ConsensusGroupModifyPeerException e) {
LOGGER.error("failed to cleanup transferred snapshot {}", req.snapshotId, e);
Expand Down

0 comments on commit 231910e

Please sign in to comment.