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

checkTypeBeforeDropIndex #3413

Merged
merged 3 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/meta/processors/index/DropEdgeIndexProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ void DropEdgeIndexProcessor::process(const cpp2::DropEdgeIndexReq& req) {
keys.emplace_back(MetaKeyUtils::indexIndexKey(spaceID, indexName));
keys.emplace_back(MetaKeyUtils::indexKey(spaceID, edgeIndexID));

auto indexItemRet = doGet(keys.back());
if (!nebula::ok(indexItemRet)) {
auto retCode = nebula::error(indexItemRet);
if (retCode == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) {
retCode = nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND;
}
LOG(ERROR) << "Drop Edge Index Failed: SpaceID " << spaceID << " Index Name: " << indexName
<< " error: " << apache::thrift::util::enumNameSafe(retCode);
handleErrorCode(retCode);
onFinished();
return;
}

auto item = MetaKeyUtils::parseIndex(nebula::value(indexItemRet));
if (item.get_schema_id().getType() != nebula::cpp2::SchemaID::Type::edge_type) {
LOG(ERROR) << "Drop Edge Index Failed: Index Name " << indexName << " is not EdgeIndex";
resp_.set_code(nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND);
onFinished();
return;
}

LOG(INFO) << "Drop Edge Index " << indexName;
resp_.set_id(to(edgeIndexID, EntryType::INDEX));
doSyncMultiRemoveAndUpdate(std::move(keys));
Expand Down
21 changes: 21 additions & 0 deletions src/meta/processors/index/DropTagIndexProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ void DropTagIndexProcessor::process(const cpp2::DropTagIndexReq& req) {
keys.emplace_back(MetaKeyUtils::indexIndexKey(spaceID, indexName));
keys.emplace_back(MetaKeyUtils::indexKey(spaceID, tagIndexID));

auto indexItemRet = doGet(keys.back());
if (!nebula::ok(indexItemRet)) {
auto retCode = nebula::error(indexItemRet);
if (retCode == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) {
retCode = nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND;
}
LOG(ERROR) << "Drop Tag Index Failed: SpaceID " << spaceID << " Index Name: " << indexName
<< " error: " << apache::thrift::util::enumNameSafe(retCode);
handleErrorCode(retCode);
onFinished();
return;
}

auto item = MetaKeyUtils::parseIndex(nebula::value(indexItemRet));
if (item.get_schema_id().getType() != nebula::cpp2::SchemaID::Type::tag_id) {
LOG(ERROR) << "Drop Tag Index Failed: Index Name " << indexName << " is not TagIndex";
resp_.set_code(nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND);
onFinished();
return;
}

LOG(INFO) << "Drop Tag Index " << indexName;
resp_.set_id(to(tagIndexID, EntryType::INDEX));
doSyncMultiRemoveAndUpdate(std::move(keys));
Expand Down
12 changes: 12 additions & 0 deletions tests/tck/features/index/TagEdgeIndex.feature
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ Feature: tag and edge index tests from pytest
Then the result should be, in any order:
| Tag Index Name | Create Tag Index |
| 'multi_tag_index' | 'CREATE TAG INDEX `multi_tag_index` ON `tag_1` (\n `col2`,\n `col3`\n)' |
# Check if check tag/edge type before drop index
When executing query:
"""
DROP EDGE INDEX multi_tag_index
"""
Then an ExecutionError should be raised at runtime.
When executing query:
"""
DROP TAG INDEX multi_tag_index
Expand Down Expand Up @@ -405,6 +411,12 @@ Feature: tag and edge index tests from pytest
Then the result should be, in any order:
| Edge Index Name | Create Edge Index |
| 'multi_edge_index' | 'CREATE EDGE INDEX `multi_edge_index` ON `edge_1` (\n `col2`,\n `col3`\n)' |
# Check if check tag/edge type before drop index
When executing query:
"""
DROP TAG INDEX multi_edge_index
"""
Then an ExecutionError should be raised at runtime.
# Check if show create edge index works well
When executing query:
"""
Expand Down