diff options
| author | chrislu <chris.lu@gmail.com> | 2024-08-21 16:58:40 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2024-08-21 16:58:43 -0700 |
| commit | 5535b60e8c60511ca393d47fa59f66c378ab977e (patch) | |
| tree | cce8fdd1c054e30fc9785e3780fb340e42967ca2 /weed | |
| parent | 95bae91ca750b2b90cf702df9561fd8b5a82c14c (diff) | |
| download | seaweedfs-5535b60e8c60511ca393d47fa59f66c378ab977e.tar.xz seaweedfs-5535b60e8c60511ca393d47fa59f66c378ab977e.zip | |
fix replication range check
fix for https://github.com/seaweedfs/seaweedfs/wiki/Replication#replication-string
Diffstat (limited to 'weed')
| -rw-r--r-- | weed/storage/super_block/replica_placement.go | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/weed/storage/super_block/replica_placement.go b/weed/storage/super_block/replica_placement.go index a263e6669..9a59eb258 100644 --- a/weed/storage/super_block/replica_placement.go +++ b/weed/storage/super_block/replica_placement.go @@ -1,7 +1,6 @@ package super_block import ( - "errors" "fmt" ) @@ -15,18 +14,21 @@ func NewReplicaPlacementFromString(t string) (*ReplicaPlacement, error) { rp := &ReplicaPlacement{} for i, c := range t { count := int(c - '0') - if 0 <= count && count <= 2 { - switch i { - case 0: - rp.DiffDataCenterCount = count - case 1: - rp.DiffRackCount = count - case 2: - rp.SameRackCount = count - } - } else { - return rp, errors.New("Unknown Replication Type:" + t) + if count < 0 { + return rp, fmt.Errorf("unknown replication type: %s", 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 } |
