Skip to content

fix(hazelcast): use atomic operations for tag list updates#308

Merged
eko merged 1 commit into
eko:masterfrom
semihbkgr:fix/hazelcast-tags-cas
May 3, 2026
Merged

fix(hazelcast): use atomic operations for tag list updates#308
eko merged 1 commit into
eko:masterfrom
semihbkgr:fix/hazelcast-tags-cas

Conversation

@semihbkgr

Copy link
Copy Markdown
Contributor

Replaces the racy Get → modify → SetWithTTL pattern in setTags with atomic operations to remove race conditions under concurrent modification of the same tag. Two writers appending to the same tag could each Get the same value and overwrite each other's appends, silently dropping keys from the tag list.

Following the same approach as the Memcache store, the update is now done via:

  • PutIfAbsentWithTTL — atomic create-if-absent on the first-writer path (counterpart of memcache's Add).
  • ReplaceIfSame — atomic CAS on the update path (counterpart of memcache's CompareAndSwap); paired with SetTTL to refresh the tag's expiration.
  • SetTTL on the duplicate-key path so re-Set of an existing (key, tag) still refreshes the tag's TTL — same fix as fix(memcache): refresh tag TTL when re-Setting an existing (key, tag) #307 for memcache.

Mock regenerated via mockgen. Tests cover all three paths: create, CAS update, and duplicate-key TTL refresh.

Switches setTags from a racy Get → SetWithTTL pattern to atomic
PutIfAbsentWithTTL / ReplaceIfSame primitives, and refreshes the tag's
TTL on every Set (including the duplicate-key case). Aligns the
Hazelcast tag-handling shape with the Memcache store.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@eko eko merged commit ba2f816 into eko:master May 3, 2026
10 checks passed
@eko

eko commented May 3, 2026

Copy link
Copy Markdown
Owner

Thank you for this update @semihbkgr

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.

2 participants