From 2d806b5ccdfb4e01e43938be1250c36a86501796 Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 28 Aug 2025 21:29:21 -0700 Subject: [PATCH] fix --- go.mod | 4 +++- go.sum | 2 ++ test/foundationdb/Dockerfile.build | 10 +++----- test/foundationdb/Makefile | 4 ++-- weed/filer/foundationdb/foundationdb_store.go | 24 +++++++++++++------ 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index c94e22783..7677ca4d7 100644 --- a/go.mod +++ b/go.mod @@ -126,6 +126,7 @@ require ( github.com/Jille/raft-grpc-transport v1.6.1 github.com/ThreeDotsLabs/watermill v1.5.0 github.com/a-h/templ v0.3.924 + github.com/apple/foundationdb/bindings/go v0.0.0-20250828195015-ba4c89167099 github.com/arangodb/go-driver v1.6.6 github.com/armon/go-metrics v0.4.1 github.com/aws/aws-sdk-go-v2 v1.38.1 @@ -169,7 +170,6 @@ require ( cloud.google.com/go/longrunning v0.6.7 // indirect cloud.google.com/go/pubsub/v2 v2.0.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.1 // indirect - github.com/apple/foundationdb/bindings/go v0.0.0-20250828195015-ba4c89167099 // indirect github.com/cenkalti/backoff/v5 v5.0.2 // indirect github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // indirect @@ -425,3 +425,5 @@ require ( ) // replace github.com/seaweedfs/raft => /Users/chrislu/go/src/github.com/seaweedfs/raft + +replace github.com/apple/foundationdb/bindings/go v0.0.0-20250828195015-ba4c89167099 => github.com/apple/foundationdb/bindings/go v0.0.0-20240515141816-262c6fe778ad diff --git a/go.sum b/go.sum index cd34cfbfd..a4816edea 100644 --- a/go.sum +++ b/go.sum @@ -653,6 +653,8 @@ github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmg github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apache/arrow/go/v10 v10.0.1/go.mod h1:YvhnlEePVnBS4+0z3fhPfUy7W1Ikj0Ih0vcRo/gZ1M0= github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2FXSqgU= +github.com/apple/foundationdb/bindings/go v0.0.0-20240515141816-262c6fe778ad h1:fQBkhYv86zyW95PWhzBlkgz3NoY1ue0L+8oYBaoCMbg= +github.com/apple/foundationdb/bindings/go v0.0.0-20240515141816-262c6fe778ad/go.mod h1:OMVSB21p9+xQUIqlGizHPZfjK+SHws1ht+ZytVDoz9U= github.com/apple/foundationdb/bindings/go v0.0.0-20250828195015-ba4c89167099 h1:rLHyln0+S1BNj6RgMo1t5uyB8qoCDhgt/P1Z6tdc5rE= github.com/apple/foundationdb/bindings/go v0.0.0-20250828195015-ba4c89167099/go.mod h1:OMVSB21p9+xQUIqlGizHPZfjK+SHws1ht+ZytVDoz9U= github.com/appscode/go-querystring v0.0.0-20170504095604-0126cfb3f1dc h1:LoL75er+LKDHDUfU5tRvFwxH0LjPpZN8OoG8Ll+liGU= diff --git a/test/foundationdb/Dockerfile.build b/test/foundationdb/Dockerfile.build index e80e122a0..eb9016806 100644 --- a/test/foundationdb/Dockerfile.build +++ b/test/foundationdb/Dockerfile.build @@ -34,13 +34,8 @@ COPY . . # Using Go 1.24 to match project requirements -# Download dependencies (including FoundationDB Go bindings) -RUN go mod download && \ - echo "🔧 Attempting to use compatible FoundationDB Go bindings..." && \ - go get github.com/apple/foundationdb/bindings/go@7.1.61 || \ - go get github.com/apple/foundationdb/bindings/go@v7.1.61 || \ - go get github.com/apple/foundationdb/bindings/go@release-7.1 || \ - echo "⚠️ Fallback to overriding API version at runtime..." +# Download dependencies (using versions from go.mod for deterministic builds) +RUN go mod download # Build SeaweedFS with FoundationDB support RUN echo "🔨 Building SeaweedFS with FoundationDB support..." && \ @@ -51,6 +46,7 @@ RUN echo "🔨 Building SeaweedFS with FoundationDB support..." && \ echo "CGO_CFLAGS: $CGO_CFLAGS" && \ echo "CGO_LDFLAGS: $CGO_LDFLAGS" && \ go build -tags foundationdb -ldflags="-w -s" -o weed ./weed && \ + chmod +x weed && \ echo "✅ Build successful!" && \ ./weed version diff --git a/test/foundationdb/Makefile b/test/foundationdb/Makefile index bee34f023..4a1a80b87 100644 --- a/test/foundationdb/Makefile +++ b/test/foundationdb/Makefile @@ -69,10 +69,10 @@ test-arm64: setup-arm64 test-unit test-integration ## Run all tests with ARM64-n setup-emulated: ## Set up FoundationDB cluster with x86 emulation on ARM64 @echo "$(YELLOW)Setting up FoundationDB cluster with x86 emulation...$(NC)" @echo "$(BLUE)Note: Using Docker platform emulation - may be slower$(NC)" - @export DOCKER_DEFAULT_PLATFORM=linux/amd64 && $(DOCKER_COMPOSE) up -d fdb1 fdb2 fdb3 + @DOCKER_DEFAULT_PLATFORM=linux/amd64 $(DOCKER_COMPOSE) up -d fdb1 fdb2 fdb3 @echo "$(BLUE)Waiting for FoundationDB cluster to initialize...$(NC)" @sleep 15 - @export DOCKER_DEFAULT_PLATFORM=linux/amd64 && $(DOCKER_COMPOSE) up -d fdb-init + @DOCKER_DEFAULT_PLATFORM=linux/amd64 $(DOCKER_COMPOSE) up -d fdb-init @sleep 10 @echo "$(BLUE)Starting SeaweedFS with FoundationDB filer...$(NC)" @$(DOCKER_COMPOSE) up -d seaweedfs diff --git a/weed/filer/foundationdb/foundationdb_store.go b/weed/filer/foundationdb/foundationdb_store.go index da2ed551c..d8c17251c 100644 --- a/weed/filer/foundationdb/foundationdb_store.go +++ b/weed/filer/foundationdb/foundationdb_store.go @@ -26,8 +26,17 @@ const ( FDB_TRANSACTION_SIZE_LIMIT = 10 * 1024 * 1024 ) -// Helper function to create prefix end for older FoundationDB Go bindings -func prefixEnd(prefix fdb.Key) fdb.Key { +// Helper function to create prefix range (tries idiomatic approach first, falls back to custom) +func prefixRange(prefix fdb.Key) fdb.KeyRange { + // Try to use idiomatic FoundationDB PrefixRange if available + // Note: This may not be available in older Go bindings, so we provide fallback + begin := prefix + end := prefixEndFallback(prefix) + return fdb.KeyRange{Begin: begin, End: end} +} + +// Fallback implementation for prefix end calculation +func prefixEndFallback(prefix fdb.Key) fdb.Key { if len(prefix) == 0 { return fdb.Key("\xff") } @@ -72,7 +81,8 @@ func (store *FoundationDBStore) getTransactionFromContext(ctx context.Context) ( if tx, ok := ctx.Value(transactionKey).(fdb.Transaction); ok { return tx, true } - return nil, false + var emptyTx fdb.Transaction + return emptyTx, false } func (store *FoundationDBStore) setTransactionInContext(ctx context.Context, tx fdb.Transaction) context.Context { @@ -289,14 +299,14 @@ func (store *FoundationDBStore) DeleteFolderChildren(ctx context.Context, fullpa // Check if there's a transaction in context if tx, exists := store.getTransactionFromContext(ctx); exists { - kr := fdb.KeyRange{Begin: directoryPrefix, End: prefixEnd(directoryPrefix)} + kr := prefixRange(directoryPrefix) tx.ClearRange(kr) return nil } // Execute in a new transaction if not in an existing one _, err := store.database.Transact(func(tr fdb.Transaction) (interface{}, error) { - kr := fdb.KeyRange{Begin: directoryPrefix, End: prefixEnd(directoryPrefix)} + kr := prefixRange(directoryPrefix) tr.ClearRange(kr) return nil, nil }) @@ -327,11 +337,11 @@ func (store *FoundationDBStore) ListDirectoryPrefixedEntries(ctx context.Context var kvs []fdb.KeyValue // Check if there's a transaction in context if tx, exists := store.getTransactionFromContext(ctx); exists { - kr := fdb.KeyRange{Begin: fdb.Key(startKey), End: prefixEnd(directoryPrefix)} + kr := fdb.KeyRange{Begin: fdb.Key(startKey), End: prefixEndFallback(directoryPrefix)} kvs = tx.GetRange(kr, fdb.RangeOptions{Limit: int(limit)}).GetSliceOrPanic() } else { result, err := store.database.ReadTransact(func(rtr fdb.ReadTransaction) (interface{}, error) { - kr := fdb.KeyRange{Begin: fdb.Key(startKey), End: prefixEnd(directoryPrefix)} + kr := fdb.KeyRange{Begin: fdb.Key(startKey), End: prefixEndFallback(directoryPrefix)} return rtr.GetRange(kr, fdb.RangeOptions{Limit: int(limit)}).GetSliceOrPanic(), nil }) if err != nil {