Skip to content

Serialize and Restore Schema command - [MOD-11803]#7032

Merged
GuyAv46 merged 11 commits intomasterfrom
guyav-serialize_schema_to_command
Oct 17, 2025
Merged

Serialize and Restore Schema command - [MOD-11803]#7032
GuyAv46 merged 11 commits intomasterfrom
guyav-serialize_schema_to_command

Conversation

@GuyAv46
Copy link
Collaborator

@GuyAv46 GuyAv46 commented Oct 12, 2025

Implement schema serialization and deserialization as part of the ASM effort

Serialization & Deserialization

Implement IndexSpec_Serialize and IndexSpec_Deserialize functions to generate a RedisModuleString from a schema and a schema (IndexSpec) from a serialization string.
The implementations rely on the type rdb_load and rdb_save implementations, so we now re-expose these methods to redis. This is okay, as we don't actually save the schemas as part of the key-space, so they won't be called by Redis if we don't call the manual implementations.

Testing is focused on the new logic, as the RDB serialization/deserialization is already well tested

_FT._RESTOREIFNX Command

A new command for manual RESTORE logic for non-key module-type objects of the module. Currently, there is a single "SCHEMA" sub-command to restore indexes.
An additional FT.DEBUG DUMP_SCHEMA command was added to generate a schema dump for the restore command.

Testing is again focused on the behavior of the restore command. The new debug command and the ACL registration are also tested

Main objects this PR modified

  1. Schema's type (ft_index0) RDB load and save implementations
  2. Implement manual dump and restore functions for IndexSpec
  3. Implement a new internal restore command
  4. Implement a debug dump command

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

Note

Introduce IndexSpec serialization/deserialization, an internal schema restore command, and a debug command to dump schemas, with supporting RDB refactors and tests.

  • Core / RDB:
    • Add IndexSpec_Serialize and IndexSpec_Deserialize to convert schemas to/from RDB-encoded RedisModuleString.
    • Expose type rdb methods via IndexSpec_RdbLoad_Logic and wrapper for IndexSpec_RdbSave; split store logic into IndexSpec_StoreAfterRdbLoad.
    • Refactor IndexSpec_StartGC to remove RedisModuleCtx*; switch GC logs to RSDummyContext.
  • Commands:
    • New internal command '_FT._RESTOREIFNX SCHEMA <encver> <blob>' (macro RS_RESTORE_IF_NX) to restore schema; register subcommand.
    • New debug command FT.DEBUG DUMP_SCHEMA <index> returning serialized schema and encoding version; register in debug help.
  • Module wiring:
    • Register restore command and subcommand; adjust command flags/ACL categories.
  • Mocks / Tests:
    • Redismock: add SaveDataTypeToString/LoadDataTypeFromStringEncver helpers.
    • C++ tests for RDB roundtrip and string serialize/deserialize.
    • Python tests for debug help, DUMP_SCHEMA, and end-to-end restore (_FT._RESTOREIFNX SCHEMA).

Written by Cursor Bugbot for commit 17b4fe3. This will update automatically on new commits. Configure here.

@GuyAv46 GuyAv46 force-pushed the guyav-serialize_schema_to_command branch from 963f5c3 to b950314 Compare October 12, 2025 17:24
@GuyAv46 GuyAv46 changed the base branch from guyav-ASM_notifications to master October 12, 2025 17:24
@GuyAv46 GuyAv46 requested a review from alonre24 October 12, 2025 17:26
@GuyAv46 GuyAv46 changed the title Guyav serialize schema to command Serialize and Restore Schema command - [MOD-11803] Oct 12, 2025
@GuyAv46 GuyAv46 marked this pull request as ready for review October 12, 2025 17:39
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Collaborator

@alonre24 alonre24 left a comment

Choose a reason for hiding this comment

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

Nice!

Comment on lines +3394 to +3395
.rdb_load = IndexSpec_RdbLoad_Logic, // We don't store the index spec in the key space,
.rdb_save = IndexSpec_RdbSave_Wrapper, // but these are useful for serialization/deserialization (and legacy loading)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you remind me of the motivation for this change?
Is the reason for not using simply using Indexes_RdbLoad upon handling the new ASM event of adding a new node (next PR) supporting legacy loading?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can't serialize all the schemas together with aux_save, first and foremost, because there is no API to do so. It's also simpler to handle the schemas one by one, as some may exist already, while others may not.

This change gives back the existing load and save functionalities of single schema serialization and deserialization, allowing us to use RedisModule_LoadDataTypeFromStringEncver and RedisModule_SaveDataTypeToString, and maybe other APIs in the future.
We still don't actually create any key of the schema type, so these should not be called automatically by redis while saving to RDB (only by the aux_save callback)

@GuyAv46 GuyAv46 force-pushed the guyav-serialize_schema_to_command branch from cd4e361 to 17b4fe3 Compare October 13, 2025 06:23
@codecov
Copy link

codecov bot commented Oct 13, 2025

Codecov Report

❌ Patch coverage is 98.27586% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.51%. Comparing base (6cd3771) to head (17b4fe3).
⚠️ Report is 41 commits behind head on master.

Files with missing lines Patch % Lines
src/debug_commands.c 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7032      +/-   ##
==========================================
- Coverage   85.51%   85.51%   -0.01%     
==========================================
  Files         321      321              
  Lines       50738    50786      +48     
  Branches    10351    10351              
==========================================
+ Hits        43391    43430      +39     
- Misses       7196     7205       +9     
  Partials      151      151              
Flag Coverage Δ
flow 83.99% <98.27%> (-0.11%) ⬇️
unit 51.52% <46.55%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@raz-mon raz-mon left a comment

Choose a reason for hiding this comment

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

LGTM overall
One question

Copy link
Collaborator

@raz-mon raz-mon left a comment

Choose a reason for hiding this comment

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

LGTM
Regarding the ASM design (upcoming PRs to use this), I think it is not a great design (for our module at least), since replication of the index should occur upon shard addition rather than upon slot migration. It's quite wasteful to send all the aux data for every slot migration.
Nonetheless this functionality is good for us and nicely done! 💪

@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 15, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 15, 2025
@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 15, 2025
@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 16, 2025
@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 16, 2025
@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 16, 2025
@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 16, 2025
github-merge-queue bot pushed a commit that referenced this pull request Oct 16, 2025
* layout basic schema command generation

* implement IndexSpec_Serialize and IndexSpec_Deserialize

* added a unit-test

* fix warning

* implement mock API

* implement restore schema command

* add tests (and a dump debug command)

* improve test

* remove temporary logs

* fix tests
@GuyAv46 GuyAv46 removed this pull request from the merge queue due to a manual request Oct 16, 2025
@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 16, 2025
@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 16, 2025
@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 17, 2025
@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 17, 2025
@GuyAv46 GuyAv46 removed this pull request from the merge queue due to a manual request Oct 17, 2025
@GuyAv46 GuyAv46 added this pull request to the merge queue Oct 17, 2025
Merged via the queue into master with commit 5feebc4 Oct 17, 2025
28 of 32 checks passed
@GuyAv46 GuyAv46 deleted the guyav-serialize_schema_to_command branch October 17, 2025 23:15
@GuyAv46
Copy link
Collaborator Author

GuyAv46 commented Oct 23, 2025

/backport

redisearch-backport-pull-request bot pushed a commit that referenced this pull request Oct 23, 2025
* layout basic schema command generation

* implement IndexSpec_Serialize and IndexSpec_Deserialize

* added a unit-test

* fix warning

* implement mock API

* implement restore schema command

* add tests (and a dump debug command)

* improve test

* remove temporary logs

* fix tests

(cherry picked from commit 5feebc4)
@redisearch-backport-pull-request
Copy link
Contributor

Successfully created backport PR for 8.4:

github-merge-queue bot pushed a commit that referenced this pull request Oct 24, 2025
Serialize and Restore Schema command - [MOD-11803] (#7032)

* layout basic schema command generation

* implement IndexSpec_Serialize and IndexSpec_Deserialize

* added a unit-test

* fix warning

* implement mock API

* implement restore schema command

* add tests (and a dump debug command)

* improve test

* remove temporary logs

* fix tests

(cherry picked from commit 5feebc4)

Co-authored-by: GuyAv46 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants