From de3bdd0651cb2b83319d78cbb0f9da86cd950bfb Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 10 Nov 2020 12:26:05 -0800 Subject: [PATCH] delete old volume replica related to https://github.com/chrislusf/seaweedfs/issues/1607 old is: * older compaction revision * older modified time * smaller volume size --- weed/shell/command_volume_fix_replication.go | 26 +++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go index 471b24a2a..9b9abd8eb 100644 --- a/weed/shell/command_volume_fix_replication.go +++ b/weed/shell/command_volume_fix_replication.go @@ -369,18 +369,20 @@ func countReplicas(replicas []*VolumeReplica) (diffDc, diffRack, diffNode map[st func pickOneReplicaToDelete(replicas []*VolumeReplica, replicaPlacement *super_block.ReplicaPlacement) *VolumeReplica { - allSame := true - oldest := replicas[0] - for _, replica := range replicas { - if replica.info.ModifiedAtSecond < oldest.info.ModifiedAtSecond { - oldest = replica - allSame = false + sort.Slice(replicas, func(i, j int) bool { + a, b := replicas[i], replicas[j] + if a.info.CompactRevision != b.info.CompactRevision { + return a.info.CompactRevision < b.info.CompactRevision } - } - if !allSame { - return oldest - } + if a.info.ModifiedAtSecond != b.info.ModifiedAtSecond { + return a.info.ModifiedAtSecond < b.info.ModifiedAtSecond + } + if a.info.Size != b.info.Size { + return a.info.Size < b.info.Size + } + return false + }) + + return replicas[0] - // TODO what if all the replicas have the same timestamp? - return oldest }