mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06333ca84e | ||
|
|
0164ad8464 | ||
|
|
81b420c71a | ||
|
|
d46eff96da | ||
|
|
b083f40cfd | ||
|
|
0aea318693 | ||
|
|
2a06745590 | ||
|
|
5ec35006cc |
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package topology
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/super_block"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
||||
@@ -425,3 +427,424 @@ func TestFailedWritablePushRetriedOnNextReport(t *testing.T) {
|
||||
return !topo.isQuarantined(dn1, v1.Id) && isWritable(t, topo, v1) && writablePushes.Load() >= 2
|
||||
}, 5*time.Second, time.Millisecond, "the next volume report must retry the release and its writable push")
|
||||
}
|
||||
|
||||
type quarantinePush struct {
|
||||
dn NodeId
|
||||
readOnly bool
|
||||
}
|
||||
|
||||
type quarantinePushRecorder struct {
|
||||
mu sync.Mutex
|
||||
pushes []quarantinePush
|
||||
}
|
||||
|
||||
func (r *quarantinePushRecorder) push(dn *DataNode, _ needle.VolumeId, readOnly bool) error {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
r.pushes = append(r.pushes, quarantinePush{dn.Id(), readOnly})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *quarantinePushRecorder) to(dn *DataNode) []bool {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
var marks []bool
|
||||
for _, p := range r.pushes {
|
||||
if p.dn == dn.Id() {
|
||||
marks = append(marks, p.readOnly)
|
||||
}
|
||||
}
|
||||
return marks
|
||||
}
|
||||
|
||||
func TestQuarantineLeavesReadOnlyCopyUnpushed(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
rp, _ := super_block.NewReplicaPlacementFromString("000")
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
|
||||
dn1 := NewDataNode("server1")
|
||||
dn2 := NewDataNode("server2")
|
||||
v1 := storage.VolumeInfo{Id: 7, Collection: "a", ReplicaPlacement: rp, Ttl: needle.EMPTY_TTL, ReadOnly: true}
|
||||
v2 := storage.VolumeInfo{Id: 7, Collection: "b", ReplicaPlacement: rp, Ttl: needle.EMPTY_TTL}
|
||||
dn1.UpdateVolumes([]storage.VolumeInfo{v1})
|
||||
dn2.UpdateVolumes([]storage.VolumeInfo{v2})
|
||||
topo.GetVolumeLayout(v1.Collection, v1.ReplicaPlacement, v1.Ttl, types.ToDiskType(v1.DiskType)).RegisterVolume(&v1, dn1, nil)
|
||||
topo.GetVolumeLayout(v2.Collection, v2.ReplicaPlacement, v2.Ttl, types.ToDiskType(v2.DiskType)).RegisterVolume(&v2, dn2, nil)
|
||||
topo.flagDuplicateVolumeId(v2, dn2)
|
||||
|
||||
// the mark still takes deletes, so pushing it onto a copy its server
|
||||
// already holds read-only could only relax that copy
|
||||
require.Empty(t, recorder.to(dn1), "a copy already read-only must not be pushed")
|
||||
require.Equal(t, []bool{true}, recorder.to(dn2))
|
||||
|
||||
topo.UnRegisterVolumeLayout(v2, dn2)
|
||||
require.False(t, topo.isQuarantined(dn1, v1.Id))
|
||||
require.Empty(t, recorder.to(dn1), "the release must not open a copy the master never marked")
|
||||
require.False(t, isWritable(t, topo, v1), "the survivor keeps its own read-only state")
|
||||
}
|
||||
|
||||
func TestQuarantineReleaseFollowsWritableReportAfterMark(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
rp, _ := super_block.NewReplicaPlacementFromString("000")
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
|
||||
dn1 := NewDataNode("server1")
|
||||
dn2 := NewDataNode("server2")
|
||||
v1 := storage.VolumeInfo{Id: 7, Collection: "a", ReplicaPlacement: rp, Ttl: needle.EMPTY_TTL, ReadOnly: true, Version: needle.Version3}
|
||||
v2 := storage.VolumeInfo{Id: 7, Collection: "b", ReplicaPlacement: rp, Ttl: needle.EMPTY_TTL}
|
||||
dn1.UpdateVolumes([]storage.VolumeInfo{v1})
|
||||
dn2.UpdateVolumes([]storage.VolumeInfo{v2})
|
||||
topo.GetVolumeLayout(v1.Collection, v1.ReplicaPlacement, v1.Ttl, types.ToDiskType(v1.DiskType)).RegisterVolume(&v1, dn1, nil)
|
||||
topo.GetVolumeLayout(v2.Collection, v2.ReplicaPlacement, v2.Ttl, types.ToDiskType(v2.DiskType)).RegisterVolume(&v2, dn2, nil)
|
||||
topo.flagDuplicateVolumeId(v2, dn2)
|
||||
|
||||
// whoever froze the copy reopens it while the conflict stands: the
|
||||
// master marks it again, and the reopening is what a release restores
|
||||
topo.SyncDataNodeRegistration([]*master_pb.VolumeInformationMessage{{
|
||||
Id: 7, Collection: "a", ReplicaPlacement: 0, Version: uint32(needle.Version3),
|
||||
}}, dn1)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.Equal(t, []bool{true}, recorder.to(dn1))
|
||||
require.False(t, isWritable(t, topo, v1), "the writable report must not lift the quarantine")
|
||||
|
||||
topo.UnRegisterVolumeLayout(v2, dn2)
|
||||
require.False(t, topo.isQuarantined(dn1, v1.Id))
|
||||
require.Equal(t, []bool{true, false}, recorder.to(dn1))
|
||||
require.True(t, isWritable(t, topo, v1), "the release must restore the state the server last chose")
|
||||
}
|
||||
|
||||
func TestQuarantineReleaseKeepsStricterMarkAfterMark(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
rp, _ := super_block.NewReplicaPlacementFromString("000")
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
|
||||
dn1 := NewDataNode("server1")
|
||||
dn2 := NewDataNode("server2")
|
||||
v1 := storage.VolumeInfo{Id: 7, Collection: "a", ReplicaPlacement: rp, Ttl: needle.EMPTY_TTL, Version: needle.Version3}
|
||||
v2 := storage.VolumeInfo{Id: 7, Collection: "b", ReplicaPlacement: rp, Ttl: needle.EMPTY_TTL}
|
||||
dn1.UpdateVolumes([]storage.VolumeInfo{v1})
|
||||
dn2.UpdateVolumes([]storage.VolumeInfo{v2})
|
||||
topo.GetVolumeLayout(v1.Collection, v1.ReplicaPlacement, v1.Ttl, types.ToDiskType(v1.DiskType)).RegisterVolume(&v1, dn1, nil)
|
||||
topo.GetVolumeLayout(v2.Collection, v2.ReplicaPlacement, v2.Ttl, types.ToDiskType(v2.DiskType)).RegisterVolume(&v2, dn2, nil)
|
||||
topo.flagDuplicateVolumeId(v2, dn2)
|
||||
require.Equal(t, []bool{true}, recorder.to(dn1))
|
||||
|
||||
// the mark lands, then something freezes the copy so it refuses deletes
|
||||
// too; that is no longer the master's mark, and a release must keep it
|
||||
for _, canDelete := range []bool{true, false} {
|
||||
topo.ApplyVolumeChanges([]*master_pb.VolumeInformationMessage{{
|
||||
Id: 7, Collection: "a", Version: uint32(needle.Version3), ReadOnly: true, ReadOnlyCanDelete: canDelete,
|
||||
}}, dn1)
|
||||
}
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
|
||||
topo.UnRegisterVolumeLayout(v2, dn2)
|
||||
require.False(t, topo.isQuarantined(dn1, v1.Id))
|
||||
require.Equal(t, []bool{true}, recorder.to(dn1), "the release must not reopen a copy frozen by someone else")
|
||||
require.False(t, isWritable(t, topo, v1))
|
||||
}
|
||||
|
||||
func mountEcShards(topo *Topology, dn *DataNode, vid uint32, shardIds ...erasure_coding.ShardId) {
|
||||
msg := buildEcShardMessage(vid, "a", "", 0, shardIds)
|
||||
topo.IncrementalSyncDataNodeEcShards([]*master_pb.VolumeEcShardInformationMessage{msg}, nil, dn)
|
||||
}
|
||||
|
||||
func deleteEcShards(topo *Topology, dn *DataNode, vid uint32, shardIds ...erasure_coding.ShardId) {
|
||||
msg := buildEcShardMessage(vid, "a", "", 0, shardIds)
|
||||
topo.IncrementalSyncDataNodeEcShards(nil, []*master_pb.VolumeEcShardInformationMessage{msg}, dn)
|
||||
}
|
||||
|
||||
// requireOnlyMarked checks that marks were pushed and none of them opened
|
||||
// the copy; how many land depends on how many checks saw it.
|
||||
func requireOnlyMarked(t *testing.T, marks []bool) {
|
||||
t.Helper()
|
||||
require.NotEmpty(t, marks)
|
||||
require.NotContains(t, marks, false)
|
||||
}
|
||||
|
||||
// requireReleasedLast checks the copy was marked and then opened once, last.
|
||||
func requireReleasedLast(t *testing.T, marks []bool) {
|
||||
t.Helper()
|
||||
require.GreaterOrEqual(t, len(marks), 2)
|
||||
requireOnlyMarked(t, marks[:len(marks)-1])
|
||||
require.False(t, marks[len(marks)-1])
|
||||
}
|
||||
|
||||
func reportVolume(topo *Topology, dn *DataNode, readOnly bool) {
|
||||
topo.ApplyVolumeChanges([]*master_pb.VolumeInformationMessage{{
|
||||
Id: 7, Collection: "a", Version: uint32(needle.Version3), ReadOnly: readOnly,
|
||||
}}, dn)
|
||||
}
|
||||
|
||||
func TestEcShardsQuarantineRegularCopy(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
dn1, dn2, dn3 := NewDataNode("server1"), NewDataNode("server2"), NewDataNode("server3")
|
||||
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)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.True(t, isWritable(t, topo, v))
|
||||
|
||||
mountEcShards(topo, dn2, 7, 0, 1, 2, 3, 4, 5, 6)
|
||||
mountEcShards(topo, dn3, 7, 7, 8, 9, 10, 11, 12, 13)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
|
||||
require.False(t, isWritable(t, topo, v), "a regular copy must leave the writables once its id has EC shards")
|
||||
require.True(t, topo.isQuarantined(dn1, v.Id))
|
||||
requireOnlyMarked(t, recorder.to(dn1))
|
||||
require.Empty(t, recorder.to(dn2), "shard holders are not regular volumes")
|
||||
require.Empty(t, recorder.to(dn3), "shard holders are not regular volumes")
|
||||
}
|
||||
|
||||
func TestEcShardsKeepLateRegularCopyOutOfWritables(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
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()
|
||||
|
||||
// a stale copy of the source comes back with its server, writable
|
||||
topo.SyncDataNodeRegistration([]*master_pb.VolumeInformationMessage{{
|
||||
Id: 7, Collection: "a", Version: uint32(needle.Version3),
|
||||
}}, dn1)
|
||||
require.False(t, isWritable(t, topo, v), "the copy must be read-only from the moment it registers")
|
||||
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.False(t, isWritable(t, topo, v))
|
||||
require.True(t, topo.isQuarantined(dn1, v.Id))
|
||||
requireOnlyMarked(t, recorder.to(dn1))
|
||||
}
|
||||
|
||||
func TestEcShardsQuarantineSurvivesVacuumReopen(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
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()
|
||||
marked := len(recorder.to(dn1))
|
||||
requireOnlyMarked(t, recorder.to(dn1))
|
||||
|
||||
// the mark lands, then a compaction ends by marking the copy writable
|
||||
reportVolume(topo, dn1, true)
|
||||
reportVolume(topo, dn1, false)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
|
||||
require.False(t, isWritable(t, topo, v), "a reopened copy must stay out of the writables while the shards exist")
|
||||
require.Greater(t, len(recorder.to(dn1)), marked, "the reopened copy must be marked again")
|
||||
requireOnlyMarked(t, recorder.to(dn1))
|
||||
|
||||
// a full heartbeat repeating the writable flag does not lift it either
|
||||
topo.SyncDataNodeRegistration([]*master_pb.VolumeInformationMessage{{
|
||||
Id: 7, Collection: "a", Version: uint32(needle.Version3),
|
||||
}}, dn1)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.False(t, isWritable(t, topo, v))
|
||||
}
|
||||
|
||||
func TestEcShardsGoneReleasesDecodedVolume(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
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, dn1, 7, 0, 1, 2, 3, 4, 5, 6)
|
||||
mountEcShards(topo, dn2, 7, 7, 8, 9, 10, 11, 12, 13)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
|
||||
// the decode collects the data shards on dn1, generates the volume there
|
||||
// and mounts it, then deletes every shard
|
||||
reportVolume(topo, dn1, false)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.False(t, isWritable(t, topo, v), "the decoded volume stays read-only while shards remain")
|
||||
|
||||
deleteEcShards(topo, dn2, 7, 7, 8, 9, 10, 11, 12, 13)
|
||||
require.False(t, isWritable(t, topo, v), "some shards still remain")
|
||||
require.True(t, topo.isQuarantined(dn1, v.Id))
|
||||
|
||||
deleteEcShards(topo, dn1, 7, 0, 1, 2, 3, 4, 5, 6)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.False(t, topo.isQuarantined(dn1, v.Id))
|
||||
require.True(t, isWritable(t, topo, v), "the decoded volume must end writable")
|
||||
requireReleasedLast(t, recorder.to(dn1))
|
||||
}
|
||||
|
||||
func TestEcEncodeSourceStaysReadOnlyUntilDeleted(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
dn1, dn2, dn3 := NewDataNode("server1"), NewDataNode("server2"), NewDataNode("server3")
|
||||
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)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
|
||||
// the encode freezes the source, mounts the shards, then deletes the source
|
||||
reportVolume(topo, dn1, true)
|
||||
mountEcShards(topo, dn2, 7, 0, 1, 2, 3, 4, 5, 6)
|
||||
mountEcShards(topo, dn3, 7, 7, 8, 9, 10, 11, 12, 13)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.False(t, isWritable(t, topo, v))
|
||||
require.Empty(t, recorder.to(dn1), "a frozen source needs no mark, which would let it take deletes")
|
||||
|
||||
topo.SyncDataNodeRegistration(nil, dn1)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.False(t, topo.isQuarantined(dn1, v.Id), "the record goes with the source")
|
||||
require.Empty(t, recorder.to(dn1))
|
||||
_, found := topo.FindCollection("a")
|
||||
require.False(t, found, "no regular copy is left to write to")
|
||||
require.NotEmpty(t, topo.Lookup("a", v.Id), "lookups resolve to the shard holders")
|
||||
}
|
||||
|
||||
func TestEcEncodeRollbackRestoresWritableSource(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
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)
|
||||
reportVolume(topo, dn1, true)
|
||||
mountEcShards(topo, dn2, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
|
||||
// a failed encode tears the shards down and reopens the source; the
|
||||
// reopening can reach the master first
|
||||
reportVolume(topo, dn1, false)
|
||||
require.False(t, isWritable(t, topo, v))
|
||||
deleteEcShards(topo, dn2, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
|
||||
require.True(t, isWritable(t, topo, v), "a rolled back source must end writable")
|
||||
requireReleasedLast(t, recorder.to(dn1))
|
||||
}
|
||||
|
||||
func TestEcStaleShardsReleaseKeepsEncodeFreeze(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
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}
|
||||
|
||||
// shards left by an earlier failed encode mark the writable source
|
||||
reportVolume(topo, dn1, false)
|
||||
mountEcShards(topo, dn2, 7, 0, 1, 2)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
requireOnlyMarked(t, recorder.to(dn1))
|
||||
|
||||
// the next encode tears them down and freezes the source, and the master
|
||||
// can learn of the freeze first
|
||||
topo.ApplyVolumeChanges([]*master_pb.VolumeInformationMessage{{
|
||||
Id: 7, Collection: "a", Version: uint32(needle.Version3), ReadOnly: true,
|
||||
}}, dn1)
|
||||
deleteEcShards(topo, dn2, 7, 0, 1, 2)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
|
||||
require.False(t, topo.isQuarantined(dn1, v.Id))
|
||||
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.GetVolumeLayout(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))
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
func TestEcShardsQuarantineSurvivesHolderDisconnect(t *testing.T) {
|
||||
topo := NewTopology("topo", nil, 128, 3, false)
|
||||
var recorder quarantinePushRecorder
|
||||
topo.QuarantineVolumeFn = recorder.push
|
||||
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))
|
||||
|
||||
// the only shard holder drops out; its shards are still on its disks
|
||||
topo.UnRegisterDataNode(dn2)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.True(t, topo.isQuarantined(dn1, v.Id), "a disconnect must not release the quarantine")
|
||||
require.False(t, isWritable(t, topo, v))
|
||||
requireOnlyMarked(t, recorder.to(dn1))
|
||||
|
||||
back := NewDataNode("server2")
|
||||
mountEcShards(topo, back, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.False(t, isWritable(t, topo, v))
|
||||
|
||||
// only shards reported deleted end the conflict
|
||||
deleteEcShards(topo, back, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
|
||||
topo.duplicateFlagChecks.Wait()
|
||||
require.False(t, topo.isQuarantined(dn1, v.Id))
|
||||
require.True(t, isWritable(t, topo, v))
|
||||
requireReleasedLast(t, recorder.to(dn1))
|
||||
}
|
||||
+115
-46
@@ -139,8 +139,9 @@ type Topology struct {
|
||||
growthFreezeApplyLock sync.Mutex
|
||||
|
||||
// quarantinedVolumeIds are (node, vid) pairs force-read-only because the
|
||||
// vid collided across layouts. Kept separate from the reported flag so
|
||||
// later heartbeats from the same server cannot quietly undo it.
|
||||
// vid collided across layouts or with EC shards of the same id. Kept
|
||||
// separate from the reported flag so later heartbeats from the same
|
||||
// server cannot quietly undo it.
|
||||
quarantinedVolumeIds sync.Map
|
||||
// quarantineLock serializes each quarantine record update with the layout
|
||||
// mark it justifies: a release pass and a heartbeat read-only flag update
|
||||
@@ -316,19 +317,25 @@ func (t *Topology) enforceQuarantine(dn *DataNode, vi storage.VolumeInfo) storag
|
||||
return vi
|
||||
}
|
||||
state := v.(quarantinedVolumeState)
|
||||
if !state.enforced {
|
||||
// Once the mark lands a report that reads like it, read-only but taking
|
||||
// deletes, may be the mark itself. Any other report is the server's own:
|
||||
// writable after a restart, volume.mark or a vacuum reopening the copy,
|
||||
// or frozen harder by a mark that refuses deletes too.
|
||||
if !state.enforced || !vi.ReadOnly || !vi.ReadOnlyCanDelete {
|
||||
state.reported = vi.ReadOnly
|
||||
}
|
||||
if t.QuarantineVolumeFn == nil || (state.enforced && vi.ReadOnly) {
|
||||
// A copy its server already holds read-only takes no writes, and the
|
||||
// mark, which still takes deletes, would relax a stricter one.
|
||||
if t.QuarantineVolumeFn == nil || vi.ReadOnly {
|
||||
t.quarantinedVolumeIds.Store(q, state)
|
||||
t.quarantineLock.Unlock()
|
||||
return vi
|
||||
}
|
||||
t.quarantineLock.Unlock()
|
||||
|
||||
// The mark never landed on the server, or the server lost it (restart,
|
||||
// manual unquarantine); push it while the conflict stands. The call is
|
||||
// remote, so it runs outside the lock.
|
||||
// The server holds the copy writable: the mark never landed, or the
|
||||
// server lost it (restart, manual unquarantine); push it while the
|
||||
// conflict stands. The call is remote, so it runs outside the lock.
|
||||
pushed, err := t.pushQuarantine(dn, vi.Id, true)
|
||||
if pushed && err == nil {
|
||||
state.enforced = true
|
||||
@@ -337,16 +344,14 @@ func (t *Topology) enforceQuarantine(dn *DataNode, vi storage.VolumeInfo) storag
|
||||
cur, still := t.quarantinedVolumeIds.Load(q)
|
||||
if still {
|
||||
latest := cur.(quarantinedVolumeState)
|
||||
if !latest.enforced {
|
||||
latest.reported = state.reported
|
||||
}
|
||||
latest.reported = false
|
||||
latest.enforced = latest.enforced || state.enforced
|
||||
t.quarantinedVolumeIds.Store(q, latest)
|
||||
t.quarantineLock.Unlock()
|
||||
return vi
|
||||
}
|
||||
t.quarantineLock.Unlock()
|
||||
if state.enforced && !state.reported {
|
||||
if state.enforced {
|
||||
// The conflict resolved while the push was in flight; leave the
|
||||
// server consistent with the released layout.
|
||||
t.releaseQuarantineWritable(dn, vi.Id)
|
||||
@@ -354,6 +359,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)
|
||||
@@ -1054,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.
|
||||
@@ -1079,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 {
|
||||
ecCollection, conflict := "", false
|
||||
// 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})
|
||||
ecCollection, conflict = collection, true
|
||||
}
|
||||
}
|
||||
registered := vl.RegisterVolume(v, dn, func(n *DataNode) bool {
|
||||
return t.isQuarantined(n, v.Id)
|
||||
})
|
||||
t.quarantineLock.Unlock()
|
||||
if conflict {
|
||||
logEcShardConflict(*v, dn, ecCollection)
|
||||
}
|
||||
return registered
|
||||
}
|
||||
|
||||
func (t *Topology) flagDuplicateVolumeIdAsync(v storage.VolumeInfo, dn *DataNode) {
|
||||
t.duplicateFlagChecks.Add(1)
|
||||
go func() {
|
||||
@@ -1087,12 +1124,26 @@ func (t *Topology) flagDuplicateVolumeIdAsync(v storage.VolumeInfo, dn *DataNode
|
||||
}()
|
||||
}
|
||||
|
||||
// flagRegularCopiesAsync runs the duplicate check for every regular copy of
|
||||
// vid, for a conflicting holder that registers outside the volume layouts.
|
||||
func (t *Topology) flagRegularCopiesAsync(vid needle.VolumeId) {
|
||||
for _, item := range t.collectionMap.Items() {
|
||||
for _, vl := range item.(*Collection).GetAllVolumeLayouts() {
|
||||
for _, n := range vl.Lookup(vid) {
|
||||
if vi, err := n.GetVolumesById(vid); err == nil {
|
||||
t.flagDuplicateVolumeIdAsync(vi, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// flagDuplicateVolumeId reports and quarantines v.Id when another data node
|
||||
// already serves it under a different layout key. It runs after registration
|
||||
// so a legitimate same-node move (disk type or collection change) settles
|
||||
// first and does not trip it. Every copy across the conflicting layouts is
|
||||
// quarantined: either could be the impostor, and arrival order must not
|
||||
// decide which copy stays writable.
|
||||
// already serves it under a different layout key or as EC shards. It runs
|
||||
// after registration so a legitimate same-node move (disk type or collection
|
||||
// change) settles first and does not trip it. Every regular copy across the
|
||||
// conflicting layouts is quarantined: either could be the impostor, and
|
||||
// arrival order must not decide which copy stays writable.
|
||||
func (t *Topology) flagDuplicateVolumeId(v storage.VolumeInfo, dn *DataNode) {
|
||||
// Every pass ends with a release: a conflict could resolve between the
|
||||
// scan below and the marks, and a check finding no hits is also the retry
|
||||
@@ -1110,12 +1161,15 @@ func (t *Topology) flagDuplicateVolumeId(v storage.VolumeInfo, dn *DataNode) {
|
||||
if own == nil || !own.HasDataNode(v.Id, dn) {
|
||||
return
|
||||
}
|
||||
stats.MasterDuplicateVolumeIds.WithLabelValues(v.Collection, v.Id.String()).Inc()
|
||||
var otherKeys []string
|
||||
for _, h := range hits {
|
||||
otherKeys = append(otherKeys, h.layoutKey())
|
||||
ecOnly := len(hits) == 1 && hits[0].vl == nil
|
||||
if !ecOnly {
|
||||
stats.MasterDuplicateVolumeIds.WithLabelValues(v.Collection, v.Id.String()).Inc()
|
||||
var otherKeys []string
|
||||
for _, h := range hits {
|
||||
otherKeys = append(otherKeys, h.layoutKey())
|
||||
}
|
||||
glog.Errorf("duplicate volume id %d: %s reports it under %s but other data nodes also serve it under %s; marking all copies read-only", v.Id, dn.Id(), volumeLayoutKey(v.Collection, v.ReplicaPlacement, v.Ttl, types.ToDiskType(v.DiskType)), strings.Join(otherKeys, ", "))
|
||||
}
|
||||
glog.Errorf("duplicate volume id %d: %s reports it under %s but other data nodes also serve it under %s; marking all copies read-only", v.Id, dn.Id(), volumeLayoutKey(v.Collection, v.ReplicaPlacement, v.Ttl, types.ToDiskType(v.DiskType)), strings.Join(otherKeys, ", "))
|
||||
quarantine := func(n *DataNode, vl *VolumeLayout) {
|
||||
q := quarantinedVolume{n.Id(), v.Id}
|
||||
reported := false
|
||||
@@ -1123,12 +1177,17 @@ func (t *Topology) flagDuplicateVolumeId(v storage.VolumeInfo, dn *DataNode) {
|
||||
reported = vi.ReadOnly
|
||||
}
|
||||
t.quarantineLock.Lock()
|
||||
t.quarantinedVolumeIds.LoadOrStore(q, quarantinedVolumeState{reported: reported})
|
||||
_, loaded := t.quarantinedVolumeIds.LoadOrStore(q, quarantinedVolumeState{reported: reported})
|
||||
if vl != nil {
|
||||
vl.SetVolumeQuarantined(n, v.Id)
|
||||
}
|
||||
t.quarantineLock.Unlock()
|
||||
if t.QuarantineVolumeFn == nil {
|
||||
// every shard registration rechecks; report the record's creation only
|
||||
if ecOnly && !loaded {
|
||||
logEcShardConflict(v, n, hits[0].collection)
|
||||
}
|
||||
if t.QuarantineVolumeFn == nil || reported {
|
||||
// enforceQuarantine pushes once the server reports it writable
|
||||
return
|
||||
}
|
||||
pushed, err := t.pushQuarantine(n, v.Id, true)
|
||||
@@ -1159,6 +1218,17 @@ func (t *Topology) flagDuplicateVolumeId(v storage.VolumeInfo, dn *DataNode) {
|
||||
}
|
||||
}
|
||||
|
||||
// logEcShardConflict reports a regular copy newly quarantined beside EC shards
|
||||
// of its id. Only a writable copy could have taken writes the shards lack; a
|
||||
// read-only one is what an encode holds until it deletes its source.
|
||||
func logEcShardConflict(v storage.VolumeInfo, dn *DataNode, ecCollection string) {
|
||||
if v.ReadOnly {
|
||||
glog.V(1).Infof("volume id %d: %s holds a read-only regular copy in collection %q beside EC shards in collection %q; keeping it read-only", v.Id, dn.Id(), v.Collection, ecCollection)
|
||||
return
|
||||
}
|
||||
glog.Warningf("volume id %d: %s reports a writable regular copy in collection %q beside EC shards in collection %q; marking it read-only", v.Id, dn.Id(), v.Collection, ecCollection)
|
||||
}
|
||||
|
||||
// releaseResolvedQuarantine lifts read-only marks once the conflicting copy
|
||||
// is gone, so a finished move does not leave the surviving copy quarantined.
|
||||
// The writable push is a remote call, so the locked pass only applies the
|
||||
@@ -1244,7 +1314,8 @@ func (t *Topology) findQuarantinedVolume(dnId NodeId, vid needle.VolumeId) (*Dat
|
||||
}
|
||||
|
||||
// duplicateHit is one layout that holds v.Id on data nodes other than the
|
||||
// reporter's.
|
||||
// reporter's, or, with no layout, the EC shards of v.Id. Shard holders are
|
||||
// not regular volumes, so that hit names no nodes to mark.
|
||||
type duplicateHit struct {
|
||||
collection string
|
||||
vl *VolumeLayout
|
||||
@@ -1252,6 +1323,9 @@ type duplicateHit struct {
|
||||
}
|
||||
|
||||
func (h duplicateHit) layoutKey() string {
|
||||
if h.vl == nil {
|
||||
return fmt.Sprintf("ec shards collection=%q", h.collection)
|
||||
}
|
||||
return volumeLayoutKey(h.collection, h.vl.rp, h.vl.ttl, h.vl.diskType)
|
||||
}
|
||||
|
||||
@@ -1265,7 +1339,9 @@ func ttlEqual(a, b *needle.TTL) bool {
|
||||
|
||||
// findDuplicateVolumeLayouts reports every layout that already holds v.Id on
|
||||
// data nodes other than dn. Volume ids are global, so the same id held by two
|
||||
// nodes under two layouts means the allocator reused an id.
|
||||
// nodes under two layouts means the allocator reused an id. EC shards of v.Id
|
||||
// conflict too: a read resolves to whichever holder the lookup prefers, and
|
||||
// the shards never see what the regular copy took.
|
||||
func (t *Topology) findDuplicateVolumeLayouts(v storage.VolumeInfo, dn *DataNode) []duplicateHit {
|
||||
if v.ReplicaPlacement == nil {
|
||||
return nil
|
||||
@@ -1293,6 +1369,9 @@ func (t *Topology) findDuplicateVolumeLayouts(v storage.VolumeInfo, dn *DataNode
|
||||
}
|
||||
}
|
||||
}
|
||||
if collection, held := t.ecShardsHeld(v.Id); held {
|
||||
hits = append(hits, duplicateHit{collection: collection})
|
||||
}
|
||||
return hits
|
||||
}
|
||||
|
||||
@@ -1552,12 +1631,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
|
||||
@@ -1666,12 +1740,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.
|
||||
|
||||
@@ -137,8 +137,6 @@ func (t *Topology) RegisterEcShards(ecvi *erasure_coding.EcVolumeInfo, dn *DataN
|
||||
t.UpAdjustMaxVolumeId(ecvi.VolumeId)
|
||||
|
||||
t.ecShardMapLock.Lock()
|
||||
defer t.ecShardMapLock.Unlock()
|
||||
|
||||
locations, found := t.ecShardMap[ecvi.VolumeId]
|
||||
if !found {
|
||||
locations = NewEcShardLocations(ecvi.Collection)
|
||||
@@ -147,15 +145,28 @@ func (t *Topology) RegisterEcShards(ecvi *erasure_coding.EcVolumeInfo, dn *DataN
|
||||
for _, shardId := range ecvi.ShardsInfo.Ids() {
|
||||
locations.AddShard(shardId, dn)
|
||||
}
|
||||
t.ecShardMapLock.Unlock()
|
||||
|
||||
// a regular copy registered before the shards must not stay writable
|
||||
// beside them
|
||||
t.flagRegularCopiesAsync(ecvi.VolumeId)
|
||||
}
|
||||
|
||||
// UnRegisterEcShards drops shards dn reported deleted.
|
||||
func (t *Topology) UnRegisterEcShards(ecvi *erasure_coding.EcVolumeInfo, dn *DataNode) {
|
||||
t.unregisterEcShards(ecvi, dn, true)
|
||||
}
|
||||
|
||||
// unregisterEcShards drops dn's shards of ecvi from the lookup. Once a
|
||||
// volume's last shards are reported deleted its entry goes, and with it the
|
||||
// conflict that quarantines regular copies of the id. A node that only went
|
||||
// away may come back with its shards, so its last shards leave the entry.
|
||||
func (t *Topology) unregisterEcShards(ecvi *erasure_coding.EcVolumeInfo, dn *DataNode, reportedDeleted bool) {
|
||||
glog.Infof("removing ec shard info:%+v", ecvi)
|
||||
t.ecShardMapLock.Lock()
|
||||
defer t.ecShardMapLock.Unlock()
|
||||
|
||||
locations, found := t.ecShardMap[ecvi.VolumeId]
|
||||
if !found {
|
||||
t.ecShardMapLock.Unlock()
|
||||
return
|
||||
}
|
||||
for _, shardId := range ecvi.ShardsInfo.Ids() {
|
||||
@@ -164,6 +175,37 @@ func (t *Topology) UnRegisterEcShards(ecvi *erasure_coding.EcVolumeInfo, dn *Dat
|
||||
}
|
||||
locations.DeleteShard(shardId, dn)
|
||||
}
|
||||
gone := reportedDeleted && !locations.hasShards()
|
||||
if gone {
|
||||
delete(t.ecShardMap, ecvi.VolumeId)
|
||||
}
|
||||
t.ecShardMapLock.Unlock()
|
||||
|
||||
if gone {
|
||||
// the regular copy a decode left behind is no longer in conflict
|
||||
t.releaseResolvedQuarantine(ecvi.VolumeId)
|
||||
}
|
||||
}
|
||||
|
||||
func (loc *EcShardLocations) hasShards() bool {
|
||||
for _, nodes := range loc.Locations {
|
||||
if len(nodes) > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ecShardsHeld reports whether vid has EC shards, as far as the master knows,
|
||||
// and under which collection: some node holds them, or their holders went
|
||||
// away without reporting them deleted.
|
||||
func (t *Topology) ecShardsHeld(vid needle.VolumeId) (collection string, held bool) {
|
||||
t.ecShardMapLock.RLock()
|
||||
defer t.ecShardMapLock.RUnlock()
|
||||
if locations, found := t.ecShardMap[vid]; found {
|
||||
return locations.Collection, true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func (t *Topology) LookupEcShards(vid needle.VolumeId) (locations *EcShardLocations, found bool) {
|
||||
@@ -269,8 +311,6 @@ func (t *Topology) ListEcServersByCollection(collection string) (dataNodes []pb.
|
||||
|
||||
func (t *Topology) DeleteEcCollection(collection string) {
|
||||
t.ecShardMapLock.Lock()
|
||||
defer t.ecShardMapLock.Unlock()
|
||||
|
||||
var vids []needle.VolumeId
|
||||
for vid, ecVolumeLocation := range t.ecShardMap {
|
||||
if ecVolumeLocation.Collection == collection {
|
||||
@@ -281,4 +321,9 @@ func (t *Topology) DeleteEcCollection(collection string) {
|
||||
for _, vid := range vids {
|
||||
delete(t.ecShardMap, vid)
|
||||
}
|
||||
t.ecShardMapLock.Unlock()
|
||||
|
||||
for _, vid := range vids {
|
||||
t.releaseResolvedQuarantine(vid)
|
||||
}
|
||||
}
|
||||
@@ -126,12 +126,13 @@ func (t *Topology) UnRegisterDataNode(dn *DataNode) {
|
||||
// unregister ec shards when volume server disconnected. The node's own
|
||||
// records clear first so the still-held check cannot skip the drop, and
|
||||
// each unregister gets a copy — DeleteEcShard drains the shared
|
||||
// ShardsInfo.
|
||||
// ShardsInfo. The shards may come back with the node, so regular copies
|
||||
// of their ids stay quarantined.
|
||||
for _, s := range dn.GetEcShards() {
|
||||
held := *s
|
||||
held.ShardsInfo = s.ShardsInfo.Copy()
|
||||
dn.DeleteEcShard(s)
|
||||
t.UnRegisterEcShards(&held, dn)
|
||||
t.unregisterEcShards(&held, dn, false)
|
||||
}
|
||||
|
||||
negativeUsages := dn.GetDiskUsages().negative()
|
||||
|
||||
Reference in new issue
Block a user