This commit is contained in:
chrislu
2025-08-28 21:29:21 -07:00
parent 6d7cd2b73d
commit 2d806b5ccd
5 changed files with 27 additions and 17 deletions

4
go.mod
View File

@@ -126,6 +126,7 @@ require (
github.com/Jille/raft-grpc-transport v1.6.1 github.com/Jille/raft-grpc-transport v1.6.1
github.com/ThreeDotsLabs/watermill v1.5.0 github.com/ThreeDotsLabs/watermill v1.5.0
github.com/a-h/templ v0.3.924 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/arangodb/go-driver v1.6.6
github.com/armon/go-metrics v0.4.1 github.com/armon/go-metrics v0.4.1
github.com/aws/aws-sdk-go-v2 v1.38.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/longrunning v0.6.7 // indirect
cloud.google.com/go/pubsub/v2 v2.0.0 // 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/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/cenkalti/backoff/v5 v5.0.2 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // 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/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

2
go.sum
View File

@@ -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/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/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/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 h1:rLHyln0+S1BNj6RgMo1t5uyB8qoCDhgt/P1Z6tdc5rE=
github.com/apple/foundationdb/bindings/go v0.0.0-20250828195015-ba4c89167099/go.mod h1:OMVSB21p9+xQUIqlGizHPZfjK+SHws1ht+ZytVDoz9U= 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= github.com/appscode/go-querystring v0.0.0-20170504095604-0126cfb3f1dc h1:LoL75er+LKDHDUfU5tRvFwxH0LjPpZN8OoG8Ll+liGU=

View File

@@ -34,13 +34,8 @@ COPY . .
# Using Go 1.24 to match project requirements # Using Go 1.24 to match project requirements
# Download dependencies (including FoundationDB Go bindings) # Download dependencies (using versions from go.mod for deterministic builds)
RUN go mod download && \ 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..."
# Build SeaweedFS with FoundationDB support # Build SeaweedFS with FoundationDB support
RUN echo "🔨 Building 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_CFLAGS: $CGO_CFLAGS" && \
echo "CGO_LDFLAGS: $CGO_LDFLAGS" && \ echo "CGO_LDFLAGS: $CGO_LDFLAGS" && \
go build -tags foundationdb -ldflags="-w -s" -o weed ./weed && \ go build -tags foundationdb -ldflags="-w -s" -o weed ./weed && \
chmod +x weed && \
echo "✅ Build successful!" && \ echo "✅ Build successful!" && \
./weed version ./weed version

View File

@@ -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 setup-emulated: ## Set up FoundationDB cluster with x86 emulation on ARM64
@echo "$(YELLOW)Setting up FoundationDB cluster with x86 emulation...$(NC)" @echo "$(YELLOW)Setting up FoundationDB cluster with x86 emulation...$(NC)"
@echo "$(BLUE)Note: Using Docker platform emulation - may be slower$(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)" @echo "$(BLUE)Waiting for FoundationDB cluster to initialize...$(NC)"
@sleep 15 @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 @sleep 10
@echo "$(BLUE)Starting SeaweedFS with FoundationDB filer...$(NC)" @echo "$(BLUE)Starting SeaweedFS with FoundationDB filer...$(NC)"
@$(DOCKER_COMPOSE) up -d seaweedfs @$(DOCKER_COMPOSE) up -d seaweedfs

View File

@@ -26,8 +26,17 @@ const (
FDB_TRANSACTION_SIZE_LIMIT = 10 * 1024 * 1024 FDB_TRANSACTION_SIZE_LIMIT = 10 * 1024 * 1024
) )
// Helper function to create prefix end for older FoundationDB Go bindings // Helper function to create prefix range (tries idiomatic approach first, falls back to custom)
func prefixEnd(prefix fdb.Key) fdb.Key { 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 { if len(prefix) == 0 {
return fdb.Key("\xff") return fdb.Key("\xff")
} }
@@ -72,7 +81,8 @@ func (store *FoundationDBStore) getTransactionFromContext(ctx context.Context) (
if tx, ok := ctx.Value(transactionKey).(fdb.Transaction); ok { if tx, ok := ctx.Value(transactionKey).(fdb.Transaction); ok {
return tx, true 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 { 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 // Check if there's a transaction in context
if tx, exists := store.getTransactionFromContext(ctx); exists { if tx, exists := store.getTransactionFromContext(ctx); exists {
kr := fdb.KeyRange{Begin: directoryPrefix, End: prefixEnd(directoryPrefix)} kr := prefixRange(directoryPrefix)
tx.ClearRange(kr) tx.ClearRange(kr)
return nil return nil
} }
// Execute in a new transaction if not in an existing one // Execute in a new transaction if not in an existing one
_, err := store.database.Transact(func(tr fdb.Transaction) (interface{}, error) { _, err := store.database.Transact(func(tr fdb.Transaction) (interface{}, error) {
kr := fdb.KeyRange{Begin: directoryPrefix, End: prefixEnd(directoryPrefix)} kr := prefixRange(directoryPrefix)
tr.ClearRange(kr) tr.ClearRange(kr)
return nil, nil return nil, nil
}) })
@@ -327,11 +337,11 @@ func (store *FoundationDBStore) ListDirectoryPrefixedEntries(ctx context.Context
var kvs []fdb.KeyValue var kvs []fdb.KeyValue
// Check if there's a transaction in context // Check if there's a transaction in context
if tx, exists := store.getTransactionFromContext(ctx); exists { 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() kvs = tx.GetRange(kr, fdb.RangeOptions{Limit: int(limit)}).GetSliceOrPanic()
} else { } else {
result, err := store.database.ReadTransact(func(rtr fdb.ReadTransaction) (interface{}, error) { 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 return rtr.GetRange(kr, fdb.RangeOptions{Limit: int(limit)}).GetSliceOrPanic(), nil
}) })
if err != nil { if err != nil {