Fix/trashcan restore wal barrier - #54
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MR title
fix(crud): prevent trash-can restore from wedging WAL publishingSummary
Fix WAL barrier bookkeeping during trash-can restore and add diagnostics for detecting a stalled WAL publisher.
This MR:
activeOpswhen one handler acquires graph locks in multiple passes;Problem
Graph write locks participate in the WAL barrier:
MarkOperationActive(opTime).operationKeysMutexUnlockcallsMarkOperationDone(opTime).Trash-can restore broke this pairing.
CreateObjectand theUpdateObjectupsert path first acquired the object's write lock, thenrestoreObjectFromTrashCanacquired additional edge locks. Both lock passes marked the same operation active, but the handler performed only one unlock:The orphan permanently pinned the WAL barrier. The publisher stopped draining
pendingTxs, causing unbounded memory growth and repeated sorting and scanning of the growing backlog.A related issue allowed
__key_lock_timeto propagate into child handler payloads. The child then consumed the parent's mark during its own unlock, releasing the WAL barrier while the parent was still writing.Fix
Balanced per-handler marking
Both graph lock helpers now use
markOperationActiveOnce.A handler acquiring locks several times before one unlock contributes only one
activeOpsmark. If a later lock pass unexpectedly carries an olderopTime, the mark is moved to the older timestamp by activating it before releasing the newer one, so the barrier is never temporarily empty.Invocation-local child payloads
injectParentHoldsLocksstill promotes held locks into__parent_holds_locks, but now removes both per-handler fields from the child payload:__key_locks__key_lock_timeThe child therefore knows which locks its parent holds without inheriting bookkeeping that its own unlock could consume.
This remains local to graph CRUD and does not introduce global payload filtering in the statefun runtime.
Restore contract guard
restoreObjectFromTrashCandocuments its locking contract and emits a warning when called without an existing operation mark.Observability
Added the following per-cache Prometheus gauges:
cache_pending_transactionscache_active_operationscache_oldest_pending_age_secondscache_oldest_active_operation_age_secondscache_wal_publish_totalcache_wal_publish_errors_totalThe age metrics distinguish a temporarily busy publisher from a wedged one. With a stuck barrier, the oldest pending age keeps increasing while the successful publish count stays flat.
StoreStatsForTestexposes the same snapshot data for deterministic regression and leak tests.Tests
Added:
CreateObject;UpdateObject(..., upsert=true);Verification performed:
go test ./statefun/cache/... ./embedded/graph/crud/... -count=1 scripts/run-leak-tests.sh --scenario s14S14 result:
Commits
827957a fix(crud): balance WAL barrier across trash restores04ed9e2 feat(cache): expose WAL barrier metrics