From 4c96fccacee91db23ad165183b31819005045914 Mon Sep 17 00:00:00 2001 From: Conor Nolan Date: Tue, 3 Dec 2024 09:01:54 +0000 Subject: [PATCH] Remove bucket exists cache (#302) * Remove unused cache for bucket exists * go mod vendor --- cmd/provider/main.go | 4 ---- go.mod | 1 - go.sum | 2 -- internal/rgw/bucket.go | 5 ---- internal/rgw/cache/cache.go | 46 ------------------------------------- 5 files changed, 58 deletions(-) delete mode 100644 internal/rgw/cache/cache.go diff --git a/cmd/provider/main.go b/cmd/provider/main.go index a24b8491..48bd1916 100644 --- a/cmd/provider/main.go +++ b/cmd/provider/main.go @@ -66,7 +66,6 @@ import ( "github.com/linode/provider-ceph/internal/controller/s3clienthandler" "github.com/linode/provider-ceph/internal/features" - "github.com/linode/provider-ceph/internal/rgw/cache" ) var defaultZapConfig = map[string]string{ @@ -87,7 +86,6 @@ func main() { backendMonitorInterval = app.Flag("backend-monitor-interval", "Interval between backend monitor controller reconciliations.").Default("60s").Duration() pollInterval = app.Flag("poll", "How often individual resources will be checked for drift from the desired state").Short('p').Default("30m").Duration() pollStateMetricInterval = app.Flag("poll-state-metric", "State metric recording interval").Default("5s").Duration() - bucketExistsCache = app.Flag("bucket-exists-cache", "How long the provider caches bucket exists result").Short('c').Default("5s").Duration() reconcileConcurrency = app.Flag("reconcile-concurrency", "Set number of reconciliation loops.").Default("100").Int() maxReconcileRate = app.Flag("max-reconcile-rate", "The global maximum rate per second at which resources may checked for drift from the desired state.").Default("1000").Int() reconcileTimeout = app.Flag("reconcile-timeout", "Object reconciliation timeout").Short('t').Default("3s").Duration() @@ -214,8 +212,6 @@ func main() { cfg = ratelimiter.LimitRESTConfig(cfg, *kubeClientRate) - cache.BucketExistsCacheTTL = *bucketExistsCache - const oneDotTwo = 1.2 const two = 2 diff --git a/go.mod b/go.mod index a51eaa2e..481fdb1d 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ toolchain go1.23.1 require ( github.com/alecthomas/kingpin/v2 v2.3.2 - github.com/allegro/bigcache/v3 v3.1.0 github.com/aws/aws-sdk-go-v2 v1.25.2 github.com/aws/aws-sdk-go-v2/config v1.27.4 github.com/aws/aws-sdk-go-v2/credentials v1.17.4 diff --git a/go.sum b/go.sum index abff018c..84a92014 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc= github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= -github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk= -github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I= github.com/aws/aws-sdk-go-v2 v1.25.2 h1:/uiG1avJRgLGiQM9X3qJM8+Qa6KRGK5rRPuXE0HUM+w= github.com/aws/aws-sdk-go-v2 v1.25.2/go.mod h1:Evoc5AsmtveRt1komDwIsjHFyrP5tDuF1D1U+6z6pNo= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 h1:gTK2uhtAPtFcdRRJilZPx8uJLL2J85xK11nKtWL0wfU= diff --git a/internal/rgw/bucket.go b/internal/rgw/bucket.go index a7058852..6e420574 100644 --- a/internal/rgw/bucket.go +++ b/internal/rgw/bucket.go @@ -10,7 +10,6 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/resource" "github.com/linode/provider-ceph/internal/backendstore" "github.com/linode/provider-ceph/internal/otel/traces" - "github.com/linode/provider-ceph/internal/rgw/cache" "go.opentelemetry.io/otel" "golang.org/x/sync/errgroup" ) @@ -40,8 +39,6 @@ func CreateBucket(ctx context.Context, s3Backend backendstore.S3Client, bucket * return resp, errors.Wrap(err, errCreateBucket) } - cache.Set(*bucket.Bucket) - return resp, err } @@ -61,8 +58,6 @@ func BucketExists(ctx context.Context, s3Backend backendstore.S3Client, bucketNa return false, errors.Wrap(err, errHeadBucket) } - cache.Set(bucketName) - // Bucket exists, return true with no error. return true, nil } diff --git a/internal/rgw/cache/cache.go b/internal/rgw/cache/cache.go deleted file mode 100644 index 481a1175..00000000 --- a/internal/rgw/cache/cache.go +++ /dev/null @@ -1,46 +0,0 @@ -package cache - -import ( - "context" - "sync" - "time" - - "github.com/alecthomas/kingpin/v2" - "github.com/allegro/bigcache/v3" -) - -var ( - BucketExistsCacheTTL = time.Duration(0) - - bucketExistsCache *bigcache.BigCache - bucketExistsCacheEntry = make([]byte, 0) - bucketExistsCacheInit = sync.Once{} -) - -func bucketExistsCacheInitFunc() { - config := bigcache.DefaultConfig(BucketExistsCacheTTL) - config.MaxEntrySize = 0 - config.Verbose = false - config.Logger = nil - - var err error - bucketExistsCache, err = bigcache.New(context.Background(), config) - kingpin.FatalIfError(err, "Cannot create S3 bucket exists client cache") -} - -func Exists(key string) bool { - bucketExistsCacheInit.Do(bucketExistsCacheInitFunc) - - _, err := bucketExistsCache.Get(key) - - return err == nil -} - -func Set(key string) { - bucketExistsCacheInit.Do(bucketExistsCacheInitFunc) - - err := bucketExistsCache.Set(key, bucketExistsCacheEntry) - if err != nil { - kingpin.Errorf("failed to set bucket exists cache entry: %w", err) - } -}