Skip to content

Add NotFound callback to CustomRawStringFunctions and CustomObjectFunctions#1820

Merged
kevin-montrose merged 7 commits into
mainfrom
users/kmontrose/customRespCommandNotFound
May 22, 2026
Merged

Add NotFound callback to CustomRawStringFunctions and CustomObjectFunctions#1820
kevin-montrose merged 7 commits into
mainfrom
users/kmontrose/customRespCommandNotFound

Conversation

@kevin-montrose

@kevin-montrose kevin-montrose commented May 22, 2026

Copy link
Copy Markdown
Contributor

Today custom commands that need a non-null response must register as ReadModifyWrite and write the response NeedInitialUpdate.

This isn't ideal because NeedInitialUpdate runs under an exclusive lock for the record, so commands which are logical reads block each other.

This PR adds:

  • CustomRawStringFunctions.NotFound(ReadOnlySpan<byte> key, ref StringInput input, ref RespMemoryWriter writer)
  • CustomObjectFunctions.NotFound(ReadOnlySpan<byte> key, ref ObjectInput input, ref RespMemoryWriter writer)

Which can be overridden to customize behavior. The default behavior remains writing a null (either _\r\n or $-1\r\n depending on RESP version).

These methods are called only when the custom command is registered as CommandType.Read when GarnetStatus.NOTFOUND is returned by Read_ObjectStore or Read_MainStore.

…nctions; allows for extensions with non-null not found responses to register as read commands
Copilot AI review requested due to automatic review settings May 22, 2026 18:17

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.

Pull request overview

This PR adds a NotFound callback to the custom command function bases (CustomRawStringFunctions and CustomObjectFunctions) so custom read commands can emit a non-null response on missing keys without needing to register as ReadModifyWrite (avoiding exclusive record locks for logical reads).

Changes:

  • Introduces NotFound(...) virtual methods on CustomRawStringFunctions and CustomObjectFunctions, defaulting to writing a RESP null.
  • Wires NOTFOUND handling for custom raw-string and custom object commands to call the new NotFound callback instead of always writing a null.
  • Adds tests covering custom NOTFOUND responses (including a large key payload) for both object and raw-string custom commands.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/standalone/Garnet.test.scripting/RespCustomCommandTests.cs Adds tests and helper custom function types validating overridden NotFound responses.
libs/server/Resp/RespServerSession.cs Updates call sites to pass the full custom command object into execution helpers.
libs/server/Custom/CustomRespCommands.cs Routes NOTFOUND cases through functions.NotFound(...) for both network and invoke paths.
libs/server/Custom/CustomRawStringFunctions.cs Adds NotFound virtual with default null response + documentation.
libs/server/Custom/CustomObjectFunctions.cs Adds NotFound virtual with default null response + documentation.
libs/common/RespMemoryWriter.cs Minor signature cleanup: removes redundant unsafe modifier from the ctor.

Comment thread libs/server/Custom/CustomRespCommands.cs Outdated
Comment thread libs/server/Custom/CustomRespCommands.cs Outdated
Comment thread libs/server/Custom/CustomRawStringFunctions.cs Outdated
Comment thread libs/server/Custom/CustomObjectFunctions.cs Outdated
Comment thread libs/server/Custom/CustomRespCommands.cs Outdated
@kevin-montrose kevin-montrose merged commit a658d2a into main May 22, 2026
267 of 269 checks passed
@kevin-montrose kevin-montrose deleted the users/kmontrose/customRespCommandNotFound branch May 22, 2026 21:04
crprashant added a commit to crprashant/garnet that referenced this pull request Jun 2, 2026
Replace the RMW-on-read workaround for R.GETBIT/R.BITCOUNT/R.BITPOS with the new NotFound callback (PR microsoft#1820), so reads no longer create keys. Register these three as CommandType.Read. Drop Allure attributes from the Roaring Bitmap tests to match the test project on main.
kevin-montrose pushed a commit that referenced this pull request Jun 10, 2026
* Roaring Bitmaps as a Garnet module (issue #1270)

Addresses PR review feedback from @badrishc:
- Move the extension from main/GarnetServer/Extensions/RoaringBitmap to
  modules/RoaringBitmap so it isn't bundled by default (mirrors GarnetJSON).
- Retarget the PR to dev (companion change).

Implementation changes for the move:
- New modules/RoaringBitmap/GarnetRoaringBitmap.csproj (mirrors GarnetJSON.csproj,
  signs assembly, exposes InternalsVisibleTo Garnet.test).
- New RoaringBitmapModule : ModuleBase entry point that registers the
  factory and the four R.SETBIT/R.GETBIT/R.BITCOUNT/R.BITPOS commands.
- Renamed namespace Garnet.Extensions.RoaringBitmap -> GarnetRoaringBitmap
  to avoid the namespace/class collision with class RoaringBitmap.
- Updated CustomObjectFunctions overrides to dev-branch
  scoped ReadOnlySpan<byte> signatures for NeedInitialUpdate / Updater.
- Updated RoaringBitmapObject to dev-branch CustomObjectBase ctor and
  HeapMemorySize accounting.
- Wired the module into Garnet.slnx and Garnet.test.csproj.
- Tests still register via server.Register.NewCommand in [SetUp] (in-process),
  matching the existing custom-object test pattern.
- Updated StringKeyAndCustomObjectKey_AreSeparate to expect WRONGTYPE on the
  unified store on dev.

* ci: retrigger failed cluster test jobs

Co-authored-by: Copilot <[email protected]>

* Use NotFound callback for read-only R.* commands

Replace the RMW-on-read workaround for R.GETBIT/R.BITCOUNT/R.BITPOS with the new NotFound callback (PR #1820), so reads no longer create keys. Register these three as CommandType.Read. Drop Allure attributes from the Roaring Bitmap tests to match the test project on main.

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Prashant Chinnam <[email protected]>
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.

3 participants