Skip to content

Commit

Permalink
Fix the same name tag and edge in same space vesoft-inc#598
Browse files Browse the repository at this point in the history
  • Loading branch information
laura-ding committed Jul 18, 2019
1 parent 55a2331 commit 2b86780
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 13 deletions.
23 changes: 12 additions & 11 deletions src/interface/meta.thrift
Expand Up @@ -11,23 +11,24 @@ namespace go nebula.meta
include "common.thrift"

enum ErrorCode {
SUCCEEDED = 0,
SUCCEEDED = 0,

// RPC Failure
E_DISCONNECTED = -1,
E_FAIL_TO_CONNECT = -2,
E_RPC_FAILURE = -3,
E_DISCONNECTED = -1,
E_FAIL_TO_CONNECT = -2,
E_RPC_FAILURE = -3,

E_LEADER_CHANGED = -11,
E_LEADER_CHANGED = -11,

// Operation Failure
E_NO_HOSTS = -21,
E_EXISTED = -22,
E_NOT_FOUND = -23,
E_INVALID_HOST = -24,
E_UNSUPPORTED = -25,
E_NOT_DROP = -26,
E_NO_HOSTS = -21,
E_EXISTED = -22,
E_NOT_FOUND = -23,
E_INVALID_HOST = -24,
E_UNSUPPORTED = -25,
E_NOT_DROP = -26,
E_BALANCER_RUNNING = -27,
E_CONFLICT = -28,

// KV Failure
E_STORE_FAILURE = -31,
Expand Down
2 changes: 2 additions & 0 deletions src/meta/client/MetaClient.cpp
Expand Up @@ -306,6 +306,8 @@ Status MetaClient::handleResponse(const RESP& resp) {
return Status::Error("existed!");
case cpp2::ErrorCode::E_NOT_FOUND:
return Status::Error("not existed!");
case cpp2::ErrorCode::E_CONFLICT:
return Status::Error("conflict!");
case cpp2::ErrorCode::E_LEADER_CHANGED: {
HostAddr leader(resp.get_leader().get_ip(), resp.get_leader().get_port());
{
Expand Down
11 changes: 11 additions & 0 deletions src/meta/processors/schemaMan/CreateEdgeProcessor.cpp
Expand Up @@ -19,6 +19,17 @@ void CreateEdgeProcessor::process(const cpp2::CreateEdgeReq& req) {
onFinished();
return;
}
{
folly::SharedMutex::ReadHolder rHolder(LockUtils::tagLock());
auto conflictRet = getTagId(req.get_space_id(), req.get_edge_name());
if (conflictRet.ok()) {
LOG(ERROR) << "Create Edge Failed :" << req.get_edge_name() << " has same name tag";
resp_.set_id(to(conflictRet.value(), EntryType::EDGE));
resp_.set_code(cpp2::ErrorCode::E_CONFLICT);
onFinished();
return;
}
}
std::vector<kvstore::KV> data;
EdgeType edgeType = autoIncrementId();
data.emplace_back(MetaServiceUtils::indexEdgeKey(req.get_space_id(), req.get_edge_name()),
Expand Down
16 changes: 14 additions & 2 deletions src/meta/processors/schemaMan/CreateTagProcessor.cpp
Expand Up @@ -13,15 +13,27 @@ void CreateTagProcessor::process(const cpp2::CreateTagReq& req) {
CHECK_SPACE_ID_AND_RETURN(req.get_space_id());
folly::SharedMutex::WriteHolder wHolder(LockUtils::tagLock());
auto ret = getTagId(req.get_space_id(), req.get_tag_name());
std::vector<kvstore::KV> data;
if (ret.ok()) {
LOG(ERROR) << "Create Tag Failed :" << req.get_tag_name() << " have existed";
LOG(ERROR) << "Create Tag Failed :" << req.get_tag_name() << " has existed";
resp_.set_id(to(ret.value(), EntryType::TAG));
resp_.set_code(cpp2::ErrorCode::E_EXISTED);
onFinished();
return;
}
{
// if there is an edge of the same name
folly::SharedMutex::ReadHolder rHolder(LockUtils::edgeLock());
auto conflictRet = getEdgeType(req.get_space_id(), req.get_tag_name());
if (conflictRet.ok()) {
LOG(ERROR) << "Create Tag Failed :" << req.get_tag_name() << " has same name edge";
resp_.set_id(to(conflictRet.value(), EntryType::TAG));
resp_.set_code(cpp2::ErrorCode::E_CONFLICT);
onFinished();
return;
}
}
TagID tagId = autoIncrementId();
std::vector<kvstore::KV> data;
data.emplace_back(MetaServiceUtils::indexTagKey(req.get_space_id(), req.get_tag_name()),
std::string(reinterpret_cast<const char*>(&tagId), sizeof(tagId)));
LOG(INFO) << "Create Tag " << req.get_tag_name() << ", tagId " << tagId;
Expand Down
24 changes: 24 additions & 0 deletions src/meta/test/ProcessorTest.cpp
Expand Up @@ -361,6 +361,18 @@ TEST(ProcessorTest, CreateTagTest) {
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, resp.code);
ASSERT_EQ(4, resp.get_id().get_tag_id());
}
{
// Create same name edge in same spaces
cpp2::CreateEdgeReq req;
req.set_space_id(1);
req.set_edge_name("default_tag");
req.set_schema(schema);
auto* processor = CreateEdgeProcessor::instance(kv.get());
auto f = processor->getFuture();
processor->process(req);
auto resp = std::move(f).get();
ASSERT_EQ(cpp2::ErrorCode::E_CONFLICT, resp.code);
}

// Set schema ttl property
nebula::cpp2::SchemaProp schemaProp;
Expand Down Expand Up @@ -475,6 +487,18 @@ TEST(ProcessorTest, CreateEdgeTest) {
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, resp.code);
ASSERT_EQ(4, resp.get_id().get_edge_type());
}
{
// Create same name tag in same spaces
cpp2::CreateTagReq req;
req.set_space_id(1);
req.set_tag_name("default_edge");
req.set_schema(schema);
auto* processor = CreateTagProcessor::instance(kv.get());
auto f = processor->getFuture();
processor->process(req);
auto resp = std::move(f).get();
ASSERT_EQ(cpp2::ErrorCode::E_CONFLICT, resp.code);
}

// Set schema ttl property
nebula::cpp2::SchemaProp schemaProp;
Expand Down

0 comments on commit 2b86780

Please sign in to comment.