From 2d1074225ab8d25fa822fc944f273f55949af132 Mon Sep 17 00:00:00 2001 From: liyuheng Date: Tue, 28 May 2024 11:56:22 +0800 Subject: [PATCH] done --- .../iotdb/consensus/iot/IoTConsensus.java | 20 +++++++++---------- .../consensus/iot/IoTConsensusServerImpl.java | 14 +++++++++++-- .../IoTConsensusRPCServiceProcessor.java | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java index 46d911608f94..d220d7cac274 100644 --- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java +++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java @@ -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) { @@ -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(); } } diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java index 86c514a48b39..63fdcbf25aee 100644 --- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java +++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java @@ -874,8 +874,7 @@ 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 { @@ -883,6 +882,17 @@ public void cleanupTransferredSnapshot(String snapshotId) } 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); } } diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/service/IoTConsensusRPCServiceProcessor.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/service/IoTConsensusRPCServiceProcessor.java index 1c5f5354c82d..e29d48fed7cf 100644 --- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/service/IoTConsensusRPCServiceProcessor.java +++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/service/IoTConsensusRPCServiceProcessor.java @@ -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);