From 7609dc7252551299c5cabfc6bb088a5ea5f4964e Mon Sep 17 00:00:00 2001 From: yunfeiyangbuaa Date: Wed, 18 Sep 2019 14:36:32 +0800 Subject: [PATCH] fix gc bug Signed-off-by: yunfeiyangbuaa --- supernode/daemon/mgr/gc/gc_dfget_task.go | 14 ++++++++++++++ supernode/daemon/mgr/gc/gc_peer.go | 1 + 2 files changed, 15 insertions(+) diff --git a/supernode/daemon/mgr/gc/gc_dfget_task.go b/supernode/daemon/mgr/gc/gc_dfget_task.go index d258c798e..3182b6742 100644 --- a/supernode/daemon/mgr/gc/gc_dfget_task.go +++ b/supernode/daemon/mgr/gc/gc_dfget_task.go @@ -25,6 +25,20 @@ import ( func (gcm *Manager) gcDfgetTasksWithTaskID(ctx context.Context, taskID string, cids []string) []error { var errSlice []error for _, cid := range cids { + // NOTE: At present, we create a peer for every dfgetTask. + // So we should also delete the peer when the dfgetTask deleted. + // In addition,if a peer crashes when servers,we can gc it by this way + // + // TODO: In the future, we need a heartbeat mechanism to get the peer status and + // implement a one-to-many relationship between peers and dfgetTasks. + // For compatibility with older versions, we can perform different operations according to the version of peer. + dfgetTask, err := gcm.dfgetTaskMgr.Get(ctx, cid, taskID) + if err == nil { + gcm.progressMgr.UpdatePeerServiceDown(ctx, dfgetTask.PeerID) + } else { + errSlice = append(errSlice, errors.Wrapf(err, "failed to get dfgetTask by cid(%s)", cid)) + } + if err := gcm.progressMgr.DeleteCID(ctx, cid); err != nil { errSlice = append(errSlice, errors.Wrapf(err, "failed to delete dfgetTask(%s) progress info", cid)) } diff --git a/supernode/daemon/mgr/gc/gc_peer.go b/supernode/daemon/mgr/gc/gc_peer.go index b2397ca1b..b74d7b9ac 100644 --- a/supernode/daemon/mgr/gc/gc_peer.go +++ b/supernode/daemon/mgr/gc/gc_peer.go @@ -38,6 +38,7 @@ func (gcm *Manager) gcPeers(ctx context.Context) { peerState, err := gcm.progressMgr.GetPeerStateByPeerID(ctx, peerID) if err != nil { logrus.Warnf("gc peers: failed to get peerState peerID(%s): %v", peerID, err) + gcm.gcPeer(ctx, peerID) continue }