Skip to content

[Objects] Do not create the key when an object RMW leaves the new object empty - #2194

Merged
Badrish Chandramouli (badrishc) merged 1 commit into
microsoft:mainfrom
Laurianti:fix-zadd-xx-missing-key
Oct 2, 2026
Merged

Badrish Chandramouli (badrishc) merged 1 commit into
microsoft:mainfrom
Laurianti:fix-zadd-xx-missing-key

Conversation

@Laurianti

@Laurianti Federico Laurianti (Laurianti) commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause

ZADD with XX on a missing key creates an empty sorted set: ZADD must create the object in general, so GarnetObject.NeedToCreate returns true, and InitialUpdater stores the new object even though XX left it empty. The key then shows up in EXISTS, TYPE and DBSIZE.

Description of Change

libs/server/Storage/Functions/ObjectStore/RMWMethods.cs: in InitialUpdater, after Operate, if the object signals RemoveKey (it is empty) the record is not created and InitialUpdater returns false. This is the flag InPlaceUpdater and CopyUpdater already use to remove a collection that becomes empty, and the same false return the main store's InitialUpdater uses for SET and PFADD.

The reply written by Operate is kept, so ZADD XX still validates its options and replies 0 as before. Any other operation that would leave a new object empty gets the same treatment.

Tests

  • RespSortedSetTests.AddWithXXOnMissingKeyDoesNotCreateKey: after ZADD XX and ZADD XX CH on a missing key, the key does not exist. It fails without the change.
  • AddWithOptionsErrorConditions (option errors on a missing key) still passes. On current main with this change, net10.0: Garnet.test.collections 783 passed, Garnet.test 1291 passed (9 skipped).

Issues Fixed

Fixes #2191

@Laurianti
Federico Laurianti (Laurianti) marked this pull request as ready for review October 2, 2026 03:59
Copilot AI balanced review requested due to automatic review settings October 2, 2026 03:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

A reused ObjectOutput can retain a stale RemoveKey flag and incorrectly reject a later valid object creation.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Prevents empty object keys from being created when an initial RMW leaves the collection empty.

Changes:

  • Rejects initial object creation when RemoveKey is signaled.
  • Adds coverage for ZADD XX and XX CH on missing keys.
File Description
libs/​server/​Storage/​Functions/​ObjectStore/​RMWMethods.cs Skips creation of empty objects.
test/​standalone/​Garnet.test.collections/​RespSortedSetTests.cs Tests missing-key ZADD XX behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread libs/server/Storage/Functions/ObjectStore/RMWMethods.cs
@badrishc
Badrish Chandramouli (badrishc) merged commit c465175 into microsoft:main Oct 2, 2026
169 checks passed
@Laurianti
Federico Laurianti (Laurianti) deleted the fix-zadd-xx-missing-key branch October 2, 2026 18:24
x@01 (x-at-01) added a commit to webc-fork/garnet that referenced this pull request Oct 4, 2026
…n missing key (microsoft#2192), ZADD XX INCR null (microsoft#2197), no empty object from object RMW (microsoft#2194), fresh ObjectOutput per key HCOLLECT/ZCOLLECT (microsoft#2200), CompletionEvent disposal + LogSizeTracker coalesce (microsoft#2198), dynamic test ports (microsoft#2193)
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.

LSET, HDEL, HPERSIST and ZADD XX create an empty key when the key does not exist

3 participants