mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* filer: run an entry update again when a rename or delete of it commits meanwhile
UpdateEntry reads the entry, checks its preconditions against it, then
writes. The path lock keeps the two together only against writers of that
path on that filer. A rename or a delete sent to another filer does not
take it, and on any filer a rename or recursive delete of a directory above
the entry moves and removes what is below it unlocked. One that committed
between the read and the write had the write store the entry again at the
path it had left, and the update returned success: the entry back under a
directory that is gone, two names sharing chunks, or a file back after its
unlink returned.
Where the store refuses a conflicting commit, the read, the checks and the
write now run in one store transaction. The rename or delete wrote the
entry's key after it began, so the commit is refused with
ErrTransactionConflict and the update runs again, up to five times with
the rename's back-off, and answers from what is there now.
- filer.ConflictRefusingStore is how a store says so. TiKV does. Other
stores, and entries in a path-specific store, run once without a
transaction, as before.
- A refused run gives up its commit stamp and deletes the manifest chunks
it folded the request's chunks into.
- Chunk deletion and the metadata event come after the commit, in the
order they had.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* filer: commit what an update's lookup removed, give up a failed run's manifests
From the review of 156a0078c.
FindEntry removes an expired entry and, for an expired S3 object, tells the
subscribers. Inside the update's transaction a NotFound rolled that removal
back while the event stayed, and the next lookup announced it again. What
the read answers the update with (the entry is not there, a precondition
does not hold) is now the run's result and not its failure: the run commits
whatever the lookup removed and UpdateEntry returns the answer. Only an
error of the write itself rolls back.
A run that fails after cleanupChunks folded the request's chunks into
manifests is rolled back, so nothing refers to them: it now gives them up
the way a run with a refused commit does. The cleanup tolerates a run that
got no further than its lookup.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* filer: leave an expired S3 object to a lookup outside a transaction
FindEntry's removal of an expired S3 object deletes a remote copy and
publishes a delete event at once. Inside a store transaction a refused
commit restores the entry but not those, so subscribers could keep a
delete for a path that still holds an entry. A lookup in a transaction
now only answers NotFound and leaves the removal to one outside it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer: guard update retries and retain expired rename targets
Reject retries when the originally observed entry changes, so stale requests cannot restore chunks already deleted by a concurrent writer. Keep expired S3 overwrite targets visible to rename cleanup, and defer overwritten remote-object deletion until commit succeeds. Add regression coverage for concurrent updates and renames, both rename RPCs, remote data, and rollback.
* filer: extend conflict-checked entry updates to FoundationDB
Specify the optional capability in terms of entry/KV read-modify-write conflicts, without promising atomic bulk operations or blind-write conflicts. Opt FoundationDB into the update transaction path and normalize only known uncommitted conflicts. Add routing, error-classification, and live FoundationDB entry/KV conflict tests, and document its transaction boundaries.
* filer: prepare update manifests outside metadata transactions
* filer: keep update rereads from restoring renamed remote entries
---------
Co-authored-by: MapleWhiteZZZ <18653045+MapleWhiteZZZ@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Chris Lu <chris.lu@gmail.com>
111 lines
3.1 KiB
Go
111 lines
3.1 KiB
Go
//go:build foundationdb
|
|
|
|
package foundationdb
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/apple/foundationdb/bindings/go/src/fdb"
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
func TestCommitErrorOnlyMarksKnownUncommittedConflicts(t *testing.T) {
|
|
conflict := fdb.Error{Code: 1020}
|
|
for _, err := range []error{conflict, fmt.Errorf("commit: %w", conflict)} {
|
|
got := commitError(err)
|
|
if !errors.Is(got, filer.ErrTransactionConflict) {
|
|
t.Fatalf("commitError(%v) = %v, want transaction conflict", err, got)
|
|
}
|
|
var original fdb.Error
|
|
if !errors.As(got, &original) || original.Code != conflict.Code {
|
|
t.Fatalf("commitError lost FoundationDB's error: %v", got)
|
|
}
|
|
}
|
|
// An unknown result must not let the retry loop delete manifests that
|
|
// may have committed. Timeouts and other errors keep their own meaning.
|
|
for _, err := range []error{nil, fdb.Error{Code: 1021}, fmt.Errorf("commit: %w", fdb.Error{Code: 1021}), fdb.Error{Code: 1007}, errors.New("unavailable")} {
|
|
if got := commitError(err); got != err {
|
|
t.Fatalf("commitError(%v) = %v, want unchanged", err, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEntryAndKVTransactionsRefuseConcurrentDeletes(t *testing.T) {
|
|
if _, err := os.Stat(getTestClusterFile()); err != nil {
|
|
t.Skip("FoundationDB cluster file is not available")
|
|
}
|
|
store := &FoundationDBStore{directoryPrefix: fmt.Sprintf("seaweedfs-conflict-test-%d", time.Now().UnixNano())}
|
|
if err := store.initialize(getTestClusterFile(), 740); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(store.Shutdown)
|
|
ctx := context.Background()
|
|
path := util.FullPath("/conflict/file")
|
|
entry := &filer.Entry{FullPath: path, Attr: filer.Attr{Mode: 0644}}
|
|
key, value := []byte("hard-link"), []byte("shared metadata")
|
|
|
|
for _, kv := range []bool{false, true} {
|
|
t.Run(map[bool]string{false: "entry", true: "shared KV"}[kv], func(t *testing.T) {
|
|
var err error
|
|
if kv {
|
|
err = store.KvPut(ctx, key, value)
|
|
} else {
|
|
err = store.InsertEntry(ctx, entry)
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
txCtx, err := store.BeginTransaction(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer store.RollbackTransaction(txCtx)
|
|
if kv {
|
|
_, err = store.KvGet(txCtx, key)
|
|
} else {
|
|
_, err = store.FindEntry(txCtx, path)
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if kv {
|
|
err = store.KvDelete(ctx, key)
|
|
} else {
|
|
err = store.DeleteEntry(ctx, path)
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if kv {
|
|
err = store.KvPut(txCtx, key, value)
|
|
} else {
|
|
err = store.UpdateEntry(txCtx, entry)
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = store.CommitTransaction(txCtx); !errors.Is(err, filer.ErrTransactionConflict) {
|
|
t.Fatalf("commit = %v, want transaction conflict", err)
|
|
}
|
|
if kv {
|
|
_, err = store.KvGet(ctx, key)
|
|
if !errors.Is(err, filer.ErrKvNotFound) {
|
|
t.Fatalf("KV after refused commit = %v, want absent", err)
|
|
}
|
|
} else {
|
|
_, err = store.FindEntry(ctx, path)
|
|
if !errors.Is(err, filer_pb.ErrNotFound) {
|
|
t.Fatalf("entry after refused commit = %v, want absent", err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|