mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-29 07:37:05 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c18ea21f7a | ||
|
|
18b98fdb72 | ||
|
|
44b3f2efc8 | ||
|
|
d80538a187 | ||
|
|
1a09bc43d1 | ||
|
|
2b643f477d | ||
|
|
05034aade5 |
No files matched your search
@@ -1,4 +1,4 @@
|
||||
apiVersion: v1
|
||||
description: SeaweedFS
|
||||
name: seaweedfs
|
||||
version: 1.93
|
||||
version: 1.94
|
||||
@@ -4,7 +4,7 @@ global:
|
||||
registry: ""
|
||||
repository: ""
|
||||
imageName: chrislusf/seaweedfs
|
||||
imageTag: "1.93"
|
||||
imageTag: "1.94"
|
||||
imagePullPolicy: IfNotPresent
|
||||
imagePullSecrets: imagepullsecret
|
||||
restartPolicy: Always
|
||||
|
||||
@@ -3,9 +3,9 @@ package elastic
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/filer"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
elastic "github.com/olivere/elastic/v7"
|
||||
)
|
||||
@@ -32,7 +32,7 @@ func (store *ElasticStore) KvGet(ctx context.Context, key []byte) (value []byte,
|
||||
Id(string(key)).
|
||||
Do(ctx)
|
||||
if elastic.IsNotFound(err) {
|
||||
return nil, filer_pb.ErrNotFound
|
||||
return nil, filer.ErrKvNotFound
|
||||
}
|
||||
if searchResult != nil && searchResult.Found {
|
||||
esEntry := &ESKVEntry{}
|
||||
@@ -41,7 +41,7 @@ func (store *ElasticStore) KvGet(ctx context.Context, key []byte) (value []byte,
|
||||
}
|
||||
}
|
||||
glog.Errorf("find key(%s),%v.", string(key), err)
|
||||
return nil, filer_pb.ErrNotFound
|
||||
return nil, filer.ErrKvNotFound
|
||||
}
|
||||
|
||||
func (store *ElasticStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
|
||||
|
||||
@@ -36,7 +36,7 @@ func (c *commandVolumeFixReplication) Help() string {
|
||||
Note:
|
||||
* each time this will only add back one replica for one volume id. If there are multiple replicas
|
||||
are missing, e.g. multiple volume servers are new, you may need to run this multiple times.
|
||||
* do not run this too quick within seconds, since the new volume replica may take a few seconds
|
||||
* do not run this too quickly within seconds, since the new volume replica may take a few seconds
|
||||
to register itself to the master.
|
||||
|
||||
`
|
||||
@@ -64,31 +64,35 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv,
|
||||
|
||||
// find all volumes that needs replication
|
||||
// collect all data nodes
|
||||
replicatedVolumeLocations := make(map[uint32][]location)
|
||||
replicatedVolumeInfo := make(map[uint32]*master_pb.VolumeInformationMessage)
|
||||
volumeReplicas := make(map[uint32][]*VolumeReplica)
|
||||
var allLocations []location
|
||||
eachDataNode(resp.TopologyInfo, func(dc string, rack RackId, dn *master_pb.DataNodeInfo) {
|
||||
loc := newLocation(dc, string(rack), dn)
|
||||
for _, v := range dn.VolumeInfos {
|
||||
if v.ReplicaPlacement > 0 {
|
||||
replicatedVolumeLocations[v.Id] = append(replicatedVolumeLocations[v.Id], loc)
|
||||
replicatedVolumeInfo[v.Id] = v
|
||||
volumeReplicas[v.Id] = append(volumeReplicas[v.Id], &VolumeReplica{
|
||||
location: &loc,
|
||||
info: v,
|
||||
})
|
||||
}
|
||||
}
|
||||
allLocations = append(allLocations, loc)
|
||||
})
|
||||
|
||||
// find all under replicated volumes
|
||||
underReplicatedVolumeLocations := make(map[uint32][]location)
|
||||
for vid, locations := range replicatedVolumeLocations {
|
||||
volumeInfo := replicatedVolumeInfo[vid]
|
||||
replicaPlacement, _ := super_block.NewReplicaPlacementFromByte(byte(volumeInfo.ReplicaPlacement))
|
||||
if replicaPlacement.GetCopyCount() > len(locations) {
|
||||
underReplicatedVolumeLocations[vid] = locations
|
||||
var underReplicatedVolumeIds, overReplicatedVolumeIds []uint32
|
||||
for vid, replicas := range volumeReplicas {
|
||||
replica := replicas[rand.Intn(len(replicas))]
|
||||
replicaPlacement, _ := super_block.NewReplicaPlacementFromByte(byte(replica.info.ReplicaPlacement))
|
||||
if replicaPlacement.GetCopyCount() > len(replicas) {
|
||||
underReplicatedVolumeIds = append(underReplicatedVolumeIds, vid)
|
||||
} else if replicaPlacement.GetCopyCount() < len(replicas) {
|
||||
overReplicatedVolumeIds = append(overReplicatedVolumeIds, vid)
|
||||
fmt.Fprintf(writer, "volume %d replication %s, but over replicated %+d\n", replica.info.Id, replicaPlacement, len(replicas))
|
||||
}
|
||||
}
|
||||
|
||||
if len(underReplicatedVolumeLocations) == 0 {
|
||||
if len(underReplicatedVolumeIds) == 0 {
|
||||
return fmt.Errorf("no under replicated volumes")
|
||||
}
|
||||
|
||||
@@ -99,18 +103,22 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv,
|
||||
// find the most under populated data nodes
|
||||
keepDataNodesSorted(allLocations)
|
||||
|
||||
for vid, locations := range underReplicatedVolumeLocations {
|
||||
volumeInfo := replicatedVolumeInfo[vid]
|
||||
replicaPlacement, _ := super_block.NewReplicaPlacementFromByte(byte(volumeInfo.ReplicaPlacement))
|
||||
return c.fixUnderReplicatedVolumes(commandEnv, writer, takeAction, underReplicatedVolumeIds, volumeReplicas, allLocations)
|
||||
|
||||
}
|
||||
|
||||
func (c *commandVolumeFixReplication) fixUnderReplicatedVolumes(commandEnv *CommandEnv, writer io.Writer, takeAction bool, underReplicatedVolumeIds []uint32, volumeReplicas map[uint32][]*VolumeReplica, allLocations []location) error {
|
||||
for _, vid := range underReplicatedVolumeIds {
|
||||
replicas := volumeReplicas[vid]
|
||||
replica := replicas[rand.Intn(len(replicas))]
|
||||
replicaPlacement, _ := super_block.NewReplicaPlacementFromByte(byte(replica.info.ReplicaPlacement))
|
||||
foundNewLocation := false
|
||||
for _, dst := range allLocations {
|
||||
// check whether data nodes satisfy the constraints
|
||||
if dst.dataNode.FreeVolumeCount > 0 && satisfyReplicaPlacement(replicaPlacement, locations, dst) {
|
||||
if dst.dataNode.FreeVolumeCount > 0 && satisfyReplicaPlacement(replicaPlacement, replicas, dst) {
|
||||
// ask the volume server to replicate the volume
|
||||
sourceNodes := underReplicatedVolumeLocations[vid]
|
||||
sourceNode := sourceNodes[rand.Intn(len(sourceNodes))]
|
||||
foundNewLocation = true
|
||||
fmt.Fprintf(writer, "replicating volume %d %s from %s to dataNode %s ...\n", volumeInfo.Id, replicaPlacement, sourceNode.dataNode.Id, dst.dataNode.Id)
|
||||
fmt.Fprintf(writer, "replicating volume %d %s from %s to dataNode %s ...\n", replica.info.Id, replicaPlacement, replica.location.dataNode.Id, dst.dataNode.Id)
|
||||
|
||||
if !takeAction {
|
||||
break
|
||||
@@ -118,11 +126,11 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv,
|
||||
|
||||
err := operation.WithVolumeServerClient(dst.dataNode.Id, commandEnv.option.GrpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
|
||||
_, replicateErr := volumeServerClient.VolumeCopy(context.Background(), &volume_server_pb.VolumeCopyRequest{
|
||||
VolumeId: volumeInfo.Id,
|
||||
SourceDataNode: sourceNode.dataNode.Id,
|
||||
VolumeId: replica.info.Id,
|
||||
SourceDataNode: replica.location.dataNode.Id,
|
||||
})
|
||||
if replicateErr != nil {
|
||||
return fmt.Errorf("copying from %s => %s : %v", sourceNode.dataNode.Id, dst.dataNode.Id, replicateErr)
|
||||
return fmt.Errorf("copying from %s => %s : %v", replica.location.dataNode.Id, dst.dataNode.Id, replicateErr)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -138,11 +146,10 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv,
|
||||
}
|
||||
}
|
||||
if !foundNewLocation {
|
||||
fmt.Fprintf(writer, "failed to place volume %d replica as %s, existing:%+v\n", volumeInfo.Id, replicaPlacement, locations)
|
||||
fmt.Fprintf(writer, "failed to place volume %d replica as %s, existing:%+v\n", replica.info.Id, replicaPlacement, len(replicas))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -182,11 +189,11 @@ func keepDataNodesSorted(dataNodes []location) {
|
||||
return false
|
||||
}
|
||||
*/
|
||||
func satisfyReplicaPlacement(replicaPlacement *super_block.ReplicaPlacement, existingLocations []location, possibleLocation location) bool {
|
||||
func satisfyReplicaPlacement(replicaPlacement *super_block.ReplicaPlacement, replicas []*VolumeReplica, possibleLocation location) bool {
|
||||
|
||||
existingDataNodes := make(map[string]int)
|
||||
for _, loc := range existingLocations {
|
||||
existingDataNodes[loc.String()] += 1
|
||||
for _, replica := range replicas {
|
||||
existingDataNodes[replica.location.String()] += 1
|
||||
}
|
||||
sameDataNodeCount := existingDataNodes[possibleLocation.String()]
|
||||
// avoid duplicated volume on the same data node
|
||||
@@ -195,8 +202,8 @@ func satisfyReplicaPlacement(replicaPlacement *super_block.ReplicaPlacement, exi
|
||||
}
|
||||
|
||||
existingDataCenters := make(map[string]int)
|
||||
for _, loc := range existingLocations {
|
||||
existingDataCenters[loc.DataCenter()] += 1
|
||||
for _, replica := range replicas {
|
||||
existingDataCenters[replica.location.DataCenter()] += 1
|
||||
}
|
||||
primaryDataCenters, _ := findTopKeys(existingDataCenters)
|
||||
|
||||
@@ -219,11 +226,11 @@ func satisfyReplicaPlacement(replicaPlacement *super_block.ReplicaPlacement, exi
|
||||
|
||||
// now this is one of the primary dcs
|
||||
existingRacks := make(map[string]int)
|
||||
for _, loc := range existingLocations {
|
||||
if loc.DataCenter() != possibleLocation.DataCenter() {
|
||||
for _, replica := range replicas {
|
||||
if replica.location.DataCenter() != possibleLocation.DataCenter() {
|
||||
continue
|
||||
}
|
||||
existingRacks[loc.Rack()] += 1
|
||||
existingRacks[replica.location.Rack()] += 1
|
||||
}
|
||||
primaryRacks, _ := findTopKeys(existingRacks)
|
||||
sameRackCount := existingRacks[possibleLocation.Rack()]
|
||||
@@ -280,6 +287,11 @@ func isAmong(key string, keys []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type VolumeReplica struct {
|
||||
location *location
|
||||
info *master_pb.VolumeInformationMessage
|
||||
}
|
||||
|
||||
type location struct {
|
||||
dc string
|
||||
rack string
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
)
|
||||
|
||||
type testcase struct {
|
||||
name string
|
||||
replication string
|
||||
existingLocations []location
|
||||
possibleLocation location
|
||||
expected bool
|
||||
name string
|
||||
replication string
|
||||
replicas []*VolumeReplica
|
||||
possibleLocation location
|
||||
expected bool
|
||||
}
|
||||
|
||||
func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||
@@ -21,8 +21,10 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||
{
|
||||
name: "test 100 negative",
|
||||
replication: "100",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
expected: false,
|
||||
@@ -30,8 +32,10 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||
{
|
||||
name: "test 100 positive",
|
||||
replication: "100",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
expected: true,
|
||||
@@ -39,10 +43,16 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||
{
|
||||
name: "test 022 positive",
|
||||
replication: "022",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||
expected: true,
|
||||
@@ -50,10 +60,16 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||
{
|
||||
name: "test 022 negative",
|
||||
replication: "022",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r4", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||
expected: false,
|
||||
@@ -61,10 +77,16 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||
{
|
||||
name: "test 210 moved from 200 positive",
|
||||
replication: "210",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r4", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||
expected: true,
|
||||
@@ -72,10 +94,16 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||
{
|
||||
name: "test 210 moved from 200 negative extra dc",
|
||||
replication: "210",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc4", "r4", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||
expected: false,
|
||||
@@ -83,10 +111,16 @@ func TestSatisfyReplicaPlacementComplicated(t *testing.T) {
|
||||
{
|
||||
name: "test 210 moved from 200 negative extra data node",
|
||||
replication: "210",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc3", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||
expected: false,
|
||||
@@ -103,9 +137,13 @@ func TestSatisfyReplicaPlacement01x(t *testing.T) {
|
||||
{
|
||||
name: "test 011 same existing rack",
|
||||
replication: "011",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
expected: true,
|
||||
@@ -113,9 +151,13 @@ func TestSatisfyReplicaPlacement01x(t *testing.T) {
|
||||
{
|
||||
name: "test 011 negative",
|
||||
replication: "011",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
expected: false,
|
||||
@@ -123,9 +165,13 @@ func TestSatisfyReplicaPlacement01x(t *testing.T) {
|
||||
{
|
||||
name: "test 011 different existing racks",
|
||||
replication: "011",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
expected: true,
|
||||
@@ -133,9 +179,13 @@ func TestSatisfyReplicaPlacement01x(t *testing.T) {
|
||||
{
|
||||
name: "test 011 different existing racks negative",
|
||||
replication: "011",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r3", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
expected: false,
|
||||
@@ -152,8 +202,10 @@ func TestSatisfyReplicaPlacement00x(t *testing.T) {
|
||||
{
|
||||
name: "test 001",
|
||||
replication: "001",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
expected: true,
|
||||
@@ -161,9 +213,13 @@ func TestSatisfyReplicaPlacement00x(t *testing.T) {
|
||||
{
|
||||
name: "test 002 positive",
|
||||
replication: "002",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
expected: true,
|
||||
@@ -171,9 +227,13 @@ func TestSatisfyReplicaPlacement00x(t *testing.T) {
|
||||
{
|
||||
name: "test 002 negative, repeat the same node",
|
||||
replication: "002",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
expected: false,
|
||||
@@ -181,10 +241,16 @@ func TestSatisfyReplicaPlacement00x(t *testing.T) {
|
||||
{
|
||||
name: "test 002 negative, enough node already",
|
||||
replication: "002",
|
||||
existingLocations: []location{
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
replicas: []*VolumeReplica{
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn2"}},
|
||||
},
|
||||
{
|
||||
location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn3"}},
|
||||
},
|
||||
},
|
||||
possibleLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn4"}},
|
||||
expected: false,
|
||||
@@ -199,9 +265,9 @@ func runTests(tests []testcase, t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
replicaPlacement, _ := super_block.NewReplicaPlacementFromString(tt.replication)
|
||||
println("replication:", tt.replication, "expected", tt.expected, "name:", tt.name)
|
||||
if satisfyReplicaPlacement(replicaPlacement, tt.existingLocations, tt.possibleLocation) != tt.expected {
|
||||
if satisfyReplicaPlacement(replicaPlacement, tt.replicas, tt.possibleLocation) != tt.expected {
|
||||
t.Errorf("%s: expect %v add %v to %s %+v",
|
||||
tt.name, tt.expected, tt.possibleLocation, tt.replication, tt.existingLocations)
|
||||
tt.name, tt.expected, tt.possibleLocation, tt.replication, tt.replicas)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
VERSION = fmt.Sprintf("%s %d.%d", sizeLimit, 1, 93)
|
||||
VERSION = fmt.Sprintf("%s %d.%d", sizeLimit, 1, 94)
|
||||
COMMIT = ""
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user