Skip to content

Commit a1e01d7

Browse files
authored
fix: search index restore when index names start with ‘:’ (e.g. :Order:index) (#5755)
* fix: load save search index fix * fix: review comments
1 parent 5b1ecb9 commit a1e01d7

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/server/rdb_load.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,8 @@ void RdbLoader::LoadSearchIndexDefFromAux(string&& def) {
28122812
facade::RespVec resp_vec;
28132813
facade::RedisParser parser;
28142814

2815+
// Prepend a whitespace so names starting with ':' are treated as names, not RESP tokens.
2816+
def.insert(def.begin(), ' ');
28152817
def += "\r\n"; // RESP terminator
28162818
io::MutableBytes buffer{reinterpret_cast<uint8_t*>(def.data()), def.size()};
28172819
auto res = parser.Parse(buffer, &consumed, &resp_vec);

src/server/rdb_test.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,26 @@ TEST_F(RdbTest, SBF) {
670670
EXPECT_THAT(Run({"BF.EXISTS", "k", "1"}), IntArg(1));
671671
}
672672

673+
TEST_F(RdbTest, RestoreSearchIndexNameStartingWithColon) {
674+
// Create an index with a name that starts with ':' and add a sample document
675+
EXPECT_EQ(Run({"FT.CREATE", ":Order:index", "ON", "HASH", "PREFIX", "1", ":Order:", "SCHEMA",
676+
"customer_name", "AS", "customer_name", "TEXT", "status", "AS", "status", "TAG"}),
677+
"OK");
678+
679+
EXPECT_THAT(Run({"HSET", ":Order:1", "customer_name", "John", "status", "new"}), IntArg(2));
680+
681+
// Save and reload to ensure the index definition is persisted and restored
682+
EXPECT_EQ(Run({"save", "df"}), "OK");
683+
EXPECT_EQ(Run({"debug", "reload"}), "OK");
684+
685+
// Verify a basic search works on the restored index
686+
auto search = Run({"FT.SEARCH", ":Order:index", "John"});
687+
ASSERT_THAT(search, ArgType(RespExpr::ARRAY));
688+
const auto& v = search.GetVec();
689+
ASSERT_FALSE(v.empty());
690+
EXPECT_THAT(v.front(), IntArg(1));
691+
}
692+
673693
TEST_F(RdbTest, DflyLoadAppend) {
674694
// Create an RDB with (k1,1) value in it saved as `filename`
675695
EXPECT_EQ(Run({"set", "k1", "1"}), "OK");

0 commit comments

Comments
 (0)