mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-05-25 11:10:20 +00:00
test: share ec repair helpers
This commit is contained in:
@@ -2,7 +2,6 @@ package ec_repair_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -15,14 +14,6 @@ import (
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type nodeSpec struct {
|
||||
id string
|
||||
address string
|
||||
diskType string
|
||||
diskID uint32
|
||||
ecShards []*master_pb.VolumeEcShardInformationMessage
|
||||
}
|
||||
|
||||
func TestEcRepairDetectionFindsCandidates(t *testing.T) {
|
||||
const (
|
||||
volumeID = uint32(100)
|
||||
@@ -85,58 +76,3 @@ func TestEcRepairDetectionFindsCandidates(t *testing.T) {
|
||||
require.NotEmpty(t, proposals)
|
||||
require.Equal(t, "ec_repair", proposals[0].JobType)
|
||||
}
|
||||
|
||||
func buildTopology(nodes []nodeSpec) *master_pb.TopologyInfo {
|
||||
dataNodes := make([]*master_pb.DataNodeInfo, 0, len(nodes))
|
||||
for _, node := range nodes {
|
||||
diskInfo := &master_pb.DiskInfo{
|
||||
DiskId: node.diskID,
|
||||
MaxVolumeCount: 100,
|
||||
VolumeCount: 10,
|
||||
EcShardInfos: node.ecShards,
|
||||
}
|
||||
dataNodes = append(dataNodes, &master_pb.DataNodeInfo{
|
||||
Id: node.id,
|
||||
Address: node.address,
|
||||
DiskInfos: map[string]*master_pb.DiskInfo{node.diskType: diskInfo},
|
||||
})
|
||||
}
|
||||
|
||||
return &master_pb.TopologyInfo{
|
||||
DataCenterInfos: []*master_pb.DataCenterInfo{
|
||||
{
|
||||
Id: "dc1",
|
||||
RackInfos: []*master_pb.RackInfo{
|
||||
{
|
||||
Id: "rack1",
|
||||
DataNodeInfos: dataNodes,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func buildEcShardInfo(volumeID uint32, collection, diskType string, diskID uint32, shardSizes map[uint32]int64) *master_pb.VolumeEcShardInformationMessage {
|
||||
shardIDs := make([]int, 0, len(shardSizes))
|
||||
for shardID := range shardSizes {
|
||||
shardIDs = append(shardIDs, int(shardID))
|
||||
}
|
||||
sort.Ints(shardIDs)
|
||||
|
||||
var bits uint32
|
||||
sizes := make([]int64, 0, len(shardIDs))
|
||||
for _, shardID := range shardIDs {
|
||||
bits |= (1 << shardID)
|
||||
sizes = append(sizes, shardSizes[uint32(shardID)])
|
||||
}
|
||||
|
||||
return &master_pb.VolumeEcShardInformationMessage{
|
||||
Id: volumeID,
|
||||
Collection: collection,
|
||||
EcIndexBits: bits,
|
||||
DiskType: diskType,
|
||||
DiskId: diskID,
|
||||
ShardSizes: sizes,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package ec_repair_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -16,14 +15,6 @@ import (
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type execNodeSpec struct {
|
||||
id string
|
||||
address string
|
||||
diskType string
|
||||
diskID uint32
|
||||
ecShards []*master_pb.VolumeEcShardInformationMessage
|
||||
}
|
||||
|
||||
func TestEcRepairExecutionRepairsShards(t *testing.T) {
|
||||
const (
|
||||
volumeID = uint32(200)
|
||||
@@ -38,54 +29,53 @@ func TestEcRepairExecutionRepairsShards(t *testing.T) {
|
||||
pluginworkers.NewVolumeServer(t, ""),
|
||||
}
|
||||
|
||||
node1 := execNodeSpec{
|
||||
id: "node1",
|
||||
address: volumeServers[0].Address(),
|
||||
diskType: diskType,
|
||||
diskID: 0,
|
||||
ecShards: []*master_pb.VolumeEcShardInformationMessage{
|
||||
buildEcShardInfoExec(volumeID, collection, diskType, 0, map[uint32]int64{
|
||||
0: 100,
|
||||
1: 100,
|
||||
2: 100,
|
||||
3: 100,
|
||||
4: 100,
|
||||
}),
|
||||
nodes := []nodeSpec{
|
||||
{
|
||||
id: "node1",
|
||||
address: volumeServers[0].Address(),
|
||||
diskType: diskType,
|
||||
diskID: 0,
|
||||
ecShards: []*master_pb.VolumeEcShardInformationMessage{
|
||||
buildEcShardInfo(volumeID, collection, diskType, 0, map[uint32]int64{
|
||||
0: 100,
|
||||
1: 100,
|
||||
2: 100,
|
||||
3: 100,
|
||||
4: 100,
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "node2",
|
||||
address: volumeServers[1].Address(),
|
||||
diskType: diskType,
|
||||
diskID: 0,
|
||||
ecShards: []*master_pb.VolumeEcShardInformationMessage{
|
||||
buildEcShardInfo(volumeID, collection, diskType, 0, map[uint32]int64{
|
||||
0: 50,
|
||||
5: 100,
|
||||
6: 100,
|
||||
7: 100,
|
||||
8: 100,
|
||||
9: 100,
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "node3",
|
||||
address: volumeServers[2].Address(),
|
||||
diskType: diskType,
|
||||
diskID: 0,
|
||||
},
|
||||
{
|
||||
id: "node4",
|
||||
address: volumeServers[3].Address(),
|
||||
diskType: diskType,
|
||||
diskID: 0,
|
||||
},
|
||||
}
|
||||
|
||||
node2 := execNodeSpec{
|
||||
id: "node2",
|
||||
address: volumeServers[1].Address(),
|
||||
diskType: diskType,
|
||||
diskID: 0,
|
||||
ecShards: []*master_pb.VolumeEcShardInformationMessage{
|
||||
buildEcShardInfoExec(volumeID, collection, diskType, 0, map[uint32]int64{
|
||||
0: 50,
|
||||
5: 100,
|
||||
6: 100,
|
||||
7: 100,
|
||||
8: 100,
|
||||
9: 100,
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
node3 := execNodeSpec{
|
||||
id: "node3",
|
||||
address: volumeServers[2].Address(),
|
||||
diskType: diskType,
|
||||
diskID: 0,
|
||||
}
|
||||
|
||||
node4 := execNodeSpec{
|
||||
id: "node4",
|
||||
address: volumeServers[3].Address(),
|
||||
diskType: diskType,
|
||||
diskID: 0,
|
||||
}
|
||||
|
||||
topo := buildExecTopology([]execNodeSpec{node1, node2, node3, node4})
|
||||
topo := buildTopology(nodes)
|
||||
response := &master_pb.VolumeListResponse{TopologyInfo: topo}
|
||||
master := pluginworkers.NewMasterServer(t, response)
|
||||
|
||||
@@ -139,58 +129,3 @@ func TestEcRepairExecutionRepairsShards(t *testing.T) {
|
||||
require.Greater(t, deleteCalls, 0)
|
||||
require.Greater(t, unmountCalls, 0)
|
||||
}
|
||||
|
||||
func buildExecTopology(nodes []execNodeSpec) *master_pb.TopologyInfo {
|
||||
dataNodes := make([]*master_pb.DataNodeInfo, 0, len(nodes))
|
||||
for _, node := range nodes {
|
||||
diskInfo := &master_pb.DiskInfo{
|
||||
DiskId: node.diskID,
|
||||
MaxVolumeCount: 200,
|
||||
VolumeCount: 10,
|
||||
EcShardInfos: node.ecShards,
|
||||
}
|
||||
dataNodes = append(dataNodes, &master_pb.DataNodeInfo{
|
||||
Id: node.id,
|
||||
Address: node.address,
|
||||
DiskInfos: map[string]*master_pb.DiskInfo{node.diskType: diskInfo},
|
||||
})
|
||||
}
|
||||
|
||||
return &master_pb.TopologyInfo{
|
||||
DataCenterInfos: []*master_pb.DataCenterInfo{
|
||||
{
|
||||
Id: "dc1",
|
||||
RackInfos: []*master_pb.RackInfo{
|
||||
{
|
||||
Id: "rack1",
|
||||
DataNodeInfos: dataNodes,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func buildEcShardInfoExec(volumeID uint32, collection, diskType string, diskID uint32, shardSizes map[uint32]int64) *master_pb.VolumeEcShardInformationMessage {
|
||||
shardIDs := make([]int, 0, len(shardSizes))
|
||||
for shardID := range shardSizes {
|
||||
shardIDs = append(shardIDs, int(shardID))
|
||||
}
|
||||
sort.Ints(shardIDs)
|
||||
|
||||
var bits uint32
|
||||
sizes := make([]int64, 0, len(shardIDs))
|
||||
for _, shardID := range shardIDs {
|
||||
bits |= (1 << shardID)
|
||||
sizes = append(sizes, shardSizes[uint32(shardID)])
|
||||
}
|
||||
|
||||
return &master_pb.VolumeEcShardInformationMessage{
|
||||
Id: volumeID,
|
||||
Collection: collection,
|
||||
EcIndexBits: bits,
|
||||
DiskType: diskType,
|
||||
DiskId: diskID,
|
||||
ShardSizes: sizes,
|
||||
}
|
||||
}
|
||||
|
||||
69
test/plugin_workers/ec_repair/helpers_test.go
Normal file
69
test/plugin_workers/ec_repair/helpers_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package ec_repair_test
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
)
|
||||
|
||||
type nodeSpec struct {
|
||||
id string
|
||||
address string
|
||||
diskType string
|
||||
diskID uint32
|
||||
ecShards []*master_pb.VolumeEcShardInformationMessage
|
||||
}
|
||||
|
||||
func buildTopology(nodes []nodeSpec) *master_pb.TopologyInfo {
|
||||
dataNodes := make([]*master_pb.DataNodeInfo, 0, len(nodes))
|
||||
for _, node := range nodes {
|
||||
diskInfo := &master_pb.DiskInfo{
|
||||
DiskId: node.diskID,
|
||||
MaxVolumeCount: 100,
|
||||
VolumeCount: 10,
|
||||
EcShardInfos: node.ecShards,
|
||||
}
|
||||
dataNodes = append(dataNodes, &master_pb.DataNodeInfo{
|
||||
Id: node.id,
|
||||
Address: node.address,
|
||||
DiskInfos: map[string]*master_pb.DiskInfo{node.diskType: diskInfo},
|
||||
})
|
||||
}
|
||||
return &master_pb.TopologyInfo{
|
||||
DataCenterInfos: []*master_pb.DataCenterInfo{
|
||||
{
|
||||
Id: "dc1",
|
||||
RackInfos: []*master_pb.RackInfo{
|
||||
{
|
||||
Id: "rack1",
|
||||
DataNodeInfos: dataNodes,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func buildEcShardInfo(volumeID uint32, collection, diskType string, diskID uint32, shardSizes map[uint32]int64) *master_pb.VolumeEcShardInformationMessage {
|
||||
shardIDs := make([]int, 0, len(shardSizes))
|
||||
for shardID := range shardSizes {
|
||||
shardIDs = append(shardIDs, int(shardID))
|
||||
}
|
||||
sort.Ints(shardIDs)
|
||||
|
||||
var bits uint32
|
||||
sizes := make([]int64, 0, len(shardIDs))
|
||||
for _, shardID := range shardIDs {
|
||||
bits |= (1 << shardID)
|
||||
sizes = append(sizes, shardSizes[uint32(shardID)])
|
||||
}
|
||||
|
||||
return &master_pb.VolumeEcShardInformationMessage{
|
||||
Id: volumeID,
|
||||
Collection: collection,
|
||||
EcIndexBits: bits,
|
||||
DiskType: diskType,
|
||||
DiskId: diskID,
|
||||
ShardSizes: sizes,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user