Add NotFound callback to CustomRawStringFunctions and CustomObjectFunctions#1820
Merged
Merged
Conversation
…nctions; allows for extensions with non-null not found responses to register as read commands
Contributor
There was a problem hiding this comment.
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 onCustomRawStringFunctionsandCustomObjectFunctions, defaulting to writing a RESP null. - Wires NOTFOUND handling for custom raw-string and custom object commands to call the new
NotFoundcallback 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. |
badrishc
approved these changes
May 22, 2026
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]>
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.
Today custom commands that need a non-null response must register as
ReadModifyWriteand write the responseNeedInitialUpdate.This isn't ideal because
NeedInitialUpdateruns 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\nor$-1\r\ndepending on RESP version).These methods are called only when the custom command is registered as
CommandType.ReadwhenGarnetStatus.NOTFOUNDis returned byRead_ObjectStoreorRead_MainStore.