mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
topology: quarantine a copy beside EC shards in the step that registers it
The quarantine record for a regular copy reported beside EC shards was created by the heartbeat before the copy was registered, and the mark was pushed while the copy was still in no layout. A release pass running in that window, such as the one ending another copy's duplicate check, found no copy for the record, dropped it, and the finished push then sent a writable release; the copy registered without a quarantine. Create the record under the same lock hold that adds the copy to its layout, so a release pass always finds the copy beside its record. The duplicate check registration starts pushes the mark as before.
This commit is contained in:
1 parent
b083f40cfd
commit
d46eff96da
2 files changed
+59
-32
No files matched your search
@@ -786,3 +786,31 @@ func TestQuarantineSurvivesServerMarkingItWritable(t *testing.T) {
|
||||
topo.SetVolumeWritable(vl, dn1, v.Id)
|
||||
require.True(t, isWritable(t, topo, v))
|
||||
}
|
||||
|
||||
func TestEcShardsQuarantineSurvivesReleaseBeforeRegistration(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
var recorder quarantinePushRecorder
|
||||
var released atomic.Bool
|
||||
topo.QuarantineVolumeFn = func(dn *DataNode, vid needle.VolumeId, readOnly bool) error {
|
||||
// a release pass for the id, finishing some other check, runs while
|
||||
// the first mark is in flight
|
||||
if readOnly && released.CompareAndSwap(false, true) {
|
||||
topo.releaseResolvedQuarantine(vid)
|
||||
}
|
||||
return recorder.push(dn, vid, readOnly)
|
||||
}
|
||||
dn1, dn2 := NewDataNode("server1"), NewDataNode("server2")
|
||||
rp, _ := super_block.NewReplicaPlacementFromString("000")
|
||||
v := storage.VolumeInfo{Id: 7, Collection: "a", ReplicaPlacement: rp, Ttl: needle.EMPTY_TTL, Version: needle.Version3}
|
||||
|
||||
mountEcShards(topo, dn2, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
|
||||
reportVolume(topo, dn1, false)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
|
||||
require.True(t, released.Load())
|
||||
require.True(t, topo.isQuarantined(dn1, v.Id))
|
||||
require.False(t, isWritable(t, topo, v), "the copy must stay quarantined")
|
||||
requireOnlyMarked(t, recorder.to(dn1))
|
||||
}
|
||||
+31
-32
@@ -305,17 +305,8 @@ func (t *Topology) enforceQuarantine(dn *DataNode, vi storage.VolumeInfo) storag
|
||||
t.quarantineLock.Lock()
|
||||
v, ok := t.quarantinedVolumeIds.Load(q)
|
||||
if !ok {
|
||||
ecCollection, held := t.ecShardsHeld(vi.Id)
|
||||
if !held {
|
||||
t.quarantineLock.Unlock()
|
||||
return vi
|
||||
}
|
||||
// Recorded before the copy registers, so it never reaches the
|
||||
// writable list.
|
||||
v = quarantinedVolumeState{}
|
||||
t.quarantinedVolumeIds.Store(q, v)
|
||||
ownKey := volumeLayoutKey(vi.Collection, vi.ReplicaPlacement, vi.Ttl, types.ToDiskType(vi.DiskType))
|
||||
defer logEcShardConflict(vi, dn, ownKey, duplicateHit{collection: ecCollection}.layoutKey())
|
||||
t.quarantineLock.Unlock()
|
||||
return vi
|
||||
}
|
||||
if t.takeQuarantineRetryLocked(q) {
|
||||
// A failed writable push re-armed this record; hand the release pass
|
||||
@@ -1082,15 +1073,7 @@ func (t *Topology) RegisterVolumeLayout(v storage.VolumeInfo, dn *DataNode) {
|
||||
diskType := types.ToDiskType(v.DiskType)
|
||||
for {
|
||||
vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl, diskType)
|
||||
// RegisterVolume reads the quarantine record and marks under
|
||||
// accessLock; holding quarantineLock keeps that pair serialized with
|
||||
// releaseResolvedQuarantine's clear-and-delete.
|
||||
t.quarantineLock.Lock()
|
||||
registered := vl.RegisterVolume(&v, dn, func(n *DataNode) bool {
|
||||
return t.isQuarantined(n, v.Id)
|
||||
})
|
||||
t.quarantineLock.Unlock()
|
||||
if registered {
|
||||
if t.registerVolume(vl, &v, dn) {
|
||||
// RegisterVolume rebuilds only the read-only flags, so a
|
||||
// location list recreated flagless would pass the writable
|
||||
// check before the next heartbeat re-measures the volume.
|
||||
@@ -1107,6 +1090,32 @@ func (t *Topology) RegisterVolumeLayout(v storage.VolumeInfo, dn *DataNode) {
|
||||
}
|
||||
}
|
||||
|
||||
// registerVolume records dn's copy of v in vl with the quarantine marks folded
|
||||
// in. A copy registering beside EC shards of its id is quarantined in the
|
||||
// same step, so it never reaches the writable list and no release pass can
|
||||
// see its record before the copy is in a layout.
|
||||
func (t *Topology) registerVolume(vl *VolumeLayout, v *storage.VolumeInfo, dn *DataNode) bool {
|
||||
var ecKey string
|
||||
// RegisterVolume reads the quarantine record and marks under accessLock;
|
||||
// holding quarantineLock keeps that pair serialized with
|
||||
// releaseResolvedQuarantine's clear-and-delete.
|
||||
t.quarantineLock.Lock()
|
||||
if !t.isQuarantined(dn, v.Id) {
|
||||
if collection, held := t.ecShardsHeld(v.Id); held {
|
||||
t.quarantinedVolumeIds.Store(quarantinedVolume{dn.Id(), v.Id}, quarantinedVolumeState{reported: v.ReadOnly})
|
||||
ecKey = duplicateHit{collection: collection}.layoutKey()
|
||||
}
|
||||
}
|
||||
registered := vl.RegisterVolume(v, dn, func(n *DataNode) bool {
|
||||
return t.isQuarantined(n, v.Id)
|
||||
})
|
||||
t.quarantineLock.Unlock()
|
||||
if ecKey != "" {
|
||||
logEcShardConflict(*v, dn, volumeLayoutKey(v.Collection, v.ReplicaPlacement, v.Ttl, types.ToDiskType(v.DiskType)), ecKey)
|
||||
}
|
||||
return registered
|
||||
}
|
||||
|
||||
func (t *Topology) flagDuplicateVolumeIdAsync(v storage.VolumeInfo, dn *DataNode) {
|
||||
t.duplicateFlagChecks.Add(1)
|
||||
go func() {
|
||||
@@ -1623,12 +1632,7 @@ func (t *Topology) SyncDataNodeRegistration(volumes []*master_pb.VolumeInformati
|
||||
// LookupVolume returns "volume id not found".
|
||||
if !vl.HasDataNode(v.Id, dn) {
|
||||
for {
|
||||
t.quarantineLock.Lock()
|
||||
registered := vl.RegisterVolume(&v, dn, func(n *DataNode) bool {
|
||||
return t.isQuarantined(n, v.Id)
|
||||
})
|
||||
t.quarantineLock.Unlock()
|
||||
if registered {
|
||||
if t.registerVolume(vl, &v, dn) {
|
||||
break
|
||||
}
|
||||
// Dropped with its collection; the next lookup creates a fresh
|
||||
@@ -1737,12 +1741,7 @@ func (t *Topology) ApplyVolumeChanges(changed []*master_pb.VolumeInformationMess
|
||||
// concerned: they were told it went when the node dropped out.
|
||||
becameServable := !vl.HasDataNode(vi.Id, dn)
|
||||
for becameServable {
|
||||
t.quarantineLock.Lock()
|
||||
registered := vl.RegisterVolume(&vi, dn, func(n *DataNode) bool {
|
||||
return t.isQuarantined(n, vi.Id)
|
||||
})
|
||||
t.quarantineLock.Unlock()
|
||||
if registered {
|
||||
if t.registerVolume(vl, &vi, dn) {
|
||||
break
|
||||
}
|
||||
// Dropped with its collection; the next lookup creates a fresh one.
|
||||
|
||||
Reference in new issue
Block a user