Browse Source

delete with prefix range; list with right start key

pull/7178/head
chrislu 2 months ago
parent
commit
414890220c
  1. 3
      test/foundationdb/Dockerfile.build
  2. 3
      test/foundationdb/Dockerfile.fdb-arm64
  3. 38
      weed/filer/foundationdb/foundationdb_store.go

3
test/foundationdb/Dockerfile.build

@ -37,9 +37,6 @@ COPY . .
# Using Go 1.24 to match project requirements
# Download foundationdb binding
RUN go get github.com/apple/foundationdb/bindings/go@${FOUNDATIONDB_VERSION}
# Download dependencies (using versions from go.mod for deterministic builds)
RUN go mod download

3
test/foundationdb/Dockerfile.fdb-arm64

@ -24,7 +24,8 @@ WORKDIR /tmp
RUN git clone https://github.com/apple/foundationdb.git
WORKDIR /tmp/foundationdb
# Checkout a stable release version
# Checkout a stable release version (ARM64 build from source)
# Using 7.1 branch as 7.4.5 ARM64 builds are not available pre-built
RUN git checkout release-7.1
# Build FoundationDB (disable bindings that cause issues)

38
weed/filer/foundationdb/foundationdb_store.go

@ -266,12 +266,11 @@ func (store *FoundationDBStore) DeleteEntry(ctx context.Context, fullpath util.F
func (store *FoundationDBStore) DeleteFolderChildren(ctx context.Context, fullpath util.FullPath) error {
// Construct tuple-aware range for all children in this directory
// Use FDBRangeKeys for proper tuple-encoded range
beginKey, endKey := tuple.Tuple{string(fullpath)}.FDBRangeKeys()
// Pack with directory subspace
startKey := store.seaweedfsDir.Pack(beginKey)
endKeyPacked := store.seaweedfsDir.Pack(endKey)
kr := fdb.KeyRange{Begin: startKey, End: endKeyPacked}
prefixBytes := store.seaweedfsDir.Pack(tuple.Tuple{string(fullpath)})
kr, err := fdb.PrefixRange(prefixBytes)
if err != nil {
return fmt.Errorf("creating prefix range for %s: %v", fullpath, err)
}
// Check if there's a transaction in context
if tx, exists := store.getTransactionFromContext(ctx); exists {
@ -280,7 +279,7 @@ func (store *FoundationDBStore) DeleteFolderChildren(ctx context.Context, fullpa
}
// 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) {
tr.ClearRange(kr)
return nil, nil
})
@ -301,17 +300,22 @@ func (store *FoundationDBStore) ListDirectoryPrefixedEntries(ctx context.Context
limit = 1000
}
// For tuple-encoded keys, construct range using directory tuples
var startKey fdb.Key
var endKey fdb.Key
// Get the range for the entire directory using tuple-aware prefix range
dirPrefixBytes := store.seaweedfsDir.Pack(tuple.Tuple{string(dirPath)})
dirRange, err := fdb.PrefixRange(dirPrefixBytes)
if err != nil {
return "", fmt.Errorf("creating prefix range for %s: %v", dirPath, err)
}
// Determine start key based on startFileName and prefix
var startKey fdb.Key
if startFileName != "" {
// Start from the specified file
startKey = store.seaweedfsDir.Pack(tuple.Tuple{string(dirPath), startFileName})
if !includeStartFile {
// Append 0x00 to exclude the start key itself
startKey = append(startKey, 0x00)
// Use next possible tuple to exclude start key (append \x00 to fileName in tuple, not to packed bytes)
startKey = store.seaweedfsDir.Pack(tuple.Tuple{string(dirPath), startFileName + "\x00"})
} else {
startKey = store.seaweedfsDir.Pack(tuple.Tuple{string(dirPath), startFileName})
}
// If prefix is specified and startFileName doesn't match, adjust
if prefix != "" && !strings.HasPrefix(startFileName, prefix) {
@ -325,13 +329,11 @@ func (store *FoundationDBStore) ListDirectoryPrefixedEntries(ctx context.Context
startKey = store.seaweedfsDir.Pack(tuple.Tuple{string(dirPath), prefix})
} else {
// Start from beginning of directory
startKey = store.seaweedfsDir.Pack(tuple.Tuple{string(dirPath), ""})
startKey = dirRange.Begin
}
// Compute the end key using tuple-aware range
// This ensures we stay within the directory bounds
beginTuple, endTuple := tuple.Tuple{string(dirPath)}.FDBRangeKeys()
endKey = store.seaweedfsDir.Pack(endTuple)
// End key is from the directory range
endKey := dirRange.End
var kvs []fdb.KeyValue
var rangeErr error

Loading…
Cancel
Save