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.

remove go.uber.org/atomic

石昌林9e036df3566e
diff --git a/go.mod b/go.mod
index 455f07e41c..b7e358ee16 100644
--- a/go.mod
+++ b/go.mod
@@ -45,7 +45,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.4 // indirect
- github.com/google/btree v1.1.1
+ github.com/google/btree v1.0.1
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/uuid v1.3.0
github.com/google/wire v0.5.0 // indirect
@@ -123,16 +123,16 @@ require (
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/exp v0.0.0-20220414153411-bcd21879b8fd
golang.org/x/image v0.0.0-20200119044424-58c23975cae1
- golang.org/x/net v0.0.0-20220526153639-5463443f8c37
- golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401 // indirect
+ golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2
+ golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
- google.golang.org/api v0.82.0
+ google.golang.org/api v0.81.0
google.golang.org/appengine v1.6.7 // indirect
- google.golang.org/genproto v0.0.0-20220527130721-00d5c0f3be58 // indirect
- google.golang.org/grpc v1.47.0
+ google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect
+ google.golang.org/grpc v1.46.2
google.golang.org/protobuf v1.28.0
gopkg.in/inf.v0 v0.9.1 // indirect
modernc.org/b v1.0.0 // indirect
@@ -149,7 +149,6 @@ require (
require (
github.com/Jille/raft-grpc-transport v1.2.0
- github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d
github.com/arangodb/go-driver v1.3.2
github.com/fluent/fluent-logger-golang v1.9.0
github.com/hanwen/go-fuse/v2 v2.1.0
@@ -157,7 +156,6 @@ require (
github.com/hashicorp/raft-boltdb v0.0.0-20220329195025-15018e9b97e0
github.com/ydb-platform/ydb-go-sdk-auth-environ v0.1.2
github.com/ydb-platform/ydb-go-sdk/v3 v3.25.3
- go.uber.org/atomic v1.9.0
)
require (
@@ -213,6 +211,7 @@ require (
github.com/ydb-platform/ydb-go-yc-metadata v0.5.2 // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
+ go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 // indirect
diff --git a/go.sum b/go.sum
index 6ab0097369..6a66a4fc7a 100644
--- a/go.sum
+++ b/go.sum
@@ -136,7 +136,6 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
-github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/arangodb/go-driver v1.3.2 h1:07cmMqPqEl+/MlosjFtVVakEbkPqBSUvw9S9/atX0+4=
@@ -402,8 +401,8 @@ github.com/gomodule/redigo v1.8.2 h1:H5XSIre1MB5NbPYFp+i1NBbb5qN1W8Y8YAQoAYbkm8k
github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
-github.com/google/btree v1.1.1 h1:OMJCfqwmbcwNihVCadalGMZiHclz5T0mRv12gnIaV0Q=
-github.com/google/btree v1.1.1/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
+github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
+github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
@@ -1059,9 +1058,8 @@ golang.org/x/net v0.0.0-20220401154927-543a649e0bdd/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220420153159-1850ba15e1be/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
+golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 h1:NWy5+hlRbC7HK+PmcXVUmW1IMyFce7to56IUvhUFm7Y=
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
-golang.org/x/net v0.0.0-20220526153639-5463443f8c37 h1:lUkvobShwKsOesNfWWlCS5q7fnbG1MEliIzwu886fn8=
-golang.org/x/net v0.0.0-20220526153639-5463443f8c37/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -1082,9 +1080,8 @@ golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
+golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 h1:OSnWWcOd/CtWQC2cYSBgbTSJv3ciqd8r54ySIW2y3RE=
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
-golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401 h1:zwrSfklXn0gxyLRX/aR+q6cgHbV/ItVyzbPlbA+dkAw=
-golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -1335,8 +1332,8 @@ google.golang.org/api v0.74.0/go.mod h1:ZpfMZOVRMywNyvJFeqL9HRWBgAuRfSjJFpe9QtRR
google.golang.org/api v0.75.0/go.mod h1:pU9QmyHLnzlpar1Mjt4IbapUCy8J+6HD6GeELN69ljA=
google.golang.org/api v0.76.0/go.mod h1:pU9QmyHLnzlpar1Mjt4IbapUCy8J+6HD6GeELN69ljA=
google.golang.org/api v0.78.0/go.mod h1:1Sg78yoMLOhlQTeF+ARBoytAcH1NNyyl390YMy6rKmw=
-google.golang.org/api v0.82.0 h1:h6EGeZuzhoKSS7BUznzkW+2wHZ+4Ubd6rsVvvh3dRkw=
-google.golang.org/api v0.82.0/go.mod h1:Ld58BeTlL9DIYr2M2ajvoSqmGLei0BMn+kVBmkam1os=
+google.golang.org/api v0.81.0 h1:o8WF5AvfidafWbFjsRyupxyEQJNUWxLZJCK5NXrxZZ8=
+google.golang.org/api v0.81.0/go.mod h1:FA6Mb/bZxj706H2j+j2d6mHEEaHBmbbWnkfvmorOCko=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
@@ -1439,8 +1436,8 @@ google.golang.org/genproto v0.0.0-20220426171045-31bebdecfb46/go.mod h1:8w6bsBMX
google.golang.org/genproto v0.0.0-20220429170224-98d788798c3e/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
google.golang.org/genproto v0.0.0-20220518221133-4f43b3371335/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
-google.golang.org/genproto v0.0.0-20220527130721-00d5c0f3be58 h1:a221mAAEAzq4Lz6ZWRkcS8ptb2mxoxYSt4N68aRyQHM=
-google.golang.org/genproto v0.0.0-20220527130721-00d5c0f3be58/go.mod h1:yKyY4AMRwFiC8yMMNaMi+RkCnjZJt9LoWuvhXjMs+To=
+google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd h1:e0TwkXOdbnH/1x5rc5MZ/VYyiZ4v+RdVfrGMqEwT68I=
+google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
@@ -1471,9 +1468,8 @@ google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ5
google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
+google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ=
google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
-google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8=
-google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
diff --git a/weed/s3api/s3_constants/s3_config.go b/weed/s3api/s3_constants/s3_config.go
index 950124f055..0fa5b26f41 100644
--- a/weed/s3api/s3_constants/s3_config.go
+++ b/weed/s3api/s3_constants/s3_config.go
@@ -8,8 +8,8 @@ var (
CircuitBreakerConfigDir = "/etc/s3"
CircuitBreakerConfigFile = "circuit_breaker.json"
AllowedActions = []string{ACTION_READ, ACTION_WRITE, ACTION_LIST, ACTION_TAGGING, ACTION_ADMIN}
- LimitTypeCount = "count"
- LimitTypeBytes = "bytes"
+ LimitTypeCount = "Count"
+ LimitTypeBytes = "MB"
Separator = ":"
)
diff --git a/weed/s3api/s3api_circuit_breaker.go b/weed/s3api/s3api_circuit_breaker.go
index f5b0be94e1..7c8311d212 100644
--- a/weed/s3api/s3api_circuit_breaker.go
+++ b/weed/s3api/s3api_circuit_breaker.go
@@ -10,21 +10,21 @@ import (
"github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
"github.com/chrislusf/seaweedfs/weed/s3api/s3err"
"github.com/gorilla/mux"
- "go.uber.org/atomic"
"net/http"
"sync"
+ "sync/atomic"
)
type CircuitBreaker struct {
sync.Mutex
Enabled bool
- counters map[string]*atomic.Int64
+ counters map[string]*int64
limitations map[string]int64
}
func NewCircuitBreaker(option *S3ApiServerOption) *CircuitBreaker {
cb := &CircuitBreaker{
- counters: make(map[string]*atomic.Int64),
+ counters: make(map[string]*int64),
limitations: make(map[string]int64),
}
@@ -156,21 +156,22 @@ func (cb *CircuitBreaker) loadCounterAndCompare(bucket, action, limitType string
cb.Lock()
counter, exists = cb.counters[key]
if !exists {
- counter = atomic.NewInt64(0)
+ var newCounter int64
+ counter = &newCounter
cb.counters[key] = counter
}
cb.Unlock()
}
- current := counter.Load()
+ current := atomic.LoadInt64(counter)
if current+inc > max {
e = errCode
return
} else {
- counter.Add(inc)
+ current := atomic.AddInt64(counter, inc)
f = func() {
- counter.Sub(inc)
+ atomic.AddInt64(counter, -inc)
}
- current = counter.Load()
+ current = atomic.LoadInt64(counter)
if current > max {
e = errCode
return
diff --git a/weed/s3api/s3api_circuit_breaker_test.go b/weed/s3api/s3api_circuit_breaker_test.go
index 63d2dc2504..f795b75fc5 100644
--- a/weed/s3api/s3api_circuit_breaker_test.go
+++ b/weed/s3api/s3api_circuit_breaker_test.go
@@ -4,9 +4,9 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb/s3_pb"
"github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
"github.com/chrislusf/seaweedfs/weed/s3api/s3err"
- "go.uber.org/atomic"
"net/http"
"sync"
+ "sync/atomic"
"testing"
)
@@ -32,7 +32,7 @@ var (
{action, s3_constants.LimitTypeBytes, 1024, 1024, 6, 200, 5},
{action, s3_constants.LimitTypeBytes, 1200, 1200, 6, 200, 6},
{action, s3_constants.LimitTypeBytes, 11990, 11990, 60, 200, 59},
- {action, s3_constants.LimitTypeBytes, 11790, 11990, 60, 200, 58},
+ {action, s3_constants.LimitTypeBytes, 11790, 11990, 70, 200, 58},
}
)
@@ -56,7 +56,7 @@ func TestLimit(t *testing.T) {
},
}
circuitBreaker := &CircuitBreaker{
- counters: make(map[string]*atomic.Int64),
+ counters: make(map[string]*int64),
limitations: make(map[string]int64),
}
err := circuitBreaker.loadCircuitBreakerConfig(circuitBreakerConfig)
@@ -72,7 +72,7 @@ func TestLimit(t *testing.T) {
}
func doLimit(circuitBreaker *CircuitBreaker, routineCount int, r *http.Request) int64 {
- var successCounter atomic.Int64
+ var successCounter int64
resultCh := make(chan []func(), routineCount)
var wg sync.WaitGroup
for i := 0; i < routineCount; i++ {
@@ -81,7 +81,7 @@ func doLimit(circuitBreaker *CircuitBreaker, routineCount int, r *http.Request)
defer wg.Done()
rollbackFn, errCode := circuitBreaker.limit(r, bucket, action)
if errCode == s3err.ErrNone {
- successCounter.Inc()
+ atomic.AddInt64(&successCounter, 1)
}
resultCh <- rollbackFn
}()
@@ -93,5 +93,5 @@ func doLimit(circuitBreaker *CircuitBreaker, routineCount int, r *http.Request)
fn()
}
}
- return successCounter.Load()
+ return successCounter
}
diff --git a/weed/shell/command_s3_circuitbreaker.go b/weed/shell/command_s3_circuitbreaker.go
index 7d6eebf34d..7e11153bf3 100644
--- a/weed/shell/command_s3_circuitbreaker.go
+++ b/weed/shell/command_s3_circuitbreaker.go
@@ -4,7 +4,6 @@ import (
"bytes"
"flag"
"fmt"
- "github.com/alecthomas/units"
"github.com/chrislusf/seaweedfs/weed/filer"
"github.com/chrislusf/seaweedfs/weed/pb/s3_pb"
"github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
@@ -61,8 +60,8 @@ func (c *commandS3CircuitBreaker) Do(args []string, commandEnv *CommandEnv, writ
global := s3CircuitBreakerCommand.Bool("global", false, "configure global circuit breaker")
actions := s3CircuitBreakerCommand.String("actions", "", "comma separated actions names: Read,Write,List,Tagging,Admin")
- limitType := s3CircuitBreakerCommand.String("type", "", "count|bytes simultaneous requests count")
- values := s3CircuitBreakerCommand.String("values", "", "comma separated max values,Maximum number of simultaneous requests content length, support byte unit: eg: 1k, 10m, 1g")
+ limitType := s3CircuitBreakerCommand.String("type", "", "'Count' or 'MB'; Count represents the number of simultaneous requests, and MB represents the content size of all simultaneous requests")
+ values := s3CircuitBreakerCommand.String("values", "", "comma separated values")
disabled := s3CircuitBreakerCommand.Bool("disable", false, "disable global or buckets circuit breaker")
deleted := s3CircuitBreakerCommand.Bool("delete", false, "delete circuit breaker config")
@@ -326,7 +325,7 @@ func (c *commandS3CircuitBreaker) initActionsAndValues(buckets, actions, limitTy
if len(elements) != 1 || len(elements) == 0 {
return nil, nil, nil, fmt.Errorf("values count of -actions and -values not equal")
}
- v, err := units.ParseStrictBytes(elements[0])
+ v, err := parseMBToBytes(elements[0])
if err != nil {
return nil, nil, nil, fmt.Errorf("value of -max must be a legal number(s)")
}
@@ -335,7 +334,7 @@ func (c *commandS3CircuitBreaker) initActionsAndValues(buckets, actions, limitTy
}
} else {
for _, value := range elements {
- v, err := units.ParseStrictBytes(value)
+ v, err := parseMBToBytes(value)
if err != nil {
return nil, nil, nil, fmt.Errorf("value of -max must be a legal number(s)")
}
@@ -351,3 +350,9 @@ func (c *commandS3CircuitBreaker) initActionsAndValues(buckets, actions, limitTy
}
return cmdBuckets, cmdActions, cmdValues, nil
}
+
+func parseMBToBytes(valStr string) (int64, error) {
+ v, err := strconv.Atoi(valStr)
+ v *= 1024 * 1024
+ return int64(v), err
+}
diff --git a/weed/shell/command_s3_circuitbreaker_test.go b/weed/shell/command_s3_circuitbreaker_test.go
index 191a62e6a0..3d0b4ac6e4 100644
--- a/weed/shell/command_s3_circuitbreaker_test.go
+++ b/weed/shell/command_s3_circuitbreaker_test.go
@@ -17,13 +17,13 @@ var (
TestCases = []*Case{
//add circuit breaker config for global
{
- args: strings.Split("-global -type count -actions Read,Write -values 500,200", " "),
+ args: strings.Split("-global -type Count -actions Read,Write -values 500,200", " "),
result: `{
"global": {
"enabled": true,
"actions": {
- "Read:count": "500",
- "Write:count": "200"
+ "Read:Count": "500",
+ "Write:Count": "200"
}
}
}`,
@@ -35,8 +35,8 @@ var (
result: `{
"global": {
"actions": {
- "Read:count": "500",
- "Write:count": "200"
+ "Read:Count": "500",
+ "Write:Count": "200"
}
}
}`,
@@ -44,34 +44,34 @@ var (
//add circuit breaker config for buckets x,y,z
{
- args: strings.Split("-buckets x,y,z -type count -actions Read,Write -values 200,100", " "),
+ args: strings.Split("-buckets x,y,z -type Count -actions Read,Write -values 200,100", " "),
result: `{
"global": {
"actions": {
- "Read:count": "500",
- "Write:count": "200"
+ "Read:Count": "500",
+ "Write:Count": "200"
}
},
"buckets": {
"x": {
"enabled": true,
"actions": {
- "Read:count": "200",
- "Write:count": "100"
+ "Read:Count": "200",
+ "Write:Count": "100"
}
},
"y": {
"enabled": true,
"actions": {
- "Read:count": "200",
- "Write:count": "100"
+ "Read:Count": "200",
+ "Write:Count": "100"
}
},
"z": {
"enabled": true,
"actions": {
- "Read:count": "200",
- "Write:count": "100"
+ "Read:Count": "200",
+ "Write:Count": "100"
}
}
}
@@ -84,29 +84,29 @@ var (
result: `{
"global": {
"actions": {
- "Read:count": "500",
- "Write:count": "200"
+ "Read:Count": "500",
+ "Write:Count": "200"
}
},
"buckets": {
"x": {
"actions": {
- "Read:count": "200",
- "Write:count": "100"
+ "Read:Count": "200",
+ "Write:Count": "100"
}
},
"y": {
"enabled": true,
"actions": {
- "Read:count": "200",
- "Write:count": "100"
+ "Read:Count": "200",
+ "Write:Count": "100"
}
},
"z": {
"enabled": true,
"actions": {
- "Read:count": "200",
- "Write:count": "100"
+ "Read:Count": "200",
+ "Write:Count": "100"
}
}
}
@@ -119,23 +119,124 @@ var (
result: `{
"global": {
"actions": {
- "Read:count": "500",
- "Write:count": "200"
+ "Read:Count": "500",
+ "Write:Count": "200"
}
},
"buckets": {
"y": {
"enabled": true,
"actions": {
- "Read:count": "200",
- "Write:count": "100"
+ "Read:Count": "200",
+ "Write:Count": "100"
}
},
"z": {
"enabled": true,
"actions": {
- "Read:count": "200",
- "Write:count": "100"
+ "Read:Count": "200",
+ "Write:Count": "100"
+ }
+ }
+ }
+ }`,
+ },
+
+ //configure the circuit breaker for the size of the uploaded file for bucket x,y
+ {
+ args: strings.Split("-buckets x,y -type MB -actions Write -values 1024", " "),
+ result: `{
+ "global": {
+ "actions": {
+ "Read:Count": "500",
+ "Write:Count": "200"
+ }
+ },
+ "buckets": {
+ "x": {
+ "enabled": true,
+ "actions": {
+ "Write:MB": "1073741824"
+ }
+ },
+ "y": {
+ "enabled": true,
+ "actions": {
+ "Read:Count": "200",
+ "Write:Count": "100",
+ "Write:MB": "1073741824"
+ }
+ },
+ "z": {
+ "enabled": true,
+ "actions": {
+ "Read:Count": "200",
+ "Write:Count": "100"
+ }
+ }
+ }
+ }`,
+ },
+
+ //delete the circuit breaker configuration for the size of the uploaded file of bucket x,y
+ {
+ args: strings.Split("-buckets x,y -type MB -actions Write -delete", " "),
+ result: `{
+ "global": {
+ "actions": {
+ "Read:Count": "500",
+ "Write:Count": "200"
+ }
+ },
+ "buckets": {
+ "x": {
+ "enabled": true
+ },
+ "y": {
+ "enabled": true,
+ "actions": {
+ "Read:Count": "200",
+ "Write:Count": "100"
+ }
+ },
+ "z": {
+ "enabled": true,
+ "actions": {
+ "Read:Count": "200",
+ "Write:Count": "100"
+ }
+ }
+ }
+ }`,
+ },
+
+ //enable global circuit breaker config (without -disable flag)
+ {
+ args: strings.Split("-global", " "),
+ result: `{
+ "global": {
+ "enabled": true,
+ "actions": {
+ "Read:Count": "500",
+ "Write:Count": "200"
+ }
+ },
+ "buckets": {
+ "x": {
+ "enabled": true
+ },
+ "y": {
+ "enabled": true,
+ "actions": {
+ "Read:Count": "200",
+ "Write:Count": "100"
+ }
+ },
+ "z": {
+ "enabled": true,
+ "actions": {
+ "Read:Count": "200",
+ "Write:Count": "100"
}
}
}