fix replication range check
fix for https://github.com/seaweedfs/seaweedfs/wiki/Replication#replication-string
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package super_block
|
package super_block
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,18 +14,21 @@ func NewReplicaPlacementFromString(t string) (*ReplicaPlacement, error) {
|
|||||||
rp := &ReplicaPlacement{}
|
rp := &ReplicaPlacement{}
|
||||||
for i, c := range t {
|
for i, c := range t {
|
||||||
count := int(c - '0')
|
count := int(c - '0')
|
||||||
if 0 <= count && count <= 2 {
|
if count < 0 {
|
||||||
switch i {
|
return rp, fmt.Errorf("unknown replication type: %s", t)
|
||||||
case 0:
|
|
||||||
rp.DiffDataCenterCount = count
|
|
||||||
case 1:
|
|
||||||
rp.DiffRackCount = count
|
|
||||||
case 2:
|
|
||||||
rp.SameRackCount = count
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return rp, errors.New("Unknown Replication Type:" + t)
|
|
||||||
}
|
}
|
||||||
|
switch i {
|
||||||
|
case 0:
|
||||||
|
rp.DiffDataCenterCount = count
|
||||||
|
case 1:
|
||||||
|
rp.DiffRackCount = count
|
||||||
|
case 2:
|
||||||
|
rp.SameRackCount = count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value := rp.DiffDataCenterCount*100 + rp.DiffRackCount*10 + rp.SameRackCount
|
||||||
|
if value > 255 {
|
||||||
|
return rp, fmt.Errorf("unexpected replication type: %s", t)
|
||||||
}
|
}
|
||||||
return rp, nil
|
return rp, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user