Files
seaweedfs/weed/filer/redis2
a2df801e6d filer: rename a file over a file in place on a store without transactions (#12894)
* 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: rename a file over a file in place on a store without transactions

A rename over an existing file deleted the target, then created the renamed
entry. On a store without transactions (the Redis stores, Cassandra,
MongoDB, etcd and the like) the delete shows at once, and the rename's path
locks fence only the filer running the rename, so a lookup or listing
through another filer could find neither name and return ENOENT; POSIX
rename keeps the new path resolvable throughout. A target deleted through
another filer between the rename's lookup and its delete failed the rename
outright ("no entry is found in filer store").

On such a store, a plain file renamed over a plain file is now written over
the target in one store write (Filer.ReplaceFileForRename, an InsertEntry,
which also lists the entry on Redis and drops the target's hard link after
the write). The target's chunks are still deleted after the rename, unless
the target's other hard links still use them, and subscribers get the same
delete-then-rename events. Stores with transactions keep delete-then-create:
no other reader sees the gap, and a target that went meanwhile fails the
transaction cleanly. So do setups with path-specific stores, whose stores
may take an insert over an existing entry differently (a SQL store inside a
transaction aborts it), and directories and entries with a remote object.
filer.WithoutTransactions tells the case apart; BeginTransaction marks it
next to IsolatingTransaction.

Tests: filer_grpc_server_rename_inplace_test.go. On master the target goes
missing after the delete, and a target deleted meanwhile fails the rename;
the transaction, path-specific store, directory and hard link tests guard
what stays as it was.

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: read the target again and keep its parents when a rename writes in place

The in-place write skipped what delete-then-create did on its way:

- Another filer can turn the target into a directory after the rename
  looked it up, by storing a child under it. The delete refused a non-empty
  directory, while the in-place write stored the file over it and stranded
  the child. The target is now read again right before the write, and a
  directory is refused. A store without transactions has no conditional
  write, so this leaves the window the delete-first path has between its own
  read of the target and its delete.
- Another filer can delete the target's directory after the lookup.
  CreateEntry creates missing parents after its insert, and the rename
  announces them before the move; the in-place write now does the same.
- The in-place write also applies CreateEntry's checks of the name (length,
  dot segments).

Tests: a target that became a directory, and a target whose directory went,
both right after the rename's lookup.

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>

* filer: write a rename in place only on a store that says its insert replaces an entry

The in-place write took "the store keeps no transaction" to mean that an
insert over an existing entry replaces it. That does not follow: the
Tarantool store's insert is an upsert that assigns only the entry's data,
so the row keeps the replaced entry's expire_at, and a file renamed over an
expiring one would expire with it.

A store now says so itself, through OverwritingStore: it keeps no
transaction, and its InsertEntry replaces the stored entry at once and
whole, with its expiry and its listing. The three Redis stores declare it:
their SET replaces value and expiry, and the insert lists the name whether
or not it was listed. Every other store keeps delete-then-create, as before
this PR. That includes the embedded default store, where each filer has a
store of its own and the rename's path locks already hide the gap.

This replaces the comparison of the context BeginTransaction returns;
BeginTransaction is back to what it was.

Tests: for each Redis store, an InsertEntry over an expiring entry leaves
the second entry, no expiry and one listing (RUN_REDIS_TESTS=1). A store
that does not declare it keeps delete-then-create, with and without
transactions. The in-place write over one of two hard links, and over the
last one.

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:35:57 -08:00
..