Zakir032002 opened a new pull request, #3368:
URL: https://github.com/apache/kvrocks/pull/3368

   ## Summary
   Add proper RDB serialization support for JSON type with full type 
preservation in DUMP/RESTORE operations.
   
   Implements custom RDB type 23 for JSON objects, enabling complete 
backup/restore functionality while maintaining all JSON data and metadata.
   
   Closes #[issue_number] (if there's an issue, otherwise remove this line)
   
   ## Changes
   - Implement custom RDB type 23 (`RDBTypeJson`) for JSON (Kvrocks-specific)
   - Add `SaveJsonObject()` and `LoadJsonObject()` methods
   - Use `friend class RDB` pattern (consistent with existing approach)
   - Integrate JSON into DUMP/RESTORE flow with proper type handling
   - Fixed clang-tidy modernize-use-auto warning
   
   ## Implementation Details
   
   **Custom RDB Type 23**:
   - Format: `[type:23][format_byte][json_string_length][json_string][crc64]`
   - Stores raw JSON string with format metadata
   - Compatible with existing RDB infrastructure
   - Preserves JSON storage format for internal operations
   
   **Integration Points**:
   - `SaveObjectType()`: Maps `kRedisJson` → `RDBTypeJson` (23)
   - `SaveObject()`: Retrieves JSON value using `read()` method and serializes
   - `LoadJsonObject()`: Deserializes JSON string from RDB stream
   - Uses `write()` method to restore JSON object to storage
   
   **Friend Class Pattern**:
   - Follows same approach as existing JSON implementation
   - Direct access to private `read()` method via `friend class RDB`
   - Consistent with project's design patterns
   
   ## Testing
   
   ### Manual Testing - Full DUMP/RESTORE Cycle
   
   **Test 1: Basic JSON Object DUMP/RESTORE with Type Preservation**
   ```bash
   127.0.0.1:6666> JSON.SET user1 $ '{"name":"Alice","age":30}'
   OK
   
   127.0.0.1:6666> JSON.GET user1 $
   "[{\"age\":30,\"name\":\"Alice\"}]"
   
   127.0.0.1:6666> DUMP user1
   "\x17\x00\x19{\"age\":30,\"name\":\"Alice\"}\x06\x007\xba9\xf6\xac\xf5;u"
   
   127.0.0.1:6666> DEL user1
   (integer) 1
   
   127.0.0.1:6666> RESTORE user1 0 
"\x17\x00\x19{\"age\":30,\"name\":\"Alice\"}\x06\x007\xba9\xf6\xac\xf5;u"
   OK
   
   127.0.0.1:6666> JSON.GET user1 $
   "[{\"age\":30,\"name\":\"Alice\"}]"  # ✅ Data preserved perfectly!
   
   127.0.0.1:6666> JSON.TYPE user1 $
   1) "object"                          # ✅ Type preserved as JSON!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to