mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
erasure_coding: bound the orphan cleanup's index reads
Detection runs with a background context, so a server that stalled while streaming an .idx or .ecx held up the whole scan. Give each read a deadline; a timed-out .ecx read moves on to the next shard holder, and the replica is kept when none answers.
This commit is contained in:
1 parent
3b07ea7145
commit
68b595d7ca
2 files changed
+57
No files matched your search
@@ -40,6 +40,10 @@ const (
|
||||
minOrphanSourceCoexistence = 30 * time.Minute
|
||||
)
|
||||
|
||||
// orphanSourceIndexReadTimeout bounds each .idx/.ecx read of the orphan
|
||||
// cleanup, so a stalled server cannot hold up detection.
|
||||
var orphanSourceIndexReadTimeout = 5 * time.Minute
|
||||
|
||||
// Detection implements the detection logic for erasure coding tasks.
|
||||
// It respects ctx cancellation and can stop early once maxResults is reached.
|
||||
func Detection(ctx context.Context, metrics []*types.VolumeHealthMetrics, clusterInfo *types.ClusterInfo, config base.TaskConfig, maxResults int) ([]*types.TaskDetectionResult, bool, error) {
|
||||
@@ -962,6 +966,8 @@ func (r *ecxReader) read(ctx context.Context) ([]byte, error) {
|
||||
|
||||
// readVolumeFile reads a whole volume file over the CopyFile RPC.
|
||||
func readVolumeFile(ctx context.Context, client volume_server_pb.VolumeServerClient, volumeID uint32, collection, ext string, isEcVolume bool) ([]byte, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, orphanSourceIndexReadTimeout)
|
||||
defer cancel()
|
||||
stream, err := client.CopyFile(ctx, &volume_server_pb.CopyFileRequest{
|
||||
VolumeId: volumeID,
|
||||
Collection: collection,
|
||||
|
||||
@@ -111,6 +111,7 @@ type fakeOrphanServer struct {
|
||||
mu sync.Mutex
|
||||
files map[string][]byte
|
||||
copyErr error
|
||||
stall bool
|
||||
deleted bool
|
||||
}
|
||||
|
||||
@@ -129,6 +130,10 @@ func (f *fakeOrphanServer) CopyFile(req *volume_server_pb.CopyFileRequest, strea
|
||||
if f.copyErr != nil {
|
||||
return f.copyErr
|
||||
}
|
||||
if f.stall {
|
||||
<-stream.Context().Done()
|
||||
return stream.Context().Err()
|
||||
}
|
||||
f.mu.Lock()
|
||||
content, found := f.files[req.GetExt()]
|
||||
f.mu.Unlock()
|
||||
@@ -375,3 +380,49 @@ func TestOrphanSourceSightingResetsWhenCoexistenceEnds(t *testing.T) {
|
||||
require.Equal(t, 0, deleted)
|
||||
require.False(t, replica.wasDeleted(), "a renewed coexistence must wait again")
|
||||
}
|
||||
|
||||
// A holder that stalls mid-read is given up on after orphanSourceIndexReadTimeout
|
||||
// and the .ecx is read from the next holder instead.
|
||||
func TestCleanupOrphanReadsEcxPastStalledHolder(t *testing.T) {
|
||||
const volumeID = uint32(959)
|
||||
saved := orphanSourceIndexReadTimeout
|
||||
orphanSourceIndexReadTimeout = 200 * time.Millisecond
|
||||
t.Cleanup(func() { orphanSourceIndexReadTimeout = saved })
|
||||
|
||||
ecx := indexBytes(indexEntry{key: 1, size: 100})
|
||||
replica := &fakeOrphanServer{files: map[string][]byte{".idx": ecx}}
|
||||
stalled := &fakeOrphanServer{stall: true}
|
||||
holder := &fakeOrphanServer{files: map[string][]byte{".ecx": ecx}}
|
||||
replicaAddr := startFakeOrphanServer(t, replica)
|
||||
half := func(addr string, bits uint32) *master_pb.DataNodeInfo {
|
||||
return &master_pb.DataNodeInfo{Id: addr, DiskInfos: map[string]*master_pb.DiskInfo{"hdd": {
|
||||
EcShardInfos: []*master_pb.VolumeEcShardInformationMessage{{Id: volumeID, EcIndexBits: bits, EncodeTsNs: 1}},
|
||||
}}}
|
||||
}
|
||||
at := topology.NewActiveTopology(10)
|
||||
require.NoError(t, at.UpdateTopology(&master_pb.TopologyInfo{
|
||||
DataCenterInfos: []*master_pb.DataCenterInfo{{
|
||||
Id: "dc1",
|
||||
RackInfos: []*master_pb.RackInfo{{
|
||||
Id: "rack1",
|
||||
DataNodeInfos: []*master_pb.DataNodeInfo{
|
||||
{Id: replicaAddr, DiskInfos: map[string]*master_pb.DiskInfo{"hdd": {
|
||||
VolumeInfos: []*master_pb.VolumeInformationMessage{{Id: volumeID}},
|
||||
}}},
|
||||
half(startFakeOrphanServer(t, stalled), uint32(1)<<erasure_coding.DataShardsCount-1),
|
||||
half(startFakeOrphanServer(t, holder), (uint32(1)<<erasure_coding.TotalShardsCount-1)&^(uint32(1)<<erasure_coding.DataShardsCount-1)),
|
||||
},
|
||||
}},
|
||||
}},
|
||||
}))
|
||||
clusterInfo := &types.ClusterInfo{
|
||||
ActiveTopology: at,
|
||||
GrpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
}
|
||||
backdateOrphanSource(t, volumeID, "", replicaAddr)
|
||||
|
||||
deleted, err := cleanupOrphanSourceReplicas(context.Background(), clusterInfo, &types.VolumeHealthMetrics{VolumeID: volumeID}, erasure_coding.TotalShardsCount)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, deleted)
|
||||
require.True(t, replica.wasDeleted())
|
||||
}
|
||||
Reference in new issue
Block a user