Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ When configuring S3 clients, ensure path-style addressing is enabled. See [docs/
- Set `block_caching_enabled: false` to cache whole objects instead — a range request then triggers a background fetch of the full object (if within threshold)
- A dropped whole-object cache listener or upstream body-read error does not publish the partial body as a new cache entry
- In tiered mode, a PUT routed to the local tier checks a concrete SigV4 `X-Amz-Content-Sha256` digest after admission and any local precondition pass and the full body passes its declared-length and any Content-MD5 checks; conditional writes against upstream-tier markers, `UNSIGNED-PAYLOAD`, and aws-chunked uploads keep their existing paths
- PUT/DELETE operations invalidate affected cache entries. For cache-enabled bulk DeleteObjects requests with a nonempty parsed key list, TAG completes an upstream 2xx response only after the post-success invalidation attempts return, bounded by a 10-second fence timeout; a fence that does not converge in time is logged as a warning and the 2xx is still returned.
- PUT/DELETE operations invalidate affected cache entries. For proxy-mode bulk DeleteObjects with a nonempty parsed key list, TAG waits for post-success invalidation attempts, bounded by a 10-second fence timeout; an unparseable result keeps the conservative all-key invalidation. In tiered mode, a local metadata entry is removed only when a complete, parseable 2xx DeleteResult establishes that at least one requested delete for the key succeeded; incomplete or unparseable results do not authorize removal. A fence that does not converge in time is logged as a warning and the 2xx is still returned.
- Fully captured successful multipart completions are cached for five seconds when TAG can identify the caller; replay requires local validation for the same access key and exact bucket, object key, and upload ID
- Legacy ordered metadata populates are refused when the tombstone cannot be read or is malformed, rather than assuming no invalidation. The detached metadata warm remains best-effort, so a successful S3 write response is unchanged.
- If a whole-object cache write returns an error during a successful GET, the upstream response is unchanged and the cache-populate slot becomes available after relay cleanup, so a later eligible GET can retry. A store call that never returns has no completion guarantee.
Expand Down
5 changes: 5 additions & 0 deletions docs/tiered-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ existing handling. `If-Match`/`If-None-Match` are honored; GET, HEAD, and
DELETE are served entirely locally. Reads and writes of small objects
generate zero upstream traffic.

A forwarded `DeleteObjects` request removes local metadata only when a complete,
parseable 2xx result establishes that at least one requested delete for the key
succeeded; an incomplete or unparseable result does not authorize metadata
removal.

**Large objects are the upstream tier.** The PUT passes through to upstream and
TAG stores a metadata marker locally. HEAD answers from the marker; GET
forwards for the body — the mode's only body traffic. DELETE forwards and
Expand Down
75 changes: 41 additions & 34 deletions proxy/delete_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type deleteObjectsResult struct {
// whether the response parsed. Counting by key (not by version) is deliberate: it
// is robust to VersionId representation differences between request and response
// (omitted "" vs "null" vs a concrete id), which exact-tuple matching gets wrong.
// On a parse failure the caller re-invalidates all requested keys (safe
// over-invalidation).
// On a parse failure proxy-mode callers keep their conservative all-key
// invalidation fallback.
func erroredDeleteKeyCounts(body []byte) (map[string]int, bool) {
var result deleteObjectsResult
if err := xml.Unmarshal(body, &result); err != nil {
Expand Down Expand Up @@ -141,7 +141,8 @@ func (w *deleteObjectsResponseStager) commit(dst http.ResponseWriter, capture *R
}

// HandleDeleteObjects handles POST /{bucket}?delete for bulk object deletion.
// Invalidates cache for requested objects BEFORE forwarding to ensure consistency.
// Proxy modes invalidate requested cache keys before forwarding; tiered mode
// converges authoritative metadata only after a complete, parsed result.
func (s *Service) HandleDeleteObjects(w http.ResponseWriter, r *http.Request) error {
start := time.Now()
bucket, _ := ParseBucketKey(r)
Expand All @@ -155,8 +156,9 @@ func (s *Service) HandleDeleteObjects(w http.ResponseWriter, r *http.Request) er
}
r.Body = io.NopCloser(bytes.NewReader(bodyBytes))

// Parse request to get keys being deleted and invalidate cache BEFORE forwarding
// This ensures cache consistency even if forwarding fails after cache invalidation.
// Parse the request to identify keys and capture tiered versions before forwarding.
// Proxy modes invalidate cache entries before forwarding for consistency; tiered
// mode keeps authoritative metadata until an upstream result authorizes convergence.
// requestedCounts tracks how many entries each key was requested under (the same
// key may appear multiple times with different version IDs).
var requestedCounts map[string]int
Expand Down Expand Up @@ -216,16 +218,15 @@ func (s *Service) HandleDeleteObjects(w http.ResponseWriter, r *http.Request) er
// <Error> elements for partial failures.
capture, err := s.forwarder.ForwardWithCapture(r.Context(), forwardWriter, r)

// Re-invalidate AFTER upstream confirms the deletes, for the same
// read-after-write reason as HandleDeleteObject: a GET racing the in-flight
// bulk delete may have re-cached a not-yet-deleted object; this second fence bump
// blocks that stale repopulation. A key is re-invalidated when at least one of
// its requested entries was deleted — i.e. more entries were requested for the
// key than upstream reported as errored. Counting by key (never matching version
// IDs) is robust to VersionId representation differences and to Quiet mode, and
// can never leave a truly-deleted object cached (a success is never an <Error>).
// A key whose entries ALL errored keeps its refill (it's still upstream).
// Routed through invalidateObject so a failed re-invalidation is recorded/logged.
// Reconcile cache state after a successful upstream status. For a parsed
// result, a key is re-invalidated when at least one requested entry was
// deleted — more entries were requested for the key than upstream reported as
// errored. Counting by key (not VersionId) handles representation differences
// and Quiet mode; keys whose entries all errored keep their metadata. Proxy modes
// retain conservative all-key invalidation for an unparseable result. Tiered mode
// processes results only when capture is complete and parsed, so an incomplete or
// unparseable result cannot remove authoritative metadata.
// Routed through invalidateObject so proxy-mode fence failures are recorded.
if err == nil && capture != nil && capture.StatusCode >= 200 && capture.StatusCode < 300 && s.cache.IsEnabled() {
// Upstream has committed the deletes, so a client disconnect must not
// abandon the fence (WithoutCancel); the timeout keeps a stalled cache
Expand All @@ -235,26 +236,32 @@ func (s *Service) HandleDeleteObjects(w http.ResponseWriter, r *http.Request) er
fenceCtx, cancelFence := context.WithTimeout(context.WithoutCancel(r.Context()), bulkDeleteFenceTimeout)
fencedKeys, skippedKeys := 0, 0
erroredCounts, parsed := erroredDeleteKeyCounts(capture.Body)
for key, reqN := range requestedCounts {
// On a parse failure, over-invalidate every requested key (safe).
if parsed && reqN <= erroredCounts[key] {
continue // every requested entry for this key errored — object still present
}
// Once the shared deadline has passed, stop starting per-key fences in
// either mode: the tiered helper runs under its own per-key timeout, so
// without this check a large tiered batch could hold the 2xx for N times
// that timeout. Skipped keys age out via TTL and are counted below.
if fenceCtx.Err() != nil {
skippedKeys++
continue
}
fencedKeys++
if tieredPriors != nil {
p := tieredPriors[key]
s.convergeTieredDelete(bucket, key, p.version, p.known)
continue
// Proxy-mode caches can conservatively discard every requested key when
// the result cannot be parsed. Tiered metadata is authoritative, so only
// a complete, parsed result can authorize a versioned local converge.
if tieredPriors == nil || (capture.Complete && parsed) {
for key, reqN := range requestedCounts {
// Parse failures reach this loop only in proxy mode, which keeps its
// conservative all-key invalidation fallback.
if parsed && reqN <= erroredCounts[key] {
continue // every requested entry for this key errored — object still present
}
// Once the shared deadline has passed, stop starting per-key fences in
// either mode: the tiered helper runs under its own per-key timeout, so
// without this check a large tiered batch could hold the 2xx for N times
// that timeout. Skipped keys age out via TTL and are counted below.
if fenceCtx.Err() != nil {
skippedKeys++
continue
}
fencedKeys++
if tieredPriors != nil {
p := tieredPriors[key]
s.convergeTieredDelete(bucket, key, p.version, p.known)
continue
}
s.convergeInvalidation(fenceCtx, bucket, key)
}
s.convergeInvalidation(fenceCtx, bucket, key)
}
if fenceCtx.Err() != nil {
log.Warn().
Expand Down
Loading
Loading