Extend DUMP & RESTORE to support object types (#1343) - #2090
Extend DUMP & RESTORE to support object types (#1343)#2090adirathore1402 wants to merge 1 commit into
Conversation
DUMP and RESTORE previously supported only string values. This extends them to Set, SortedSet, Hash and List objects by serializing/deserializing via GarnetObjectSerializer, wrapping the payload in the existing DUMP envelope (value-type byte + RESP length + payload + RDB version + CRC64). Also fixes the DUMP CRC64 to cover the value-type byte (matching RESTORE and Redis); this was previously masked because the string type byte is 0x00, which does not affect a CRC-64 with zero initial value.
|
adirathore1402 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
Pull request overview
Extends RESP DUMP/RESTORE handling to round-trip collection objects.
Changes:
- Adds object serialization and restoration paths.
- Includes value-type bytes in CRC64 generation.
- Adds collection, TTL, and existing-key tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
libs/server/Resp/KeyAdminCommands.cs |
Implements object DUMP/RESTORE handling. |
test/standalone/Garnet.test/RespTests.cs |
Adds object round-trip tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| GarnetObjectSerializer.Serialize(objectOutput.GarnetObject, out var serialized); | ||
|
|
||
| // The serializer output starts with the GarnetObjectType byte; use it as the payload's | ||
| // value-type byte and store the remaining bytes as the body (mirrors the string layout). | ||
| WriteDumpResult(serialized[0], serialized.AsSpan(1)); |
| var objectStatus = storageApi.GET(key, out ObjectOutput objectOutput); | ||
| if (objectStatus is GarnetStatus.OK && objectOutput.GarnetObject is not null) | ||
| { | ||
| GarnetObjectSerializer.Serialize(objectOutput.GarnetObject, out var serialized); |
| IGarnetObject garnetObject; | ||
| try | ||
| { | ||
| garnetObject = storeWrapper.GarnetObjectSerializer.Deserialize(serialized); | ||
| } | ||
| catch (GarnetException) | ||
| { | ||
| garnetObject = null; |
| storageApi.SET(key, garnetObject); | ||
|
|
||
| if (expiry > 0) | ||
| storageApi.EXPIRE(key, TimeSpan.FromSeconds(expiry), out _, ExpireOption.None); |
| storageApi.SET(key, garnetObject); | ||
|
|
||
| if (expiry > 0) | ||
| storageApi.EXPIRE(key, TimeSpan.FromSeconds(expiry), out _, ExpireOption.None); |
| GarnetObjectSerializer.Serialize(objectOutput.GarnetObject, out var serialized); | ||
|
|
||
| // The serializer output starts with the GarnetObjectType byte; use it as the payload's | ||
| // value-type byte and store the remaining bytes as the body (mirrors the string layout). | ||
| WriteDumpResult(serialized[0], serialized.AsSpan(1)); |
DUMP and RESTORE previously supported only string values. This extends them to Set, SortedSet, Hash and List objects by serializing/deserializing via GarnetObjectSerializer, wrapping the payload in the existing DUMP envelope (value-type byte + RESP length + payload + RDB version + CRC64).
Also fixes the DUMP CRC64 to cover the value-type byte (matching RESTORE and Redis); this was previously masked because the string type byte is 0x00, which does not affect a CRC-64 with zero initial value.