Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: search index persistence #1721

Merged
merged 3 commits into from
Aug 24, 2023
Merged

Conversation

dranikpg
Copy link
Contributor

@dranikpg dranikpg commented Aug 21, 2023

This PR adds persistence for search indices

Their definitions are stored in plain string form in AUX fields

@dranikpg dranikpg force-pushed the search-persistence branch 2 times, most recently from 223e35e to a7319dd Compare August 22, 2023 08:20
Comment on lines +2362 to +2366
if (res != facade::RedisParser::Result::OK) {
LOG(ERROR) << "Bad index definition: " << def;
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Script compilation (see above) fails silently, so this should too?

@dranikpg dranikpg changed the title [WIP] feat: WIP search index persistence feat: search index persistence Aug 22, 2023
@dranikpg dranikpg marked this pull request as ready for review August 22, 2023 08:23
Comment on lines 2356 to 2362
facade::RespVec resp_vec;
facade::RedisParser parser;

absl::Span<uint8_t> buffer{reinterpret_cast<uint8_t*>(def.data()), def.size()};
auto res = parser.Parse(buffer, &consumed, &resp_vec);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically we don't need this bulky parser code, we can just split by whitespace (taking into account we build the string like this without any formatting). So RESP would be needed only for quotation marks? 🤔

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
void LoadScriptFromAux(std::string&& value);
void LoadSearchIndexDefFromAux(std::string&& value);

private:
Copy link
Contributor

Choose a reason for hiding this comment

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

This private is redundant, you should also get a warning for that. Plz see comment below, and if you don't agree ignore me here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I always do this to group members away from functions. Does it produce a warning? Will look at it

src/server/rdb_save.cc Outdated Show resolved Hide resolved
RETURN_ON_ERR(impl_->SaveAuxFieldStrStr("lua", s));
}

// Save search index definitions only in summary dfs file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Question here, isn't the summary file only part of our extension to the rdb format? Actually this is also a good place to check my mental understanding of this so:

  1. For plain rdb compatible with redis, we produce only one file no matter how many threads we run on.
  2. For our extension, we produce n + 1 files where n is the number of threads + 1 for the summary file.

If the above is true, then shouldn't we also cover the case for plain rdb files ? (assuming here this is 1-1, because this is a module in redis and I am unsure how search works there)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, will add a comment. For now we decided to be not compatible with rdb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, your points are correct, I intend to save only inside the dfs summary

absl::StrAppend(&out, " PREFIX", " 1 ", base_index.prefix);

absl::StrAppend(&out, " SCHEMA");
for (auto [fname, finfo] : base_index.schema.fields) {
Copy link
Contributor

Choose a reason for hiding this comment

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

deep copy here of std::string && SchemaField. I made a suggestion so you don't have to deal with this :)

src/server/search/doc_index.cc Outdated Show resolved Hide resolved
@kostasrim
Copy link
Contributor

Nice work 👨‍🍳

dranikpg and others added 2 commits August 23, 2023 16:03
Co-authored-by: Kostas Kyrimis  <kostaskyrim@gmail.com>
Signed-off-by: Vladislav <vladislav.oleshko@gmail.com>
Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
RETURN_ON_ERR(impl_->SaveAuxFieldStrStr("lua", s));

if (save_mode_ == SaveMode::RDB) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! So that was a bug!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I just print a warnings now 😄 Unknown aux fields are ignored either way

@dranikpg dranikpg merged commit 84871b8 into dragonflydb:main Aug 24, 2023
7 checks passed
@dranikpg dranikpg deleted the search-persistence branch August 25, 2023 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants