-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AlterEdgeProcessor, GetEdgeProcessor, RemoveEdgeProcessor and UTs (…
…#346) * add AlterEdgeProcessor, GetEdgeProcessor, RemoveEdgeProcessor * address dangleptr's comment * rebase master modify SET to CHANGE * fix UT
- Loading branch information
1 parent
c5ca970
commit 166e434
Showing
25 changed files
with
835 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved | ||
* | ||
* This source code is licensed under Apache 2.0 License | ||
* (found in the LICENSE.Apache file in the root directory) | ||
*/ | ||
|
||
#include "meta/processors/AlterEdgeProcessor.h" | ||
#include "time/TimeUtils.h" | ||
|
||
namespace nebula { | ||
namespace meta { | ||
|
||
void AlterEdgeProcessor::process(const cpp2::AlterEdgeReq& req) { | ||
if (spaceExist(req.get_space_id()) == Status::SpaceNotFound()) { | ||
resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); | ||
onFinished(); | ||
return; | ||
} | ||
folly::SharedMutex::WriteHolder wHolder(LockUtils::edgeLock()); | ||
auto ret = getEdgeType(req.get_space_id(), req.get_edge_name()); | ||
if (!ret.ok()) { | ||
resp_.set_code(to(ret.status())); | ||
onFinished(); | ||
return; | ||
} | ||
auto edgeType = ret.value(); | ||
|
||
// Check the edge belongs to the space | ||
std::unique_ptr<kvstore::KVIterator> iter; | ||
auto edgePrefix = MetaServiceUtils::schemaEdgePrefix(req.get_space_id(), edgeType); | ||
auto code = kvstore_->prefix(kDefaultSpaceId_, kDefaultPartId_, edgePrefix, &iter); | ||
if (code != kvstore::ResultCode::SUCCEEDED || !iter->valid()) { | ||
LOG(WARNING) << "Edge could not be found " << req.get_edge_name() | ||
<< ", spaceId " << req.get_space_id() << ", edgeType " << edgeType; | ||
resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); | ||
onFinished(); | ||
return; | ||
} | ||
|
||
// Get lasted version of edge | ||
auto version = MetaServiceUtils::parseEdgeVersion(iter->key()) + 1; | ||
auto schema = MetaServiceUtils::parseSchema(iter->val()); | ||
auto columns = schema.get_columns(); | ||
auto& edgeItems = req.get_edge_items(); | ||
for (auto& edgeItem : edgeItems) { | ||
auto& cols = edgeItem.get_schema().get_columns(); | ||
for (auto& col : cols) { | ||
auto retCode = MetaServiceUtils::alterColumnDefs(columns, col, edgeItem.op); | ||
if (retCode != cpp2::ErrorCode::SUCCEEDED) { | ||
LOG(WARNING) << "Alter edge error " << static_cast<int32_t>(retCode); | ||
resp_.set_code(retCode); | ||
onFinished(); | ||
return; | ||
} | ||
} | ||
} | ||
schema.set_columns(std::move(columns)); | ||
std::vector<kvstore::KV> data; | ||
LOG(INFO) << "Alter edge " << req.get_edge_name() << ", edgeTye " << edgeType; | ||
data.emplace_back(MetaServiceUtils::schemaEdgeKey(req.get_space_id(), edgeType, version), | ||
MetaServiceUtils::schemaEdgeVal(req.get_edge_name(), schema)); | ||
resp_.set_code(cpp2::ErrorCode::SUCCEEDED); | ||
resp_.set_id(to(edgeType, EntryType::EDGE)); | ||
doPut(std::move(data)); | ||
} | ||
|
||
} // namespace meta | ||
} // namespace nebula | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved | ||
* | ||
* This source code is licensed under Apache 2.0 License | ||
* (found in the LICENSE.Apache file in the root directory) | ||
*/ | ||
|
||
#ifndef META_ALTEREDGEPROCESSOR_H_ | ||
#define META_ALTEREDGEPROCESSOR_H_ | ||
|
||
#include "meta/processors/BaseProcessor.h" | ||
|
||
namespace nebula { | ||
namespace meta { | ||
|
||
class AlterEdgeProcessor : public BaseProcessor<cpp2::ExecResp> { | ||
public: | ||
static AlterEdgeProcessor* instance(kvstore::KVStore* kvstore) { | ||
return new AlterEdgeProcessor(kvstore); | ||
} | ||
|
||
void process(const cpp2::AlterEdgeReq& req); | ||
|
||
private: | ||
explicit AlterEdgeProcessor(kvstore::KVStore* kvstore) | ||
: BaseProcessor<cpp2::ExecResp>(kvstore) {} | ||
}; | ||
|
||
} // namespace meta | ||
} // namespace nebula | ||
#endif // META_ALTEREDGEPROCESSOR_H_ | ||
|
Oops, something went wrong.