diff options
| author | hilimd <68371223+hilimd@users.noreply.github.com> | 2020-11-11 10:16:39 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-11 10:16:39 +0800 |
| commit | a38efe2e7baf34cb074c9db095f7db50de0fa156 (patch) | |
| tree | a731f4e931f5ec6ec3087babfa1f4a2ff781b80c /weed/shell/command_volume_fix_replication.go | |
| parent | 546f1bcb903dd26ba447cdbedb972736fdb31b42 (diff) | |
| parent | de3bdd0651cb2b83319d78cbb0f9da86cd950bfb (diff) | |
| download | seaweedfs-a38efe2e7baf34cb074c9db095f7db50de0fa156.tar.xz seaweedfs-a38efe2e7baf34cb074c9db095f7db50de0fa156.zip | |
Merge pull request #35 from chrislusf/master
sync
Diffstat (limited to 'weed/shell/command_volume_fix_replication.go')
| -rw-r--r-- | weed/shell/command_volume_fix_replication.go | 26 |
1 files 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 } |
