Sampling r1's epoch and then waiting for that exact epoch failed when a
further round moved it in between. waitRejoinConverged polls until r1 is a
healthy primary at some epoch e >= 2 and r2 and r3 are healthy peers at the
same e, read in one pass, and returns e.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- the scratch-cut exemption holds only while the chunk keeps the version
the scratch cut captured; a stale capture grants nothing
- TestMain has no switch that turns the strict findings off
- the raced-fill test bounds every wait and always releases and joins
its reader
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After its 6 s pause the resumed primary can answer the promotion gate's
probe not ready on a loaded host; the gate then runs one more fencing round
and continues r1 at the next epoch. The test waited for healthy peers at
epoch 2 only and failed (run 46515001535: r2 and r3 healthy at 3). It now
waits for both replicas healthy at r1's current epoch (at least 2), checks
that r1 is still the primary and that no replica was promoted, and reads
blocks A and B back; a further round is logged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check isClosed while holding the queue mutex so the check and insertion are atomic with respect to CloseInput. This prevents a producer from successfully enqueueing after a consumer has exited a closed, empty queue.
Add concurrent enqueue, close, and drain coverage with a bounded wait, plus checks for both sequential close orderings. The concurrent regression reproduces the original data race and stranded item under the race detector.
Co-authored-by: Master <Master@node0.8m510.lpad-pg0.utah.cloudlab.us>
The bitmap is pinned block by block (the file's local block, a single and a
batch log suffix, their non-local neighbours). The crash before the fence is
the injected one at the first slot write, with the pages complete, no
header and the presence file there at that point; a crash after the fence
and before the header completes on reopen; a retry over a complete record
writes no page, no header and no descriptor slot (file identity checked).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A store marked at this epoch is never seeded from the presence file: a
complete record only has the file removed, an incomplete one gets its pages
again from the store's bitmap through the boundary's same-epoch retry, with
a seed that refuses. A store marked at another epoch is refused, typed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two reds: a completed upgrade with a damaged header re-reads the presence
file; an upgrade at another epoch than the store's marker is taken.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After Recover, with extent draining held and before the chunk layer
attaches: seed the store's bitmap from the presence file (present chunks
whole; absent chunks with the file's local blocks and those of log entries
not yet applied), write the record's pages from the prepared coverage with
each chunk classified by the kernel's Rebuilt event, let the store publish
the bitmap and fence both slots, write the header, remove the presence file.
Each step repeats; a complete record only has the presence file removed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The flush wrote offset_min/offset_max only when minOffset > 0, using 0
as "no range given". A partition's first window starts at offset 0, so
its file never got a range. A restarted broker derives the high water
mark from those ranges, so a partition whose data was all in its first
file read as empty.
The renewal goroutine rewrites the owner on every attempt while other
goroutines read it through LockOwner. The MQ broker reads it on every
request it proxies to the balancer.
A download closed done and then moved its reservation to the budget's
idle list, so a reader woken by done could ask the budget for room
before the chunk it had just read was evictable.
TestReaderCacheBudgetLendsScratchToHedges failed this way about 1 in
1000 runs under -race ("hedge buffers did not evict the idle chunks").
The download now completes in the budget first.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The stub store kept the caller's entry, which the path translator changes
back after the insert, so TestNameInAPathSpecificStoreCreatedTwiceIsCountedOnce
raced with a lookup under -race.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* webdav: set mtime when a file is created
OpenFile created the entry with Mtime 0 and only Close after a Write set
the real time, so an empty PUT, or one truncating a file to empty, left
it at 1970. The "new entry" marker for a failed first upload is now a
field on the file.
* webdav: keep a failed upload from removing another writer's version
With every new entry carrying an mtime, a failed first upload removed
whatever the path held at the first Write, including a version another
writer stored after this open created it. The open now records the
commit stamp of the entry it created, and the first Write keeps the
removal only when the loaded entry still has that stamp.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* webdav: check the entry's commit stamp when the upload fails
The first Write's lookup left a gap: a version another writer stored
after it was still removed by a later failed flush. Flushes only append
chunks locally, so the stored entry keeps the create's stamp until
Close; the failed flush now reads it then and removes it only while it
still has that stamp.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* s3api: reset the circuit breaker when its config is deleted
The delete handler parsed an empty file, which always fails, so the old
limits stayed in place. It now loads an empty config.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* s3api: read and swap the circuit breaker limits under its lock
A config change or delete replaced Enabled and the limitations map while
requests read them without a lock. The swap now holds the breaker's
write lock, and requests read both under the read lock that
loadCounterAndCompare already took for the counters.
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>
The parent no longer claims, so its claim map stays empty and -count=2
passes; a hold helper keeps the claim until its stdin closes, a try helper
reports taken or refused, and both run under a local deadline and are
reaped. Held: refused to another process; after the holder exits: taken.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A lock file created by one runner user (0644 under umask 022, never removed)
was opened read-write by the next user and refused with EACCES, locking its
port out for good. flock needs no write access: open read-only, create
0444. Only EWOULDBLOCK means another process holds the port; any other
claim error is reported once, with its path, and the port is left to the
listen probe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer.sync: save the sync position on the source filer as a replay cursor
The position stays authoritative on the target. The source copy holds the
last position the target checkpoint stored (a fresh sync without one holds
just before the first event it received) and is rewritten hourly while the
sync runs, even when the position does not move.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer.sync: do not replicate the sync cursors of the source
A target never holds cursors that describe the source's log. A rename into
or out of the cursor directory replicates the ordinary side.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* metadata log purge: keep the logs a filer.sync still needs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer.sync: describe the sync in its source cursor
The source cursor is informational: besides the position it records the
source and target filers and paths, exclusions, host, version, when the
sync started, whether the position is a target checkpoint, and the
processed and failed event times, for display in admin tools. The
target checkpoint stays authoritative.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer.sync: save the first sync cursor when the first event arrives and retry failed saves
A fresh sync only saved its cursor on the next minute tick, and a failed
save still pushed the next attempt out by an hour, leaving the purge
without a cursor while the sync replayed old log days.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer.backup: do not seed the source's sync cursors in the initial snapshot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* metadata log purge: say that a position not saved for 7 days stops holding the log
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer.backup test: lock the recording sink for concurrent snapshot workers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer.sync: leave the sync cursors out of the metadata log gap check
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* security: filer token source read from a file
FilerTokenFile is the token source of a client that holds a pre-issued
filer token rather than a signing key. It reads the file on every call,
so an atomic replacement that keeps size and mtime takes effect on the
next attempt, and trims surrounding whitespace. A missing, unreadable,
empty or malformed file fails the call: there is no fallback to anonymous
or admin authority, and errors name the path but not the contents.
FilerTokenClaims decodes a token's claims without a key, and
FilerTokenGrantCovers compares two grants, so a client can plan
reconnects before expiry and know when a replacement narrows what it
may see.
* mount: -filer.tokenFile authorizes filer calls with a pre-issued token
A mount that should not hold a filer signing key can now present a
token issued for it. -filer.tokenFile (or -o filer.tokenFile=) names the
file; it is read for every filer gRPC attempt, so a replaced file takes
effect on the next call or retry without a restart, and a missing or
empty file fails the call locally.
The source reaches every filer client the mount builds: the startup
handshake, each attempt of WithFilerClient, the volume location client,
the SSE-S3 reader's configuration call, the peer registrar dial and the
lock client. It is attached per call, never to the cached channel, and
never to master, volume or peer mount RPCs.
The filer refuses MountRegister, MountList and distributed locks to
scoped tokens, so the mount refuses to start when -filer.tokenFile is
combined with -peer.enable or -dlm instead of failing at run time.
Server-side copy_file_range signs its filer HTTP request with the HTTP
key, not this token, and is unsupported with it.
Without the flag the mount behaves as before.
* mount: resubscribe metadata with a replaced filer token
A metadata subscription keeps the authority it opened with, so a mount
reading -filer.tokenFile would follow with the old token until the filer
ended the stream at expiry, and every such end took the gap path that
distrusts all cached listings.
SubscribeMetaEvents now takes the credentials of each attempt. The mount
opens each subscription with the token current at that moment and
watches the file; once it holds a different token the attempt ends and
the follow resubscribes at once from its checkpoint. This planned
resubscribe is not a gap: cached listings stay, unless the new grant may
show less than the old one or either token cannot be decoded, in which
case they are read again so nothing the old grant showed outlives it.
The filer walk treats a resubscribe like a stopped follow, so the same
attempt is not replayed on the next filer. Without a token file nothing
changes.
* mount: hand the mutation stream over to a replaced filer token
The mutation stream keeps the token it opened with, and a filer refuses
to send on a scoped stream once that token has expired. A mutation
applied at that moment loses its reply, the mount reads that as a
transport failure, and the unary fallback sends it again.
The stream now opens with a snapshot of the token source. Before
admitting a request it checks the source: when the file holds another
token, or the stream's token would expire before a reply could come
back, the stream is retired. New requests wait while the admitted ones
are answered, the stream is half-closed so the filer finishes it, and a
successor opens with the new token. The waits give up only after
filerRPCWait without a response, so a rename that keeps answering is not
cut short. A request is never resent by the handover: one still
unanswered when the wait gives up fails as on any lost stream, as
before.
A token too close to expiry to open a stream with is refused before
anything is sent, so the request goes out once as a unary call, which
the filer checks when it starts. Without a token file nothing changes.
* mount: review fixes for the filer token file
- A distrust of cached listings now also discards the directory builds in
flight, in the meta cache's apply loop: such a build publishes nothing,
its entries are wiped and the visit lists the directory again, so a
listing read under a grant that has since narrowed is never cached after
the distrust. The cached flags are reset again in the loop, after any
build that completed before it.
- Retiring the mutation stream runs in the background, and a request that
waits for the retirement gives up on its own context, unadmitted.
- With a token file and no filer signing key, server-side whole-file copy
is not tried: its filer HTTP request would go out unsigned and fail as
ambiguous. The copy streams through the chunk path instead.
- On Windows the token file is opened with delete sharing, so a renewer
can replace it by rename while a read holds it open; the missing-file
test checks os.ErrNotExist instead of Unix wording.
* mount: review fixes for the mutation stream handover
A request admitted to the mutation stream with just over one RPC wait
left on its token could wait behind a slow send until that margin was
gone; its reply could then be refused at expiry and the request was
resent over unary. The send loop now checks the margin again right
before sending and holds back a request that no longer has it, which is
safe to send over unary because the filer never saw it. A sent request
whose reply is lost while the token has one RPC wait or less left now
fails with EIO instead of a transport error: the filer may have applied
it, so it is not resent. Losses with the margin intact fall back to
unary as before.
A newly opened stream now admits its first request through the same
checks as an open one, so a token file replaced, or a token that neared
expiry, while the stream opened is caught before anything is sent.
A retirement keeps a cancel handle for its stream. Close uses it, so
unmount no longer waits for admitted requests to be answered, and a
waiter that gives up on a retiring stream stops it as it would stop an
open one, so a request still queued there is never sent after that
waiter fell back to unary. An ordinary rotation still drains admitted
requests.
* mount: drop kernel listings when the filer token's grant narrows
A replacement token whose grant may not cover the old one already
distrusts the mount's own cached listings. The kernel kept its own copy:
OpenDir sets FOPEN_CACHE_DIR | FOPEN_KEEP_CACHE, so a directory still
reachable under the new grant was listed again from the page cache with
names the new grant may hide, until something else invalidated it.
On a narrowed or undecodable grant the mount now also notifies the
kernel for every directory inode it holds, from the subscription
goroutine as the metadata apply path already does, so the next readdir
reaches the mount. A readdir already under way on an open handle still
finishes from what it read.
* mount: drop kernel listings after a subscription gap too
distrustCachedListings serves both the narrowed-grant path and the gap
path. A gap can lose the very events that would have dropped the kernel's
cached listings one directory at a time, and with FOPEN_KEEP_CACHE on
OpenDir the kernel then serves those listings on every reopen. Move the
kernel drop into distrustCachedListings so both paths get it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* s3api: optionally answer NoSuchBucket to a denied signed request on a missing bucket
## Problem
AWS S3 answers 404 NoSuchBucket to an authenticated caller that is denied on a bucket that does not exist. SeaweedFS answers 403 AccessDenied. S3-compatibility test suites run by data platforms (which create, probe and clean up buckets with a scoped key) flag the difference, and a client that maps 404 to "create it" or "skip it" takes the 403 for a permissions problem instead.
Answering 404 tells every authenticated identity whether a bucket name exists, which a multi-tenant deployment may not want, so the default stays 403.
## Fix
A new option, off by default: `-s3.noSuchBucketWhenDenied` on `weed server`, `weed filer` and `weed mini`, `-noSuchBucketWhenDenied` on `weed s3` (`S3ApiServerOption.NoSuchBucketWhenDenied`).
With it set, `refineDenial` extends `refineDenialForBucketName` (400 InvalidBucketName) with the NoSuchBucket answer, in `Auth`, `AuthPostPolicy` and the POST policy handler:
- only after authentication succeeded with a signature or a token (signed, presigned, V2, streaming signed, streaming-unsigned with a signed header, JWT). The anonymous identity keeps 403 under any auth type, so an anonymous caller still learns nothing about which buckets exist;
- a bucket-level PUT (CreateBucket, configuring a bucket) keeps 403, as AWS answers a refused create;
- the lookup goes through the bucket config cache, which the authorization path has usually just filled, so a denied request rarely costs a filer lookup; a failed lookup is "unknown" and keeps 403;
- an allowed request never looks a bucket up.
`Auth` now keeps the auth type it used to discard; the POST policy handler, which verifies the form signature itself, passes `authTypeSigned`.
With the option off nothing changes.
## Tests
`weed/s3api/auth_no_such_bucket_test.go`:
- `TestRefineDenialThroughAuth`: through `iam.Auth`, a signed caller denied on another identity's existing bucket gets 403 and on a missing bucket 404 (GET, PUT, a signed streaming-unsigned PUT); a bucket-level PUT stays 403; the caller's own bucket is allowed with no lookup.
- `TestRefineDenialAnonymousLearnsNothing`: anonymous requests answer 403 for a missing and an existing bucket alike and never drive a lookup.
- `TestRefineDenialRules`: presigned and JWT callers, failed authentication, allowed requests, a missing bucket name, a failed lookup, and the option off (no lookup wired) all keep their answer.
- `TestPostPolicyDeniedNoSuchBucket`: a verified browser POST form denied on a missing bucket answers NoSuchBucket; a bad signature stays SignatureDoesNotMatch; an existing bucket stays AccessDenied.
`TestRefineDenialThroughAuth`, `TestRefineDenialRules` and `TestPostPolicyDeniedNoSuchBucket` fail without the NoSuchBucket answer. `go vet` reports nothing in the touched files; `go test ./weed/s3api/ ./weed/command/`: ok. `go build ./weed`: ok.
* s3api: count streaming-unsigned as signed only with a SigV4 or JWT credential
A client-certificate identity that streamed its body unsigned answered
NoSuchBucket on a denied missing bucket, while the same request without
the body-encoding header answered 403.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* s3api: tell the anonymous identity by name, without the unlocked pointer read
isAnonymousIdentity compared against iam.identityAnonymous without iam.m,
racing a configuration reload. The configured anonymous identity always
has the anonymous name and account, which the check already covers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* command: keep allowBackslashInKeyUsage's doc comment on its const
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* s3api: answer NoSuchBucket to a denied request on a missing bucket by default
AWS S3 answers it this way, so drop the -s3.noSuchBucketWhenDenied flag
and always wire the bucket lookup.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* s3api: answer NoSuchBucket to a client-certificate identity too
The AWS answer now goes to every authenticated identity, so it no
longer depends on how the caller authenticated. The anonymous identity
keeps 403, as anonymous object reads mask a missing bucket.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* s3api: fold the NoSuchBucket answer into refineDenialForBucketName
One refinement for the bucket a denied request names: 400 for a
malformed name, 404 for a missing one. The anonymous read paths keep
their answer, since the anonymous identity never gets the 404.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* filer.sync: warn when the source metadata log no longer covers the sync
A sync replays the source's metadata log from its saved position, or from
the oldest log file when it has none. Once older log days are purged, a
position older than the log silently skips the purged changes, and a fresh
sync never copies entries whose last change was purged, so the target ends
up incomplete without any sign of it.
At start, compare the position with the oldest log file the source keeps;
for a fresh sync, look for a child of the source path whose last change
(commit time, or mtime for entries without one) predates the log, and log
a warning naming it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer.sync: skip excluded and multipart upload entries in the log gap check
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer.sync: run the log gap check without delaying the subscription
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* s3 backend: HTTP/1.1 client defaults for disable_http2
## Problem
`disable_http2` (#11897) keeps the cloud tier's S3 client on HTTP/1.1, so every tier upload and range read gets a connection of its own. The rest of the client still has the defaults sized for one multiplexed HTTP/2 connection:
- Go's idle pool keeps only 2 connections per host, so a burst of concurrent range reads redials TLS for almost every request once the burst is over and the next one starts;
- the wait for response headers is the 60 s bound every tier client has;
- the SDK retries 3 times.
On a Ceph RGW-based S3 service, HTTP/2's small flow-control window held tier uploads at 18 MB/s and made 24 concurrent cold scans take 52 s each; on HTTP/1.1 they took 3.7 s each, but only with a larger idle pool, a shorter header bound and more retries for the 503 SlowDown answers that the extra parallelism draws.
## Fix
With `disable_http2 = true` the tier client also gets:
- an idle pool of 100 (`MaxIdleConns` and `MaxIdleConnsPerHost`);
- `ResponseHeaderTimeout` of 30 s;
- `MaxRetries` 5, so the SDK's retryer backs off on 5xx, SlowDown and throttling.
`max_connections` and `idle_connection_timeout_seconds` apply as before. Without `disable_http2` the client is unchanged. The scaffold `master.toml` mentions the defaults.
## Tests
`TestS3BackendHTTP1ClientDefaults` in `weed/storage/backend/s3_backend/s3_sessions_test.go`: with `disable_http2` the transport has the idle pool and the 30 s header bound, and the client 5 retries; without it (and with `max_connections` set) the client keeps the SDK's retries, the default idle pool and `s3ReadTimeout`. It fails without the change.
`go vet ./weed/storage/backend/s3_backend/` and `go test ./weed/storage/backend/s3_backend/`: ok. `go build ./weed`: ok.
* s3 backend: keep the larger idle pool for every tier client
A tier client on a plain http:// endpoint, or on a TLS service that offers
no HTTP/2, speaks HTTP/1.1 without disable_http2 and had the same 2 idle
connections per host, so each burst of concurrent reads redialed. HTTP/2
keeps one connection, so the pool size does not change it. The header
bound and retries stay with disable_http2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Two defects that #833 introduced, each shown by a test that fails at
f5926348:
- a format-2 bitmap baseline outlives a discarded WAL suffix
(Recover returns nil with bitmap position 1 while the retained
position is 0);
- the legacy FenceChunkStateUpgrade relabels an initialized format-2
bitmap epoch (7 -> 8).
The fixes exist but are not yet qualified on Linux. Main goes back to
its state before #833; the feature returns as one PR with the fixes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Heap per chunk after a cut, 262,144 chunks: stated 520 B in total and 56 B
for the shadow's share (measured 481 and 48).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>