From b083f40cfd7fe0855f8a131e98c52b3a6098d020 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 6 Dec 2026 00:41:02 -0800 Subject: [PATCH] master: keep a quarantined copy out of the writables when its server marks it writable A volume server that makes a volume writable, as a vacuum does after its commit, tells the master straight away through VolumeMarkReadonly with IsReadonly unset. The master applied that to the layout directly, so a quarantined copy returned to the writable list until its next heartbeat put the quarantine back, and file ids could be assigned on it meanwhile. Record the server's flag but keep the layout mark while the copy is quarantined; the heartbeat that repeats the flag pushes the mark again. --- weed/server/master_grpc_server_volume.go | 2 +- weed/topology/duplicate_volume_id_test.go | 24 +++++++++++++++++++++++ weed/topology/topology.go | 14 +++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/weed/server/master_grpc_server_volume.go b/weed/server/master_grpc_server_volume.go index 6567e0225a..25fed9a727 100644 --- a/weed/server/master_grpc_server_volume.go +++ b/weed/server/master_grpc_server_volume.go @@ -532,7 +532,7 @@ func (ms *MasterServer) VolumeMarkReadonly(ctx context.Context, req *master_pb.V glog.V(0).Infof("volume %d marked readonly with %d pending bytes", vid, pending) } } else { - vl.SetVolumeWritable(dn, vid) + ms.Topo.SetVolumeWritable(vl, dn, vid) } } } diff --git a/weed/topology/duplicate_volume_id_test.go b/weed/topology/duplicate_volume_id_test.go index 6cfaa29564..81e0331d54 100644 --- a/weed/topology/duplicate_volume_id_test.go +++ b/weed/topology/duplicate_volume_id_test.go @@ -762,3 +762,27 @@ func TestEcStaleShardsReleaseKeepsEncodeFreeze(t *testing.T) { require.False(t, isWritable(t, topo, v), "the release must not reopen a source an encode froze") requireOnlyMarked(t, recorder.to(dn1)) } + +func TestQuarantineSurvivesServerMarkingItWritable(t *testing.T) { + topo := NewTopology("topo", nil, 128, 3, false) + 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} + + reportVolume(topo, dn1, false) + mountEcShards(topo, dn2, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) + topo.duplicateFlagChecks.Wait() + require.True(t, topo.isQuarantined(dn1, v.Id)) + + // a vacuum's commit ends with the server telling the master the copy is + // writable again, ahead of its next heartbeat + vl := topo.FindVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl, types.ToDiskType(v.DiskType)) + topo.SetVolumeWritable(vl, dn1, v.Id) + require.False(t, isWritable(t, topo, v), "the server's word must not lift the quarantine") + + // without a quarantine the same call reopens the copy + deleteEcShards(topo, dn2, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) + reportVolume(topo, dn1, true) + topo.SetVolumeWritable(vl, dn1, v.Id) + require.True(t, isWritable(t, topo, v)) +} diff --git a/weed/topology/topology.go b/weed/topology/topology.go index db56f73951..b55c2fffd0 100644 --- a/weed/topology/topology.go +++ b/weed/topology/topology.go @@ -368,6 +368,20 @@ func (t *Topology) enforceQuarantine(dn *DataNode, vi storage.VolumeInfo) storag return vi } +// SetVolumeWritable applies a volume server's own word that its copy of vid +// takes writes again, as a vacuum sends after its commit. A quarantined copy +// keeps its layout mark; the heartbeat that repeats the flag marks the server +// again. +func (t *Topology) SetVolumeWritable(vl *VolumeLayout, dn *DataNode, vid needle.VolumeId) { + t.quarantineLock.Lock() + defer t.quarantineLock.Unlock() + if t.isQuarantined(dn, vid) { + dn.SetVolumeReadOnly(vid, false) + return + } + vl.SetVolumeWritable(dn, vid) +} + func NewTopology(id string, seq sequence.Sequencer, volumeSizeLimit uint64, pulse int, replicationAsMin bool) *Topology { t := &Topology{} t.id = NodeId(id)