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

Clean up local snapshot after add region peer #12602

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 @@ -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
Loading