forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateTagProcessor.cpp
48 lines (44 loc) · 1.95 KB
/
CreateTagProcessor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Copyright (c) 2018 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
#include "meta/processors/schemaMan/CreateTagProcessor.h"
namespace nebula {
namespace meta {
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());
if (ret.ok()) {
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;
data.emplace_back(MetaServiceUtils::schemaTagKey(req.get_space_id(), tagId, 0),
MetaServiceUtils::schemaTagVal(req.get_tag_name(), req.get_schema()));
resp_.set_code(cpp2::ErrorCode::SUCCEEDED);
resp_.set_id(to(tagId, EntryType::TAG));
doPut(std::move(data));
}
} // namespace meta
} // namespace nebula