Skip to content

feat: [stable-8.0][OCISDEV-855] receivedsharecache: retry on transient storage errors in CAS loop - #709

Merged
mklos-kw merged 3 commits into
stable-8.0from
backport/8.0/feat-ocisdev-855-receivedsharecache-retry-transient
Aug 13, 2026
Merged

mklos-kw merged 3 commits into
stable-8.0from
backport/8.0/feat-ocisdev-855-receivedsharecache-retry-transient

Conversation

@mklos-kw

Copy link
Copy Markdown
Member

backports: #657

…rors in CAS loop (#657)

* fix: ocisdev-855, cs3/decomposefs transactional concurent upload

* fix: ocisdev-855, cs3/decomposefs optimistic-abort concurent upload

* fix: ocisdev-855, cs3/decomposefs optimistic-abort concurent upload

* feat: logs and cleanup

* feat: cleanup

* feat: review fixes

* feat: cleanup in tracing
@kw-security

kw-security commented Aug 12, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

…e Download in concurrent test

status.NewTooEarly was added after stable-8.0 branched; map IsTooEarly to
NewAborted instead (same retry semantics for the client).

DiskStorage.Upload on stable-8.0 uses os.WriteFile (not renameio), so
concurrent Download calls can read a partial file. Add a mutex to
barrierStorage that serializes Upload/Download pairs in the test.
@mzner
mzner self-requested a review August 13, 2026 07:48
@mklos-kw
mklos-kw merged commit 3dbd3c2 into stable-8.0 Aug 13, 2026
16 checks passed
@mklos-kw
mklos-kw deleted the backport/8.0/feat-ocisdev-855-receivedsharecache-retry-transient branch August 13, 2026 08:13
@2403905

2403905 commented Sep 25, 2026 •

Copy link
Copy Markdown

The Claud's post-merged review: @mklos-kw Could you have a look?

/code-review 3dbd3c2#diff-d1b078acb1599e399ab6e7cc97627d35747ba4faebd4e4f66ad4922bc9da1922

⏺ Code review(review · 10 findings)
pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go
● 246 [correctness] retryPersist's switch has no case for errtypes.InternalError (falls to default and aborts immediately), while isSyncTransient a few lines below treats the same error type as transient and retries it during sync.
● 309 [correctness] syncIfStale's NotFound branch now eagerly calls c.persist to bootstrap an empty cache file and swallows any error from it (Warn-only, still returns nil), turning a previously side-effect-free read path into a write attempt whose failure is silently ignored.
● 239 [regression-risk] Retry budget was cut from 100 attempts (no backoff) to 20 attempts (with backoff); equivalence under high fan-in beyond the 15-replica case covered by the new test is unverified.
● 277 [correctness] When the post-failure re-sync inside retryPersist itself fails with a transient error, the code only logs a warning and proceeds to retry persistFunc() with the same stale in-memory rss/etag instead of ensuring fresh state before the next attempt.
● 252 [observability] The retry log message for the TooEarly-manifesting-as-Aborted path (from storageprovider.go's IsTooEarly->NewAborted mapping) is logged as "CAS failed: Aborted (etag changed), retrying" even when the real cause is an in-progress upload, not an etag mismatch.
● 392 [duplication] expBackoff hand-rolls full-jitter exponential backoff even though github.com/cenkalti/backoff/v5 is already a direct dependency and already used for the same purpose in pkg/utils/ldap/reconnect.go and pkg/utils/ldap/pool.go.
● 311 [efficiency] syncIfStale's NotFound branch performs an extra Upload round-trip to bootstrap an empty file even when called from retryPersist's post-failure resync, where persistFunc() is about to issue its own real-data Upload on the very next loop iteration.
pkg/storage/utils/metadata/disk.go
● 120 [correctness] Disk.Upload still writes via non-atomic os.WriteFile - the exact race the PR's own commit message identifies - but the fix was applied only to the test (a mutex in barrierStorage), not to the production storage driver.
pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache_test.go
● 281 [test-coverage] barrierStorage (unit test) and barrierStorageCS3 (tests/integration/grpc/receivedsharecache_concurrent_test.go) are ~90% identical boilerplate (same fields, same constructor pattern, same barrier-release logic in Upload) that could be a single shared helper.
pkg/storage/utils/metadata/cs3.go
● 68 [style] An extra blank line was introduced between the CS3 struct closing brace and the NewCS3 doc comment, producing a double blank line that gofmt/golangci-lint conventions elsewhere in the file do not use.

Background review of 3dbd3c2 (receivedsharecache: retry on transient storage errors in CAS loop) finished — 10 findings, most-severe first, reported above.

Worth acting on:

  • receivedsharecache.go:246 — InternalError aborts retryPersist immediately but isSyncTransient treats the same error type as retryable a few lines below. Same error class, opposite handling depending on which call hits it — a real chance of a lost share write on a blip that would've been tolerated one line over.
  • pkg/storage/utils/metadata/disk.go:120 — the non-atomic-write race the commit message names as the motivation was fixed only in the test harness (a mutex in barrierStorage), not in the actual Disk.Upload driver. If anyone runs the Disk metadata backend in production, the bug this PR set out to fix is still there.
  • receivedsharecache.go:309 — the NotFound branch now writes (bootstraps an empty file) as a side effect of what used to be a pure read, and swallows the write's error. On read-only/quota-exhausted storage, every read for that user repeats a doomed write forever, silently.
  • receivedsharecache.go:239 — retry budget cut 100→20 attempts; the new test only covers 15 replicas, so headroom at higher real-world fan-in is unverified.

The rest (stale state reused after a failed resync, a misleading "etag changed" log for what's actually upload contention, a hand-rolled backoff sitting next to an already-vendored cenkalti/backoff, a redundant bootstrap write, duplicated test helper, and a stray blank line) are lower-severity but listed above with file/line.

@mklos-kw

Copy link
Copy Markdown
Member Author

The Claud's post-merged review: @mklos-kw Could you have a look?

/code-review 3dbd3c2#diff-d1b078acb1599e399ab6e7cc97627d35747ba4faebd4e4f66ad4922bc9da1922

⏺ Code review(review · 10 findings) pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go ● 246 [correctness] retryPersist's switch has no case for errtypes.InternalError (falls to default and aborts immediately), while isSyncTransient a few lines below treats the same error type as transient and retries it during sync. ● 309 [correctness] syncIfStale's NotFound branch now eagerly calls c.persist to bootstrap an empty cache file and swallows any error from it (Warn-only, still returns nil), turning a previously side-effect-free read path into a write attempt whose failure is silently ignored. ● 239 [regression-risk] Retry budget was cut from 100 attempts (no backoff) to 20 attempts (with backoff); equivalence under high fan-in beyond the 15-replica case covered by the new test is unverified. ● 277 [correctness] When the post-failure re-sync inside retryPersist itself fails with a transient error, the code only logs a warning and proceeds to retry persistFunc() with the same stale in-memory rss/etag instead of ensuring fresh state before the next attempt. ● 252 [observability] The retry log message for the TooEarly-manifesting-as-Aborted path (from storageprovider.go's IsTooEarly->NewAborted mapping) is logged as "CAS failed: Aborted (etag changed), retrying" even when the real cause is an in-progress upload, not an etag mismatch. ● 392 [duplication] expBackoff hand-rolls full-jitter exponential backoff even though github.com/cenkalti/backoff/v5 is already a direct dependency and already used for the same purpose in pkg/utils/ldap/reconnect.go and pkg/utils/ldap/pool.go. ● 311 [efficiency] syncIfStale's NotFound branch performs an extra Upload round-trip to bootstrap an empty file even when called from retryPersist's post-failure resync, where persistFunc() is about to issue its own real-data Upload on the very next loop iteration. pkg/storage/utils/metadata/disk.go ● 120 [correctness] Disk.Upload still writes via non-atomic os.WriteFile - the exact race the PR's own commit message identifies - but the fix was applied only to the test (a mutex in barrierStorage), not to the production storage driver. pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache_test.go ● 281 [test-coverage] barrierStorage (unit test) and barrierStorageCS3 (tests/integration/grpc/receivedsharecache_concurrent_test.go) are ~90% identical boilerplate (same fields, same constructor pattern, same barrier-release logic in Upload) that could be a single shared helper. pkg/storage/utils/metadata/cs3.go ● 68 [style] An extra blank line was introduced between the CS3 struct closing brace and the NewCS3 doc comment, producing a double blank line that gofmt/golangci-lint conventions elsewhere in the file do not use.

Background review of 3dbd3c2 (receivedsharecache: retry on transient storage errors in CAS loop) finished — 10 findings, most-severe first, reported above.

Worth acting on:

  • receivedsharecache.go:246 — InternalError aborts retryPersist immediately but isSyncTransient treats the same error type as retryable a few lines below. Same error class, opposite handling depending on which call hits it — a real chance of a lost share write on a blip that would've been tolerated one line over.
  • pkg/storage/utils/metadata/disk.go:120 — the non-atomic-write race the commit message names as the motivation was fixed only in the test harness (a mutex in barrierStorage), not in the actual Disk.Upload driver. If anyone runs the Disk metadata backend in production, the bug this PR set out to fix is still there.
  • receivedsharecache.go:309 — the NotFound branch now writes (bootstraps an empty file) as a side effect of what used to be a pure read, and swallows the write's error. On read-only/quota-exhausted storage, every read for that user repeats a doomed write forever, silently.
  • receivedsharecache.go:239 — retry budget cut 100→20 attempts; the new test only covers 15 replicas, so headroom at higher real-world fan-in is unverified.

The rest (stale state reused after a failed resync, a misleading "etag changed" log for what's actually upload contention, a hand-rolled backoff sitting next to an already-vendored cenkalti/backoff, a redundant bootstrap write, duplicated test helper, and a stray blank line) are lower-severity but listed above with file/line.

Thank you. Addressed in #751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants