mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-08 15:41:15 +02:00
* topology: follow a volume that moved between a server's disks The heartbeat diff asked only whether a volume id was reported anywhere on the node, so a volume that moved to a disk of another type stayed on the disk it left as well. The master then held two copies of it forever: the volume count was overstated, and GetVolumesById returned whichever disk the map iterated first, so lookups could hand back the disk the volume had already left. Track which disk types the heartbeat named each volume on, and treat a volume named on another disk as absent from this one. Disk types are interned to an index because a server reports a handful of them across hundreds of thousands of volumes. A volume named on two disks at once is a stale twin rather than a move, and is still kept on both -- dropping one would tell the master a replica vanished. Only a volume named twice on one disk type is unrepresentable, so that is now what marks the node, rather than any repeat of an id. * master: do not tell clients a moved volume left the node A volume moved between a node's disks is removed from one and added to the other, so it lands in both lists of the same heartbeat. Clients apply additions before deletions, so the removal wins and they end up with no location for a volume that never went anywhere. Skip removals for volumes the node still holds, as the ec shard paths already do, and update the topology before judging the delta removals so an unmount that really did happen is still reported. * trim the comments on this change to the parts that are not evident * master: judge a volume removal on normal replicas alone HasVolumesById answers for ec shards as well, so a replica encoded into ec shards looked like it was still on the node and clients were never told the normal location had gone. They hold normal and ec locations separately and prefer the normal one from the same generation, so that location would have gone on shadowing the shards.
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package topology
|
|
|
|
import (
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
)
|
|
|
|
// reportedVolumes records which disk types a heartbeat named each volume on, so
|
|
// a volume that moved between a server's disks is dropped from the one it left.
|
|
// Disk types are interned because a string header per volume would cost more
|
|
// than the map holding them.
|
|
type reportedVolumes struct {
|
|
diskTypes []string
|
|
byVolume map[needle.VolumeId]int32
|
|
// extra covers volumes named on several disk types, a stale twin rather than
|
|
// a move. Nil otherwise.
|
|
extra map[needle.VolumeId][]int32
|
|
// duplicated: named twice on one disk type, which the master stores once.
|
|
duplicated bool
|
|
}
|
|
|
|
func newReportedVolumes(size int) *reportedVolumes {
|
|
return &reportedVolumes{byVolume: make(map[needle.VolumeId]int32, size)}
|
|
}
|
|
|
|
func (r *reportedVolumes) add(vid needle.VolumeId, diskType string) {
|
|
index := r.internDiskType(diskType)
|
|
existing, seen := r.byVolume[vid]
|
|
if !seen {
|
|
r.byVolume[vid] = index
|
|
return
|
|
}
|
|
if existing == index || r.hasExtra(vid, index) {
|
|
r.duplicated = true
|
|
return
|
|
}
|
|
if r.extra == nil {
|
|
r.extra = make(map[needle.VolumeId][]int32)
|
|
}
|
|
r.extra[vid] = append(r.extra[vid], index)
|
|
}
|
|
|
|
func (r *reportedVolumes) internDiskType(diskType string) int32 {
|
|
if index := r.diskTypeIndex(diskType); index >= 0 {
|
|
return index
|
|
}
|
|
r.diskTypes = append(r.diskTypes, diskType)
|
|
return int32(len(r.diskTypes) - 1)
|
|
}
|
|
|
|
// diskTypeIndex returns -1 when the heartbeat named no volume on the type.
|
|
func (r *reportedVolumes) diskTypeIndex(diskType string) int32 {
|
|
for i, known := range r.diskTypes {
|
|
if known == diskType {
|
|
return int32(i)
|
|
}
|
|
}
|
|
return -1
|
|
}
|
|
|
|
func (r *reportedVolumes) namedOn(vid needle.VolumeId, index int32) bool {
|
|
if index < 0 {
|
|
return false
|
|
}
|
|
if stored, ok := r.byVolume[vid]; ok && stored == index {
|
|
return true
|
|
}
|
|
return r.hasExtra(vid, index)
|
|
}
|
|
|
|
func (r *reportedVolumes) hasExtra(vid needle.VolumeId, index int32) bool {
|
|
for _, other := range r.extra[vid] {
|
|
if other == index {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (r *reportedVolumes) count() int { return len(r.byVolume) }
|