mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
ec_balance: keep node addresses out of the task ID so tasks can be persisted (#13062)
* ec_balance: keep node addresses out of the task ID The ID embedded both host:port node addresses, and the admin's task persistence rejects any ID containing ':', so every ec_balance task failed to save on each state change and lived only in memory. The volume, shard, timestamp and index already make the ID unique; the nodes stay in the task's Reason and params. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * admin: test that a detected ec_balance task saves and loads Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
77333a5578
commit
e01133bfa3
2 files changed
+59
-2
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package dash
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/admin/maintenance"
|
||||
"github.com/seaweedfs/seaweedfs/weed/admin/topology"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/ec_balance"
|
||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||
)
|
||||
|
||||
// Volume servers are identified by host:port, and the detected task must
|
||||
// still be saved under its ID.
|
||||
func TestECBalanceTaskStateIsSaved(t *testing.T) {
|
||||
disk := func(shards ...*master_pb.VolumeEcShardInformationMessage) map[string]*master_pb.DiskInfo {
|
||||
return map[string]*master_pb.DiskInfo{"": {MaxVolumeCount: 100, EcShardInfos: shards}}
|
||||
}
|
||||
topoInfo := &master_pb.TopologyInfo{
|
||||
DataCenterInfos: []*master_pb.DataCenterInfo{{
|
||||
Id: "dc1",
|
||||
RackInfos: []*master_pb.RackInfo{{Id: "rack1", DataNodeInfos: []*master_pb.DataNodeInfo{
|
||||
{Id: "10.0.0.1:8080", DiskInfos: disk(&master_pb.VolumeEcShardInformationMessage{Id: 100, FileCount: 1, Collection: "col1", EcIndexBits: 0x3FFF})},
|
||||
{Id: "10.0.0.2:8080", DiskInfos: disk()},
|
||||
{Id: "10.0.0.3:8080", DiskInfos: disk()},
|
||||
}}},
|
||||
}},
|
||||
}
|
||||
at := topology.NewActiveTopology(0)
|
||||
if err := at.UpdateTopology(topoInfo); err != nil {
|
||||
t.Fatalf("UpdateTopology: %v", err)
|
||||
}
|
||||
results, _, err := ec_balance.Detection(context.Background(), nil, &types.ClusterInfo{ActiveTopology: at}, ec_balance.NewDefaultConfig(), 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Detection: %v", err)
|
||||
}
|
||||
if len(results) == 0 {
|
||||
t.Fatal("fixture planned no moves")
|
||||
}
|
||||
|
||||
cp := NewConfigPersistence(t.TempDir())
|
||||
for _, r := range results {
|
||||
task := &maintenance.MaintenanceTask{
|
||||
ID: r.TaskID,
|
||||
Type: maintenance.MaintenanceTaskType(r.TaskType),
|
||||
VolumeID: r.VolumeID,
|
||||
Server: r.Server,
|
||||
Status: maintenance.TaskStatusPending,
|
||||
}
|
||||
if err := cp.SaveTaskState(task); err != nil {
|
||||
t.Fatalf("SaveTaskState(%q): %v", r.TaskID, err)
|
||||
}
|
||||
if _, err := cp.LoadTaskState(r.TaskID); err != nil {
|
||||
t.Fatalf("LoadTaskState(%q): %v", r.TaskID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,8 +112,7 @@ func Detection(
|
||||
now := time.Now()
|
||||
results := make([]*types.TaskDetectionResult, 0, len(moves))
|
||||
for i, m := range moves {
|
||||
taskID := fmt.Sprintf("ec_balance_%d_%d_%s_%s_%d_%d",
|
||||
m.VolumeID, m.ShardID, m.SourceNode, m.TargetNode, now.UnixNano(), i)
|
||||
taskID := fmt.Sprintf("ec_balance_%d_%d_%d_%d", m.VolumeID, m.ShardID, now.UnixNano(), i)
|
||||
results = append(results, &types.TaskDetectionResult{
|
||||
TaskID: taskID,
|
||||
TaskType: types.TaskTypeECBalance,
|
||||
|
||||
Reference in new issue
Block a user