Files
seaweedfs/weed/filer/abstract_sql
7cc8a8a445 filer: run a file rename again when the store refuses its commit (#12892)
* filer: run a file rename again when the store refuses its commit

TiKV refuses an optimistic transaction's commit when another writer
committed one of its keys after it began. A rename's transaction moves the
source key, so a concurrent write of the file, through another filer for
instance, failed the rename with "move commit error: write conflict".
Standalone writes run again after such a conflict since #12798, but a
rename's transaction belongs to the rename, and it gave up.
StreamRenameEntry also sent the rename's responses before the commit, so
the client had already moved the file locally when the store refused it.

- The TiKV store reports such a refusal as filer.ErrTransactionConflict.
- A file rename runs its transaction again after it, up to five times; the
  new run reads what the other writer stored and moves that. A rename that
  copied or deleted a remote object on the way is not run again.
- On a store whose transactions keep their writes to themselves
  (filer.IsolatingTransaction: SQL, TiKV), a file rename holds its stream
  responses until the commit: a refused rename sends none, and one that
  runs again sends them once. A directory rename still streams its
  children's responses as it moves them, which keeps the client of a long
  rename from timing out, and is not run again.
- Every failed run releases its commit stamps and rolls back, the "is not
  empty" refusal included.

Tests: filer_grpc_server_rename_conflict_test.go, with a store that keeps a
transaction's writes until its commit and can refuse it, and
tikv_store_commit_test.go (-tags tikv). On master the retry, refused-commit
and remote-file tests fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer: run a rename again only when its transaction covers every write

With path-specific stores configured, the writes under their prefixes do
not go through the default store's transaction: a parent directory a rename
creates at its destination there stays when the commit is refused, and a
rename run again finds it and announces only the file's move, so peers
replaying the events never learn of the parent.

IsolatingTransaction now holds only when no path-specific store is
configured, and AtomicRenameEntry checks it too before running a rename
again, as StreamRenameEntry does through its held responses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer: finish a committed rename before its held responses go out

StreamRenameEntry sent its held responses before the work the commit leaves
(metadata events, chunk deletions, remote copies). A client that stops
reading without closing the stream blocks Send on flow control, and that
work then never ran. It now runs first; the responses still follow the
commit.

A file with a remote object no longer holds its responses: its remote copy
after the commit is part of that work, and the client should not wait for
it. It streams as it moves, as before, and is not run again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer: let the store say that its transactions isolate a rename

Whether a rename's responses wait for the commit, and whether it may run
again, was inferred from the context BeginTransaction returned and from
whether any path-specific store was configured. Neither holds up:

- A store may hand back a transaction context that its writes do not use:
  YDB begins a table-service transaction, and its statements run through
  the query service outside it. A store now says so itself, through
  IsolatingTransactionStore, which the TiKV store implements. Any other
  store keeps sending a rename's responses as the entries move and does not
  run it again, as before this PR.
- A path-specific store only matters for the paths it holds.
  Filer.TransactionCovers asks whether the rename's source and destination
  live in the default store: a rename that stays there holds its responses
  and may run again, and one that writes into a path-specific store does
  neither.

A rename that may not run again still must not announce changes before its
commit, so a file with a remote object holds its responses too. So that its
remote copy after the commit does not delay them, the held responses go out
while the rename finishes, and the call returns once both are done.

A held response checks the stream's context, so a rename whose client went
away before its first response is rolled back, as when the responses go
out at once, instead of committed unseen.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* filer: the SQL stores isolate their transactions too

AbstractSqlStore takes the sql.Tx its context carries for every entry call
(getTxOrDB) and every KV call (kvDB, also when KV has a pool of its own),
so the SQL stores built on it meet what IsolatingTransactionStore asks. A
file rename on them holds its responses until the commit again, as it did
before the declaration became explicit; it is never run again, since no
SQL store reports ErrTransactionConflict.

Bucket tables are created and dropped outside the transaction, which a
file rename does not do.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* abstract_sql: check that a transaction's writes take its own handle

sqlmock serves a pool and its transactions from one mock, so the write
expectations also pass for entry writes made through store.DB. Assert that
getTxOrDB and kvDB return the *sql.Tx the context carries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
2026-11-22 10:25:17 -08:00
..