-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(search): Add DD option support for FT.DROPINDEX command #5885
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1131,18 +1131,59 @@ void SearchFamily::FtAlter(CmdArgList args, const CommandContext& cmd_cntx) { | |
|
|
||
| void SearchFamily::FtDropIndex(CmdArgList args, const CommandContext& cmd_cntx) { | ||
| string_view idx_name = ArgS(args, 0); | ||
| // TODO: Handle optional DD param | ||
|
|
||
| // Parse optional DD (Delete Documents) parameter | ||
| bool delete_docs = false; | ||
|
||
| if (args.size() > 1) { | ||
| string_view option = ArgS(args, 1); | ||
| // Only check for DD option, ignore other arguments for compatibility | ||
| if (absl::EqualsIgnoreCase(option, "DD")) { | ||
| delete_docs = true; | ||
| } | ||
| } | ||
|
|
||
| // Collect document keys (if DD is set), drop index, and delete documents in single transaction | ||
| vector<vector<string>> shard_doc_keys(delete_docs ? shard_set->size() : 0); | ||
|
||
| atomic_uint num_deleted{0}; | ||
| cmd_cntx.tx->ScheduleSingleHop([&](Transaction* t, EngineShard* es) { | ||
|
|
||
| auto cb = [&](Transaction* t, EngineShard* es) { | ||
| // Step 1: If DD is set, collect all document keys before dropping the index | ||
| if (delete_docs) { | ||
| auto* index = es->search_indices()->GetIndex(idx_name); | ||
| if (index) { | ||
| shard_doc_keys[es->shard_id()] = index->GetAllKeys(); | ||
| } | ||
| } | ||
|
||
|
|
||
| // Step 2: Drop the index | ||
| if (es->search_indices()->DropIndex(idx_name)) | ||
| num_deleted.fetch_add(1); | ||
|
|
||
| // Step 3: If DD is set, delete all documents that were in the index | ||
| if (delete_docs) { | ||
| const auto& keys = shard_doc_keys[es->shard_id()]; | ||
| if (!keys.empty()) { | ||
| auto op_args = t->GetOpArgs(es); | ||
| auto& db_slice = op_args.GetDbSlice(); | ||
|
|
||
| for (const auto& key : keys) { | ||
| auto it = db_slice.FindMutable(op_args.db_cntx, key).it; | ||
| if (IsValid(it)) { | ||
| db_slice.Del(op_args.db_cntx, it); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return OpStatus::OK; | ||
| }); | ||
| }; | ||
|
|
||
| cmd_cntx.tx->Execute(cb, true); | ||
|
|
||
| DCHECK(num_deleted == 0u || num_deleted == shard_set->size()); | ||
| if (num_deleted == 0u) | ||
| return cmd_cntx.rb->SendError("-Unknown Index name"); | ||
|
|
||
| return cmd_cntx.rb->SendOk(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keys shouldn't be empty inside
ids_(only insidekeys_), but see previous comment on that we don't need this functionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed