Commit Graph
5 Commits
Author SHA1 Message Date
Chris LuandClaude Opus 5.5 2b157f2ef1 test: clear the codespell hits left after #13290 (#13264)
* test: use a codespell-clean non-ASCII key in TestEncodeKey

Codespell reads caf%C3%A9 as the misspelling caf.

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

* topictable: reword want's in the CheckSchema comment

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 03:28:00 -08:00
Chris Lu 081218bf8a test: reword misspelled fixtures that trip codespell (#13290) 2026-12-02 03:21:01 -08:00
Chris LuandClaude Opus 5.5 284d491587 s3: forward notification topics to webhook targets (#13245)
* util: move the guarded dialer out of the volume server

The deny list and the dialer that re-checks every resolved address at
connect time move into weed/util/netguard, with the allow-private knob as a
policy, so other outbound clients can dial through the same guard.

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

* mq: fence consumer group position saves by generation

A position saved with a generation is written only while the stored one
carries no newer generation, or the same generation from another writer:
the save reads the stored position and writes on the condition that it is
unchanged, routed to the entry's owner filer, and re-reads when another
writer got there first. A single consumer that elects itself can then store
its offsets without a deposed predecessor overwriting them. Saves without a
generation keep overwriting as before.

Loading a missing position now reports ErrNotFound instead of trying every
filer and marking each one failed.

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

* s3: post bucket event batches to a webhook target

A webhook destination renders a batch of records as one
{"Records":[...]} body, posts it with the target's bearer token, and takes
any 2xx as delivered. The renderer is a function the destination holds, a
stand-in that refuses until the record renderer lands. It dials through the
guarded dialer under a new Local policy, which refuses metadata-service,
link-local and unspecified addresses at connect time but lets an operator
point a target at a private host or a sidecar on loopback. Redirects are
followed only to the endpoint's own host and never down from https.

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

* s3: forward each target's topic to its destination

A Forwarder runs beside the Publisher on every gateway. Each enabled target
with a destination gets a lock, s3.notify.<target>, held through
LockClient.StartLongLivedLock, so one gateway forwards a target and targets
spread across gateways; a topic target has none.

The holder runs one loop per partition of the target's topic: fetch from the
stored offset at the partition's leader, decode the records, deliver them as
one batch, store the next offset. A fetch that stops short at a segment
boundary just continues from its next offset. A failed send, a rejected one
included, blocks the partition and is retried with capped backoff, and the
offset is stored only after the destination took the batch. An offset that
retention removed skips to the earliest one and counts the gap.

Offsets go to the consumer group offset storage under group forwarder,
fenced by the lock generation. On taking the lock a forwarder stores each
partition's offset back under its generation, so an older holder's saves are
refused and it stops. A stored generation at or above its own means the
lock was lost, unless the forwarder has since held the lock through a full
renewal, which happens only when the lock server's counter restarted; it
then fences above the stored generation.

Metrics per target: records delivered, send retries, retention gaps, and
lag from the forwarding gateway.

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

* s3api: run notification forwarders beside the publisher

Every gateway with filers starts a Forwarder with the publisher. It elects
itself per target through the gateway's object-write lock client, stores
offsets in the filer, reads through the same brokers the publisher uses,
follows the target registry as the publisher does, and releases its locks
on shutdown.

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

* s3: post a test event to a webhook on its own

The renderer refuses an s3:TestEvent that shares a body with other records,
so a webhook splits a batch around each one and posts them in order, the
test event as its own body. The test is a stand-in until the renderer's
lands.

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

* s3: skip a bucket event record that can never be delivered

A record that does not decode, or that the renderer refuses, used to be
retried like a failed send and would block its partition for good. The
webhook now renders a whole batch before posting any of it and names the
records that cannot render; the forwarder drops those, counts them per
target and reason in notification_skipped_records_total, logs each offset
once, and sends the rest. Only transport and HTTP failures are retried.

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

* mq: read a fenced position save at the filer that applies it

The fenced save read the stored position from whichever filer answered and
then sent its conditional write to the key's owner, so with filers that keep
their own stores the condition could be checked against an entry other than
the one read, failing until replication caught up or judging a stale copy.
The storage now takes the ring's owner lookup, the one route-by-key writes
already use, and sends both the read and the write to that filer. The
gateway hands its object-write lock client's PrimaryForKey to the forwarder
offsets.

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

* s3: follow a repartitioned notification topic

A forwarder listed its topic's partitions once, when it took the lock, so a
repartition left the new partitions unforwarded until the lock moved. It now
lists them again every 30 seconds, starts a loop for each new partition, and
marks the loops of partitions no longer listed as replaced; such a loop keeps
delivering what its partition holds and ends once it has caught up. A
failed fetch now looks up the leader of that exact partition, not of any
partition with the same range.

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

* s3: let the first forwarder take the lock before the second asks

The election test synced both gateways at once, and each forwarder asks for
its lock from its own goroutine, so the second could ask first and store the
offsets the test expected from the first.

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

* s3: warn when a partition returns nothing below its high-water mark

A fetch that returned no records and kept its next offset below the
high-water mark looked like an idle partition, so the forwarder waited
without a word while its lag stayed up. It still waits, since skipping would
lose the records, but now warns at most once a minute with the topic,
partition, offset and high-water mark, so the lag has an explanation.

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

* s3: render webhook bodies with the bucket event renderer

The webhook now renders through Render and posts each s3:TestEvent alone by
IsTestEvent, replacing the stand-ins it held until the renderer landed.
The tests send real records and read the object keys and test request ids
back out of the bodies.

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

* netguard: refuse the IPv6 and Alibaba metadata service addresses

AWS's IPv6 metadata address fd00:ec2::254 is unique-local and Alibaba's
100.100.100.200 sits in the CGNAT range, so the Private and Local
policies let a webhook or remote endpoint reach them. Refuse both under
every policy, like 169.254.169.254.

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

* grafana: chart the notification forwarder metrics

Add an S3 Notifications row with delivered records, lag, send retries,
and records skipped or lost to retention per target.

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

* s3: follow only webhook redirects that keep the POST

On a 301, 302 or 303 Go resends the request as a GET without a body, so an
endpoint that redirected and then answered 2xx counted as delivered while
it received no records. Only 307 and 308, which keep the method and resend
the body, are followed now; any other redirect fails the send and is
retried.

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

* s3: keep webhook endpoint secrets out of errors and logs

The guarded dialer names its endpoint in every refusal, and the forwarder
logs that error, so a webhook endpoint carrying credentials in its userinfo
or a token in its query had them written to the log. The dialer now gets
the endpoint as scheme, host and path only, and the parse and request
errors no longer echo the URL.

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

* mq: load a consumer group position from its owner filer

A forwarder taking over read its start offset from whichever filer answered,
while its fenced saves read and write at the key's owner. With filers that
keep their own stores, a replica still holding an older offset handed the
new holder that offset, which it then stored under its higher generation at
the owner, replaying everything delivered since. Loads now go to the owner
too when the storage knows it.

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

* mq: bound consumer group position loads and saves by the caller

LoadConsumerGroupPosition and SaveConsumerGroupPosition ran their filer
calls under context.Background(), so a filer whose store stalled held a
forwarder's save forever: ending the lead waited on it, the lock was never
released, and Close hung while the lock kept renewing. Both now take the
caller's context; the forwarder gives each call its RPC deadline under the
lead's context, so stopping returns and the lock is released. The offset
wrappers the broker uses keep their signatures.

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

* mq: list a consumer group's positions across partition generations

ListConsumerGroupPositions walks every generation and range directory of a
topic and returns the group's stored position in each, keyed by partition
directory, so a consumer can tell which ranges it holds offsets for that
the topic no longer lists.

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

* s3: stop forwarding ranges a repartition removed

A repartition drops the old assignments, and the broker serves only
assigned ranges, so the loop draining a removed range retried a refused
fetch forever, and after a restart nothing looked at it at all. Reading a
removed range's flushed data would need a read-only path in the broker.
Until then a removed range's loop delivers the batch it holds and ends,
and the forwarder logs an error naming each range it stops and, when it
takes the lock, each partition directory holding a stored offset the topic
no longer lists. The fake broker now refuses unassigned ranges as the real
one does.

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

* s3: deliver what a repartition left in the retired ranges

The lookup now offers the sealed ranges a repartition retired, and any
broker serves them from their files, so the forwarder no longer drops
them. On taking the lock and on each re-list it asks for the retired
ranges too and runs a loop for each, from its stored offset up to its
high-water mark, after which the loop ends; a range it was forwarding as
current and that is now retired gets the same end. A read below a retired
range's log start counts as a retention gap, as for a live one.

A key's records in a retired range precede its records in the ranges that
replaced it, and loops running side by side would not keep that order. So
the retired ranges go first, one generation at a time, oldest first, and
the current ranges start only once none is left. A range listed neither as
assigned nor as retired, as while a drained range is not sealed yet, pauses
until it is offered again.

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

* s3: match a retired range to its forwarding loop by directory

The broker lists a retired range at the second its generation directory
is named for, while the assignment the forwarder started its loop from
carried nanoseconds. After a repartition the retired entry missed the
running loop, so a second loop started on the same stored offset and
delivered the batch the first was still retrying. Key the loops by
partition directory; the fake broker now lists retired ranges and the
fake positions store offsets at that resolution, like the real ones.

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

* s3: replace a paused forwarding loop only once it ended

A range drained but not sealed yet is listed neither as assigned nor as
retired, so its loop is paused and dropped from the lead's loops while
it may still be retrying a batch. Once the range was offered as retired
a new loop started at the stored offset and sent that batch again. Keep
a paused loop until it ends, and start the range again only then.

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

* s3: hold the new ranges while a drained one is not sealed yet

A repartition saves the new ranges before it drains and seals the old ones,
so for a while an old range is offered neither as assigned nor as retired,
and the forwarder started the new ranges at once: a key's new records could
go out before its records still waiting in the old range. On each look at
the topic the forwarder now lists the directories holding a stored offset
that the topic does not offer, and probes each at its offset; one that may
still hold records past it, refused because it is not sealed, holds the new
ranges until it is offered as retired and drained. One that answers with
nothing past the stored offset is settled, sealed and empty or already
delivered, and stays so for the lead. While holding, the forwarder logs at
most once a minute and keeps looking even with no loop running.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: have the fake broker serve only the generation a fetch names

The broker now refuses a fetch naming a generation other than the one it
assigns for the range, unless that generation is sealed and read as
retired. The forwarder tests' fake broker matched an assigned range by its
range alone, so it served the live generation to a fetch for an older,
unsealed one; it now matches the generation too, as the broker does.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: hold the current ranges until the stored offsets can be listed

A lead whose first look at the stored offsets failed took that as no old
range left unsettled and started the current ranges, delivering a key's
newer records ahead of the ones still in a drained range that is not sealed
yet. A failed look now holds the current ranges as an unsettled range does,
and is retried with backoff and on each partition refresh; the current
ranges start only after a look succeeds. Retired ranges and loops already
running carry on meanwhile.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3api: leave forwarding off on an unusable broker TLS config

The forwarder loaded the grpc.msg_broker client TLS config with
LoadClientTLS, which exits the process on a bad one, and every gateway with
filers builds a forwarder whether or not it has webhook targets. It now
loads it as the publisher does: an unusable config is logged and leaves
forwarding off while the gateway keeps serving.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: hold the new ranges for an unsealed old range with no stored offset

The check for old ranges still unsealed looked only at ranges holding a
forwarder offset. A forwarder starting for the first time while a drained
range was not sealed yet had stored none in it, so it started the new
ranges and delivered a key's newer records ahead of its older ones. The
consumer group listing now names every partition directory of the topic,
with no position where the group stored none, and such a range is probed
from offset 0. A range with nothing left past that offset, including one
whose records retention already removed, is settled.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: check the load in the fenced save race test

The test read the stored position back ignoring the load's error, so a
failed load panicked on a nil position instead of reporting the error.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: take a partition over at the offset its last holder committed

A new forwarder generation claimed a partition by writing the offset it
had loaded. When the old generation committed again in between, the claim
rewound the stored offset and the new lead replayed what had been
delivered since. A fenced save that takes over from an older generation
now keeps the offset that generation committed last, rereading it on a
conditional write miss, and hands it back in the position, and the
forwarder starts from it.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: wait for a position's owner filer instead of asking another

A position store routed by owner fell back to any filer while the owner
of a key was not known yet, as before the lock ring is learned. That
filer's not-found ended the load there, though it may only not have
caught up, and a claim on it would start the partition over. Loads and
fenced saves now fail until the owner is known, and the forwarder
retries them; a store without an owner routing still uses any filer.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: wait for the last checkpoint before a forwarder handoff in tests

The resume, repartition and election tests stopped the first forwarder
once its records were delivered but possibly before their offsets were
stored, so they could pass on a replay rather than on a committed
handoff. They now wait for the final offsets first.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: have Close wait for removed targets to release their locks

A target removed from the registry had its forwarder cancelled and
dropped from the targets, so a Close soon after did not wait for it and
returned with that target's lock possibly still held. Removed forwarders
are now kept until they are done, and Close waits for them as well.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: hold newer retired generations behind an unsealed older one

A range of an old generation still unsealed held back only the current
ranges. A generation retired after it was offered and delivered right
away, ahead of the older generation's records of the same keys. The
unsealed range's generation now counts as the oldest one left, so only
that generation's own sealed ranges are forwarded until it is sealed.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: check the forwarder lock right before each send

A lead checked its lock at the top of each fetch and after a failed send's
backoff, so a lead that lost the lock while it fetched a batch still sent
it, and the next holder sent it again. The lock is now checked right
before each send. Delivery stays at-least-once: a lock lost during a send
cancels that send once the lead notices, which may be after the endpoint
took the batch.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: read a retired range past a broker that answers with an error

Any broker serves a retired range from its files, but a fetch took the
first broker's answer even when it was a storage error, and each retry
asked that broker first again, so one broker that could not read the
files held the range up for good. A retired fetch answered with an error
other than an offset out of range now goes on to the next broker, and
returns the error only when none could read it.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: count ranges held back behind an older generation in the lag

The lag gauge summed what each running loop reported, so the current
ranges held back while an older generation was still unsealed, and the
retired generations waiting their turn, showed no lag however much piled
up in them. On each partition refresh the lead now reports their lag
from the stored offset to the high-water mark, read from the range's
leader or the retired listing, and drops the lag of ranges it no longer
has.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: hold retired generations too while stored offsets cannot be listed

A lead whose look at the stored offsets failed held only the current
ranges and went on forwarding retired generations, though an older
generation it could not see might still be unsealed and hold earlier
records of the same keys. A failed look now holds every range not yet
running until a look succeeds; loops already running carry on.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: read stored offsets only of the ranges a lead does not know yet

The check for unsettled ranges listed every partition directory and read
every stored offset in it one by one under one deadline, before dropping
the ranges the topic offers and those already found settled. A topic
with many past generations could take longer than the deadline on every
refresh and hold a new lead for good. The listing now takes the
directories to skip and reads only the remaining offsets, a few at a
time, and the lead skips the offered ranges and those it found settled.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: test the failed-listing hold with no unsealed range

The failed-listing test also had an older generation unsealed, which
holds the newer ranges on its own once a listing succeeds, so it did not
show the listing guard by itself. A second case has no unsealed range:
nothing goes out while the listing fails, and both the retired and the
current range do once it succeeds.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: stop the lead before marking a failed loop ended

A forwarding loop that failed, as on being deposed, was marked ended
before it cancelled its lead. A partition refresh in between saw a
retired range's loop ended, took the range as delivered, and started the
next generation's ranges on the lead that was about to stop. The lead is
now cancelled first, so no refresh acts on the failed loop.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: count no retention gap below an offset only claimed

A lead claiming a partition with no stored offset wrote offset 0 to fence
it before reading anything. A lead that stopped there left 0 behind, and
the next one, finding the log start past it, counted those offsets as
lost though no forwarder had ever been at them. A claim made before any
read is now marked as such, a takeover keeps the marker of the entry it
replaces, and only an offset a lead read from counts a gap.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: retry a takeover save at the offset it kept

A claim's save that took a partition over from an older generation kept
that generation's last offset, but when its reply was lost the retry
went out with the offset the claim had loaded. The stored entry was by
then the claim's own, so the retry kept nothing and rewound the
partition, replaying what had been delivered since. A failed save now
retries with the offset and marker the attempt settled on.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: store an offset as read from once the first fetch succeeds

A claimed offset lost its claimed marker only when a later save moved it,
so a lead that read an empty partition and stopped left it marked as
never read. Records published and then removed by retention while no
gateway forwarded the target were skipped without a gap counted or
logged. The first successful fetch now stores the offset as read from,
once per claim, even when it has not moved.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: wait for the stalled topic's publisher before reading it in a test

The worker sets the topic publisher up on its own goroutine, which on a
loaded host can start after Publish has stopped waiting.

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

* s3: keep what a timed-out offset check settled for the next one

A check for unsettled ranges that could not read every stored offset
within its deadline returned nothing, so each retry read the same ranges
again and a long enough history kept the new ranges held for good. The
listing now returns the positions it read along with the error and goes
on past one that fails, and the check probes those and keeps the ranges
it finds settled before reporting the failure, so the next check reads
only the rest. The ranges stay held until a check covers them all.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: say which records the notification lag counts

The lag gauge's help, and the dashboard panel with none, read as every
undelivered record, but the records of an old range still being sealed
after a repartition cannot be read and are not counted. Both now say the
gauge covers the current ranges, the ranges held back behind an older
generation, and the sealed retired ranges.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 21:45:41 -08:00
Chris LuandClaude Opus 5.5 3f2f625822 s3: publish bucket events to each notification target's MQ topic (#13244)
* mq: report when a published message is acknowledged

Publish now returns a channel the publisher closes once the broker acks
that message, including an ack that arrives on a later stream after a
resend. A caller that has to know its message is stored, such as the S3
gateway answering a request only after its event is durable, can wait on
it with its own bound; callers that do not care ignore it.

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

* s3: build bucket event records in the AWS shape

An Event is what one operation did to one object; Record turns it into
an eventVersion 2.7 record for one rule, and Message wraps that record
in the Records envelope a consumer receives. The key is form-encoded per
path segment as AWS does it, size and eTag are left off removals, and
the sequencer is the filer's commit stamp as 16 hex digits, so one key's
sequencers compare as strings in commit order. The s3:TestEvent message
is built here too.

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

* s3: publish bucket event records to each target's MQ topic

The Publisher runs one worker per enabled target. The worker creates the
target's topic, s3.notify-<target> with 4 partitions and 7 days of
retention, then hands records to the MQ publisher keyed by bucket/key so
one object's events stay in one partition in order. Setup retries with
backoff, so a broker that is down or still taking the balancer lock after
a cold start delays records instead of losing them. A removed or
disabled target's worker stops; its topic is left for retention to age
out, since a forwarder may still be draining it.

Publish queues every record and waits up to 2 seconds, or until the
request ends, for all of them to be acked, and reports whether they
were. A record not acked by then stays queued and is still sent; the MQ
publisher resends it across leader changes. Each target's queue holds
10000 records; past that, and for records whose target has no worker, a
record is dropped. Acked, late and dropped records, the queue depth and
the wait are exported as metrics.

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

* s3api: start a bucket event publisher with the gateway

The gateway creates one event publisher and syncs it with the target
registry whenever the registry loads or changes, so each enabled target
gets its topic and worker. The publisher bootstraps from the broker the
command started beside the gateway, passed in as MqBroker once it bound,
and from every broker the masters list, so a gateway running without its
own broker still finds the cluster's. Broker connections use the
grpc.msg_broker TLS section. Shutdown stops the workers.

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

* s3api: send the test event before storing a notification configuration

Unless x-amz-skip-destination-validation is true, PUT notification
publishes an s3:TestEvent to the topic of every target the configuration
names, in parallel, and fails with InvalidArgument listing the
destinations whose topic did not ack it within the publisher's 2 second
wait. Nothing is stored in that case. The registry checks still run
with the header, and an empty configuration sends nothing.

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

* s3api: publish ObjectCreated events for PUT and POST

A PUT, including a "dir/" marker, publishes ObjectCreated:Put and a POST
upload ObjectCreated:Post, after the filer commit and before the
response, once per matching rule of the bucket's configuration, waiting
for the acks within the publisher's bound. A failed write publishes
nothing and a slow or absent broker never fails the request.

The sequencer is the filer's stamp of the commit. putToFiler records it,
from the routed ObjectTransaction or the lock path's CreateEntry, with
the committed size, into the request so the handler finds it; the marker
write and a create recovered after an ambiguous route return none, and
take the gateway's clock instead.

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

* s3api: publish ObjectCreated events for copy and multipart completion

CopyObject, including a metadata-only copy onto itself, publishes
ObjectCreated:Copy, and CompleteMultipartUpload publishes
ObjectCreated:CompleteMultipartUpload, both after the commit and before
the response; a copy that keeps the connection alive publishes before
its final answer.

The write wrappers these use dropped the transaction response, so they
now return the filer's commit stamp: routedMkFile, writeMultipartObject,
routedVersionedFinalize, routedMultipartFinalize, routedSelfCopy and
finalizeCopyDestination. Writes that go off the owner, through mkFile,
still return none and the event takes the gateway's clock.

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

* s3api: publish ObjectRemoved events for deletes

DeleteObject and DeleteObjects publish ObjectRemoved:DeleteMarkerCreated
when a delete without a version id leaves a marker in place of the key,
in a versioning-enabled or suspended bucket, and ObjectRemoved:Delete
for any other delete, including the delete of a marker by its version
id. The record carries the marker's or the deleted version's id.
DeleteObjects publishes one event per key it deleted and waits for all
of them at once.

The routed delete wrappers now return the filer's commit stamp:
routedDeleteSpecificVersion, routedDeleteNullVersion,
routedDemoteNullVersion and createDeleteMarker; deleteMutationResult
carries it to the handler. A suspended delete uses the stamp of the null
version's delete, since the marker write after it returns none. Deletes
on the lock path go through DeleteEntry, which has no stamp, and take
the gateway's clock.

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

* mq: report the ack of a published record too

PublishRecord now returns the same ack channel as Publish, so a caller
publishing to a topic with a record type can wait for its record to be
stored. Both go through doPublish, which registers the waiter for every
message.

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

* s3: carry bucket events as schematized records

A notification topic now has a record type, EventRecordType, the single
source for its flat snake_case columns: the event, requester, bucket and
object fields, the commit stamp as sequencer, and multipart columns for
later. event_time, event_name and bucket_name are required, the rest
optional, and changes to it are additive only. The topic is configured
with it, with bucket_name and object_key as key columns and the schema
format left empty as for the other schematized topics, and records go
out through PublishRecord.

The record holds raw values: the object key unencoded, the sequencer as
an int64, and nulls where a value is absent, such as size and eTag on
removals. Render turns records into the AWS JSON a destination receives,
the Records envelope with eventVersion 2.7, a form-encoded key and a hex
sequencer, or the test event message for an s3:TestEvent, so forwarders
produce exactly the body the gateway used to publish.

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

* s3: shut a stopped target's publisher down even while it is blocked

With the broker away long enough to fill a partition's unacked buffer,
the worker blocks inside PublishRecord. Removing, disabling or closing
the target only cancelled the worker's context, which the blocked worker
never looked at, so the publisher and its queued records lived on and
resumed sending once the broker came back. Stopping a target now shuts
its MQ publisher down directly, which releases the blocked publish, and
does it in the background so Sync and Close do not wait for the flush. A
publisher that finishes setting up after the stop is shut down at once,
and a worker that dequeues a record after the stop drops it.

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

* s3api: publish nothing for a retried multipart completion

A CompleteMultipartUpload retried after the object committed is answered
from that commit and writes nothing, yet the handler still published an
ObjectCreated:CompleteMultipartUpload, with size 0 since no commit was
noted. AWS sends the event once, for the completion that created the
object, so the handler now publishes only when the request itself
committed.

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

* s3api: take an event's principal from the authenticated identity only

With auth off, the gateway keeps the s3-account-id header the client
sent, and an event's principal_id fell back to it, so any client could
name itself as the requester in the record a destination trusts. The
principal is now the identity name authentication put in the request
context, or anonymous.

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

* s3api: turn notifications off instead of exiting on a bad broker TLS config

The event publisher loaded the grpc.msg_broker client TLS with
LoadClientTLS, which exits the process on a config it cannot use, such
as a cert without its key, so a broker-only TLS mistake took the S3
gateway down even with no notification targets. It now loads it with
TryLoadClientTLS and, on an error, logs it and runs without a
publisher: object writes publish nothing and a notification
configuration's test event fails. It never falls back to an insecure
connection.

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

* s3: count a record dropped while its request waits only as dropped

A record dropped while a request waited for it, by a PublishRecord error
or its target being stopped, was counted dropped where it was dropped,
and then late when the request's wait ran out, which it also sat
through in full. Each queued record now carries a done signal that both
its ack and its drop close, so the wait ends as soon as the record's
fate is known and the drop is not counted again as late. Late still
counts a record that was neither acked nor dropped when the request
answered.

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

* mq: let a caller cancel starting a topic publisher

NewTopicPublisher returned only once a partition lookup succeeded, and
retried the lookup for as long as the broker refused it, with nothing a
caller could stop it with. It now takes a context that bounds the start:
the topic configuration runs under it, and cancelling it stops the
lookup loop and returns an error. A publisher already returned is not
affected. Existing callers pass context.Background().

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

* s3: stop a removed target's publisher that is still starting

A target's MQ publisher was started without the worker's context, so a
target removed while its partitions had no leader kept its publisher
looking them up, and its worker waiting, until a lookup succeeded. The
worker's context now bounds the start, so removing or disabling the
target ends both.

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

* s3: bound each broker's ConfigureTopic during a target's setup

Setup asked each broker in turn to configure the target's topic with
the worker's context alone, so a broker that accepted the call and never
answered held the worker there for good. Each broker now gets 10
seconds before setup moves on to the next, and a stopped worker does not
ask the rest.

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

* s3api: stamp a suspended delete's event with its marker write

A suspended-bucket delete removes the null version, then writes the null
delete marker and points latest at it. Its DeleteMarkerCreated event
took the stamp of the first step, so a write landing between the steps
got a later sequencer although the marker it lost to is what remained.
The event now takes the stamp of the pointer write, the delete's last
commit.

To get it, MkFile, the gateway's mkFile and
updateLatestVersionInDirectory return the CreateEntry stamp, and
createNullDeleteMarker returns it. createDeleteMarker's unrouted path
and writeMultipartObject off the owner now return their write's stamp
too instead of none.

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

* mq: bound each broker's ConfigureTopic when a publisher starts

NewTopicPublisher configures the topic again before its lookups, with
no deadline per broker, so a broker that accepted the call and hung
held the start until the caller gave up, even with a healthy broker
next in the list. Each broker now gets 10s before the next is tried.

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

* s3api: sequence a key's events only with stamps from its owner filer

The previous change stamped a suspended delete's DeleteMarkerCreated
with the null marker's pointer write, but that write goes to the
gateway's default filer, not the key's owner. Filer clocks differ, so a
delete could get a smaller sequencer than the PUT before it, and a
consumer deduplicating on the sequencer would drop it as stale.

Routing the marker write to the owner would move the suspended delete
onto the transaction path, a change to the write itself. Until then the
event goes back to the stamp of the null version's routed delete on the
owner, and gateway clock when the delete is not routed. The same
reasoning applies to the other stamps that change began returning from
off-owner writes, a delete marker or a multipart object written through
mkFile, so those return none again, and MkFile, mkFile and
updateLatestVersionInDirectory go back to returning only an error.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3: count each queued record once as acked or dropped, and late apart

A drop counted the record as dropped and then closed its done channel,
so a request whose wait ran out between the two still saw it pending and
counted it late in the same counter. Each queued record now has a
terminal outcome, acked or dropped, set once by compare-and-swap, and
notification_records_total counts that outcome alone, so every lost
record shows as dropped exactly once.

Late moves to its own counter, notification_records_late_total, counted
once per record when its request stops waiting on it before it is acked
or dropped; that record is still counted acked or dropped when it
settles.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* s3api: publish the event of a completion recovered after its commit

When a finalize committed but returned an error, completeMultipartUpload
answered from committedCompletion without noting the commit, so the handler
published no ObjectCreated:CompleteMultipartUpload. A retry is answered as
a replay and publishes nothing either, so the event was lost although the
object exists. The recovery now notes the commit when the stored object
holds this attempt's parts, stamped by the gateway clock as the filer's
stamp is not known. One answered from another attempt's commit stays
silent.

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

* s3api: sequence a recovered completion's event with its entry's commit stamp

A completion whose finalize committed but returned an error is answered
from the stored object, and its event took the gateway clock. The stored
entry carries CommitTsNs, the meta log stamp the committing filer gave
the write, from the same sequence as the stamps the routed write paths
return, and peers that replicate the entry keep it. The event now takes
that stamp, and falls back to the gateway clock only for an entry
written by a filer that predates it.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 19:53:18 -08:00
Chris LuandClaude Opus 5.5 6b2e22950a s3: bucket notification configuration API and target registry (#13236)
* s3: add the bucket notification target registry

Notification destinations are defined by the operator in
/etc/s3/notification/targets.json and referred to by name from bucket
configurations, so a bucket owner cannot make the server connect anywhere
new. The registry parses and validates that file: unique names that fit in
an ARN segment and an MQ topic name, known types (topic and webhook now,
kafka, aws_sqs, google_pub_sub and pubsub accepted for later), the fields
each type needs, and no unknown keys. A target serves only the buckets its
allowed_buckets globs match, and none when the list is empty. Parse errors
never carry credential values.

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

* s3api: hot-reload the notification target registry

Every gateway reads /etc/s3/notification/targets.json at startup and
reloads it from the /etc metadata subscription it already runs for the IAM
and circuit breaker files. A write reloads it, a delete or rename away
empties it, and a file that does not parse leaves the previous registry in
place so a bad edit does not cut every bucket off its destinations.

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

* s3: parse and validate bucket notification configurations

The full PutBucketNotificationConfiguration document is parsed: topic,
queue and cloud function configurations with their Id, destination ARN,
events and key filter. Event names are checked against the AWS list,
wildcards and names for things that never happen here included, plus the
multipart and retention events this server emits. A filter takes at most
one prefix and one suffix rule, a document at most 100 configurations, and
overlapping rules are allowed. EventBridge stays NotImplemented.

A destination resolves by the last segment of its ARN to a target, which
must exist, be enabled and allow the bucket; the error does not say which
of those failed. A rule without an Id gets one derived from its content, so
every gateway reports the same configurationId for it.

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

* s3: match an event against a bucket's notification rules

Configuration.Match takes an event name such as s3:ObjectCreated:Put and
an object key and returns each rule that covers them, with its
configurationId and target, in configuration order. Category wildcards
cover every event in the category, prefix and suffix are case-sensitive and
checked independently, and an event that several rules cover matches each
of them, as AWS delivers one record per rule. Publishing calls this; it is
a pure function of the stored configuration.

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

* s3api: store bucket notification configurations

PutBucketNotificationConfiguration used to accept only an empty document
and answer NotImplemented for any destination. It now parses the full
document, checks every destination against the target registry for this
bucket, and stores the XML exactly as sent in one Extended key on the
bucket entry through updateBucketConfig, which patches that key alone on
the bucket's owner filer. An empty document removes the key. GET returns
the stored bytes unchanged, so tools comparing ARNs see no diff, and the
bucket config cache carries the parsed rules for publishing to match.

x-amz-skip-destination-validation is parsed and must be true or false. It
only skips the test event, which publishing will send; the registry check
always runs.

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

* s3notification: reject content after the configuration's root element

The stored document is served back unchanged by GET, so anything after the
root other than whitespace, comments or processing instructions is refused.

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

* s3notification: reject unknown elements inside rules and filters

A misspelled Filter, S3Key, FilterRule or Value was dropped by decoding and
left an unfiltered rule; it is now MalformedXML like an unknown root child.

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

* s3notification: URL-decode prefix and suffix filter values

AWS has special characters in filter values percent-encoded and a space
written as +, so reports+2026/ selects reports 2026/a. A value that is not
valid encoding is still matched as written.

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

* s3api: refuse a notification targets file stored in chunks

Only inline content is read, so a targets.json kept in chunks (written by a
mount, for one) read as an empty registry and dropped every target. It is
now refused with a warning and the loaded registry stays.

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

* s3notification: refuse overlapping rules as AWS does

AWS answers InvalidArgument ("Configuration is ambiguously defined") when two
rules share an event type and both their prefixes and suffixes overlap, so an
event for a key matches at most one rule. Such configurations were accepted
and matched every rule.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 14:45:21 -08:00