Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix replication range check

chrislu5535b60e8c60
diff --git a/weed/storage/super_block/replica_placement.go b/weed/storage/super_block/replica_placement.go
index a263e6669b..9a59eb258c 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
}