mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +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>
120 lines
5.4 KiB
Go
120 lines
5.4 KiB
Go
package filer
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
const CountEntryChunksForGzip = 50
|
|
|
|
var (
|
|
ErrUnsupportedListDirectoryPrefixed = errors.New("unsupported directory prefix listing")
|
|
ErrUnsupportedSuperLargeDirectoryListing = errors.New("unsupported super large directory listing")
|
|
ErrKvNotImplemented = errors.New("kv not implemented yet")
|
|
ErrKvNotFound = errors.New("kv: not found")
|
|
// ErrTransactionConflict marks a commit the store refused because another
|
|
// writer changed a key the transaction read or wrote. No writes from the
|
|
// refused transaction were committed; an unknown commit result must not
|
|
// carry this sentinel. Running the transaction again reads the other write.
|
|
ErrTransactionConflict = errors.New("transaction conflict")
|
|
)
|
|
|
|
type ListEachEntryFunc func(entry *Entry) (bool, error)
|
|
|
|
type FilerStore interface {
|
|
// GetName gets the name to locate the configuration in filer.toml file
|
|
GetName() string
|
|
// Initialize initializes the file store
|
|
Initialize(configuration util.Configuration, prefix string) error
|
|
InsertEntry(context.Context, *Entry) error
|
|
UpdateEntry(context.Context, *Entry) (err error)
|
|
// err == filer_pb.ErrNotFound if not found
|
|
FindEntry(context.Context, util.FullPath) (entry *Entry, err error)
|
|
DeleteEntry(context.Context, util.FullPath) (err error)
|
|
DeleteFolderChildren(context.Context, util.FullPath) (err error)
|
|
ListDirectoryEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int64, eachEntryFunc ListEachEntryFunc) (lastFileName string, err error)
|
|
ListDirectoryPrefixedEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int64, prefix string, eachEntryFunc ListEachEntryFunc) (lastFileName string, err error)
|
|
|
|
BeginTransaction(ctx context.Context) (context.Context, error)
|
|
CommitTransaction(ctx context.Context) error
|
|
RollbackTransaction(ctx context.Context) error
|
|
|
|
KvPut(ctx context.Context, key []byte, value []byte) (err error)
|
|
KvGet(ctx context.Context, key []byte) (value []byte, err error)
|
|
KvDelete(ctx context.Context, key []byte) (err error)
|
|
|
|
Shutdown()
|
|
}
|
|
|
|
// ErrUnsupportedEntryScan is returned by EntryScanner.ScanEntries, before
|
|
// any entry is visited, when the store cannot serve the scan.
|
|
var ErrUnsupportedEntryScan = errors.New("entry scan not supported by this filer store")
|
|
|
|
// UnorderedListingStore is implemented by a store whose directory listings do
|
|
// not come in file name order (Elasticsearch pages by a hash of the entry
|
|
// path), so a listing there cannot start at a name the store did not return.
|
|
type UnorderedListingStore interface {
|
|
ListsUnordered() bool
|
|
}
|
|
|
|
// EntryScanner is an optional FilerStore capability: visit every entry at and
|
|
// below dirPath, in any order, from one consistent snapshot of the store.
|
|
//
|
|
// A directory walk sees each directory at a different time, so an entry
|
|
// renamed from a directory not yet listed into one already listed is never
|
|
// seen; volume.fsck then purges its chunks as orphans. A snapshot sees it
|
|
// exactly once. The context handed to fn carries the snapshot, so store reads
|
|
// made with it (hard-link records) see the same instant.
|
|
type EntryScanner interface {
|
|
ScanEntries(ctx context.Context, dirPath util.FullPath, fn func(ctx context.Context, entry *Entry) error) error
|
|
}
|
|
|
|
type BucketAware interface {
|
|
OnBucketCreation(bucket string)
|
|
OnBucketDeletion(bucket string)
|
|
CanDropWholeBucket() bool
|
|
}
|
|
|
|
type Debuggable interface {
|
|
Debug(writer io.Writer)
|
|
}
|
|
|
|
// IsolatingTransactionStore is implemented by a store whose transactions are
|
|
// real: the entry and KV writes made under the context BeginTransaction
|
|
// returns go through that transaction, stay invisible to other readers until
|
|
// CommitTransaction, and are undone by RollbackTransaction. A store says so
|
|
// itself, once that has been checked for it: the SQL stores and TiKV do. It
|
|
// cannot be told from the context a store hands back, which may carry a
|
|
// transaction that its writes do not use.
|
|
type IsolatingTransactionStore interface {
|
|
IsolatesTransactions() bool
|
|
}
|
|
|
|
// ConflictRefusingStore protects a read-modify-write of one entry and its
|
|
// shared KV records. Entry and KV operations must use the context's transaction,
|
|
// keep its writes invisible until commit, and leave none behind on rollback.
|
|
// If another writer changes a key this transaction both reads and writes after
|
|
// its read version, CommitTransaction must refuse with ErrTransactionConflict.
|
|
// Read/write conflicts suffice; blind writes need not conflict with each other.
|
|
//
|
|
// TiKV and FoundationDB implement this capability. It does not promise that
|
|
// bulk operations such as DeleteFolderChildren stay inside the transaction.
|
|
// Other stores must opt in only after their entry and KV paths, isolation and
|
|
// conflict errors have been checked; having BeginTransaction alone is not enough.
|
|
type ConflictRefusingStore interface {
|
|
RefusesConflictingCommits() bool
|
|
}
|
|
|
|
// OverwritingStore is implemented by a store without transactions whose
|
|
// InsertEntry over an existing entry replaces it at once and whole: the stored
|
|
// entry, its expiry, and its listing in the directory. A rename can then write
|
|
// a file over its target instead of deleting the target first. A store says so
|
|
// itself, once its insert has been checked: an upsert may leave part of the
|
|
// old row in place. The Redis stores do.
|
|
type OverwritingStore interface {
|
|
OverwritesAtOnce() bool
|
|
}
|