Skip to content

Commit

Permalink
checkTypeBeforeDropIndex (#3413)
Browse files Browse the repository at this point in the history
Co-authored-by: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com>
Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 7, 2021
1 parent d42203d commit 6300233
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
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

0 comments on commit 6300233

Please sign in to comment.