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

Added if_exists flag when drop index of edge and tag #1598

Merged
merged 15 commits into from
Jan 8, 2020
2 changes: 1 addition & 1 deletion src/graph/DropEdgeIndexExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void DropEdgeIndexExecutor::execute() {

auto *name = sentence_->indexName();
auto spaceId = ectx()->rctx()->session()->space();
auto future = ectx()->getMetaClient()->dropEdgeIndex(spaceId, *name);
auto future = ectx()->getMetaClient()->dropEdgeIndex(spaceId, *name, sentence_->isIfExists());
auto *runner = ectx()->rctx()->runner();

auto cb = [this] (auto &&resp) {
Expand Down
2 changes: 1 addition & 1 deletion src/graph/DropTagIndexExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void DropTagIndexExecutor::execute() {

auto *name = sentence_->indexName();
auto spaceId = ectx()->rctx()->session()->space();
auto future = ectx()->getMetaClient()->dropTagIndex(spaceId, *name);
auto future = ectx()->getMetaClient()->dropTagIndex(spaceId, *name, sentence_->isIfExists());
auto *runner = ectx()->rctx()->runner();

auto cb = [this] (auto &&resp) {
Expand Down
24 changes: 24 additions & 0 deletions src/graph/test/IndexTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ TEST_F(IndexTest, TagIndex) {
code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::E_EXECUTION_ERROR, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "DROP TAG INDEX not_exists_tag_index";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::E_EXECUTION_ERROR, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "DROP TAG INDEX IF EXISTS not_exists_tag_index";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
}

TEST_F(IndexTest, EdgeIndex) {
Expand Down Expand Up @@ -237,6 +249,18 @@ TEST_F(IndexTest, EdgeIndex) {
code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::E_EXECUTION_ERROR, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "DROP EDGE INDEX not_exists_edge_index";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::E_EXECUTION_ERROR, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "DROP EDGE INDEX IF EXISTS not_exists_edge_index";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
}

} // namespace graph
Expand Down
2 changes: 2 additions & 0 deletions src/interface/meta.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ struct CreateTagIndexReq {
struct DropTagIndexReq {
1: common.GraphSpaceID space_id,
2: string index_name,
3: bool if_exists,
}

struct GetTagIndexReq {
Expand Down Expand Up @@ -450,6 +451,7 @@ struct CreateEdgeIndexReq {
struct DropEdgeIndexReq {
1: common.GraphSpaceID space_id,
2: string index_name,
3: bool if_exists,
}

struct GetEdgeIndexReq {
Expand Down
18 changes: 12 additions & 6 deletions src/meta/client/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,17 +1156,20 @@ MetaClient::createTagIndex(GraphSpaceID spaceID,
}

folly::Future<StatusOr<bool>>
MetaClient::dropTagIndex(GraphSpaceID spaceID, std::string name) {
MetaClient::dropTagIndex(GraphSpaceID spaceID,
std::string name,
bool ifExists) {
cpp2::DropTagIndexReq req;
req.set_space_id(std::move(spaceID));
req.set_index_name(std::move(name));
req.set_if_exists(ifExists);

folly::Promise<StatusOr<bool>> promise;
auto future = promise.getFuture();
getResponse(std::move(req), [] (auto client, auto request) {
return client->future_dropTagIndex(request);
}, [] (cpp2::ExecResp&& resp) -> TagIndexID {
return resp.get_id().get_tag_index_id();
}, [] (cpp2::ExecResp&& resp) -> bool {
return resp.code == cpp2::ErrorCode::SUCCEEDED;
}, std::move(promise), true);
return future;
}
Expand Down Expand Up @@ -1247,17 +1250,20 @@ MetaClient::createEdgeIndex(GraphSpaceID spaceID,
}

folly::Future<StatusOr<bool>>
MetaClient::dropEdgeIndex(GraphSpaceID spaceID, std::string name) {
MetaClient::dropEdgeIndex(GraphSpaceID spaceID,
std::string name,
bool ifExists) {
cpp2::DropEdgeIndexReq req;
req.set_space_id(std::move(spaceID));
req.set_index_name(std::move(name));
req.set_if_exists(ifExists);

folly::Promise<StatusOr<bool>> promise;
auto future = promise.getFuture();
getResponse(std::move(req), [] (auto client, auto request) {
return client->future_dropEdgeIndex(request);
}, [] (cpp2::ExecResp&& resp) -> EdgeIndexID {
return resp.get_id().get_edge_index_id();
}, [] (cpp2::ExecResp&& resp) -> bool {
return resp.code == cpp2::ErrorCode::SUCCEEDED;
}, std::move(promise), true);
return future;
}
Expand Down
4 changes: 2 additions & 2 deletions src/meta/client/MetaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class MetaClient {

// Remove the define of tag index
folly::Future<StatusOr<bool>>
dropTagIndex(GraphSpaceID spaceId, std::string name);
dropTagIndex(GraphSpaceID spaceId, std::string name, bool ifExists = false);

folly::Future<StatusOr<cpp2::TagIndexItem>>
getTagIndex(GraphSpaceID spaceId, std::string name);
Expand All @@ -270,7 +270,7 @@ class MetaClient {

// Remove the define of edge index
folly::Future<StatusOr<bool>>
dropEdgeIndex(GraphSpaceID spaceId, std::string name);
dropEdgeIndex(GraphSpaceID spaceId, std::string name, bool ifExists = false);

folly::Future<StatusOr<cpp2::EdgeIndexItem>>
getEdgeIndex(GraphSpaceID spaceId, std::string name);
Expand Down
8 changes: 6 additions & 2 deletions src/meta/processors/indexMan/DropEdgeIndexProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ void DropEdgeIndexProcessor::process(const cpp2::DropEdgeIndexReq& req) {

auto edgeIndexID = getEdgeIndexID(spaceID, indexName);
if (!edgeIndexID.ok()) {
LOG(ERROR) << "Edge Index not exist Space: " << spaceID << " Index name: " << indexName;
resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND);
LOG(ERROR) << "Edge Index not exists in Space: " << spaceID << " Index name: " << indexName;
if (req.get_if_exists()) {
resp_.set_code(cpp2::ErrorCode::SUCCEEDED);
} else {
resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND);
}
onFinished();
return;
}
Expand Down
8 changes: 6 additions & 2 deletions src/meta/processors/indexMan/DropTagIndexProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ void DropTagIndexProcessor::process(const cpp2::DropTagIndexReq& req) {

auto tagIndexID = getTagIndexID(spaceID, indexName);
if (!tagIndexID.ok()) {
LOG(ERROR) << "Tag Index not exist Space: " << spaceID << " Index name: " << indexName;
resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND);
LOG(ERROR) << "Tag Index not exists in Space: " << spaceID << " Index name: " << indexName;
if (req.get_if_exists()) {
resp_.set_code(cpp2::ErrorCode::SUCCEEDED);
} else {
resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND);
}
onFinished();
return;
}
Expand Down
12 changes: 6 additions & 6 deletions src/parser/MaintainSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ class DescribeEdgeSentence final : public Sentence {

class DropTagSentence final : public DropSentence {
public:
explicit DropTagSentence(std::string *name, bool ifExist) : DropSentence(ifExist) {
explicit DropTagSentence(std::string *name, bool ifExists) : DropSentence(ifExists) {
name_.reset(name);
kind_ = Kind::kDropTag;
}
Expand All @@ -495,7 +495,7 @@ class DropTagSentence final : public DropSentence {

class DropEdgeSentence final : public DropSentence {
public:
explicit DropEdgeSentence(std::string *name, bool ifExist) : DropSentence(ifExist) {
explicit DropEdgeSentence(std::string *name, bool ifExists) : DropSentence(ifExists) {
name_.reset(name);
kind_ = Kind::kDropEdge;
}
Expand Down Expand Up @@ -625,9 +625,9 @@ class DescribeEdgeIndexSentence final : public Sentence {
};


class DropTagIndexSentence final : public Sentence {
class DropTagIndexSentence final : public DropSentence {
public:
explicit DropTagIndexSentence(std::string *indexName) {
explicit DropTagIndexSentence(std::string *indexName, bool ifExists) : DropSentence(ifExists) {
indexName_.reset(indexName);
kind_ = Kind::kDropTagIndex;
}
Expand All @@ -643,9 +643,9 @@ class DropTagIndexSentence final : public Sentence {
};


class DropEdgeIndexSentence final : public Sentence {
class DropEdgeIndexSentence final : public DropSentence {
public:
explicit DropEdgeIndexSentence(std::string *indexName) {
explicit DropEdgeIndexSentence(std::string *indexName, bool ifExists) : DropSentence(ifExists) {
indexName_.reset(indexName);
kind_ = Kind::kDropEdgeIndex;
}
Expand Down
8 changes: 4 additions & 4 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -1180,14 +1180,14 @@ create_edge_index_sentence
;

drop_tag_index_sentence
: KW_DROP KW_TAG KW_INDEX name_label {
$$ = new DropTagIndexSentence($4);
: KW_DROP KW_TAG KW_INDEX opt_if_exists name_label {
$$ = new DropTagIndexSentence($5, $4);
}
;

drop_edge_index_sentence
: KW_DROP KW_EDGE KW_INDEX name_label {
$$ = new DropEdgeIndexSentence($4);
: KW_DROP KW_EDGE KW_INDEX opt_if_exists name_label {
$$ = new DropEdgeIndexSentence($5, $4);
}
;

Expand Down