delete old volume replica
related to https://github.com/chrislusf/seaweedfs/issues/1607 old is: * older compaction revision * older modified time * smaller volume size
This commit is contained in:
@@ -369,18 +369,20 @@ func countReplicas(replicas []*VolumeReplica) (diffDc, diffRack, diffNode map[st
|
|||||||
|
|
||||||
func pickOneReplicaToDelete(replicas []*VolumeReplica, replicaPlacement *super_block.ReplicaPlacement) *VolumeReplica {
|
func pickOneReplicaToDelete(replicas []*VolumeReplica, replicaPlacement *super_block.ReplicaPlacement) *VolumeReplica {
|
||||||
|
|
||||||
allSame := true
|
sort.Slice(replicas, func(i, j int) bool {
|
||||||
oldest := replicas[0]
|
a, b := replicas[i], replicas[j]
|
||||||
for _, replica := range replicas {
|
if a.info.CompactRevision != b.info.CompactRevision {
|
||||||
if replica.info.ModifiedAtSecond < oldest.info.ModifiedAtSecond {
|
return a.info.CompactRevision < b.info.CompactRevision
|
||||||
oldest = replica
|
|
||||||
allSame = false
|
|
||||||
}
|
}
|
||||||
}
|
if a.info.ModifiedAtSecond != b.info.ModifiedAtSecond {
|
||||||
if !allSame {
|
return a.info.ModifiedAtSecond < b.info.ModifiedAtSecond
|
||||||
return oldest
|
}
|
||||||
}
|
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
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user