Skip to content

Scope events cache entries to the shard context instance - #11660

Draft
prathyushpv wants to merge 2 commits into
mainfrom
ppv/events-cache-invalidation
Draft

Scope events cache entries to the shard context instance#11660
prathyushpv wants to merge 2 commits into
mainfrom
ppv/events-cache-invalidation

Conversation

@prathyushpv

@prathyushpv prathyushpv commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What changed?

Added ShardUUID to events.EventKey, populated from shardContext.GetOwner(), so cache entries become unreachable once the shard context is rebuilt.

Why?

Events are cached when they are built, before the transaction persists. A write that loses the shard's range CAS leaves the entry behind, a later transaction reuses that event ID for a different event, and transfer_queue_active_task_executor.go:967 then nil-derefs the mismatched attributes. Before #11450 a shard reload dropped the cache; now it is process-lifetime, so this mirrors the workflow context cache, whose Key already carries a ShardUUID.

How did you test it?

  • built
  • covered by existing tests
  • added new unit test(s)

TestStaleCachedEventNotServedAfterShardReload panics on main and passes here.

Events are cached when they are built, before the transaction is
persisted. If that write loses the shard's range CAS, mutable state's
NextEventID is unchanged and a later transaction can persist a different
event at the same event ID, leaving the cache holding an event that no
longer matches history. Nothing invalidates it: DeleteEvent has no
production callers.

Adding ShardUUID to EventKey makes entries unreachable after the shard
context is rebuilt, mirroring the workflow context cache, whose Key
already carries a ShardUUID from GetOwner().
- Collapse the nine EventKey literals into MutableStateImpl.eventKey so a
  future call site cannot omit the shard scope.
- Drive the reproduction test through ApplyActivityTaskScheduledEvent: a
  timer event is never cached in production, so the previous fixture could
  not occur, and calling writeEventToCache directly skipped the plumbing
  the test claims to cover. Also assert the caching instance still reads
  its own entry, so an unstable ShardUUID cannot pass silently.
- Assert the shard-scoped key in the NDC replication test; it was the only
  production site whose removal no test caught.
- Stop newTestContext mutating the caller's ShardInfo, which gave two
  contexts the same owner when a caller reused the pointer.
- Fold the duplicate invalid-key tests into one table and name the shard
  UUID in the validateKey warning.
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.

1 participant