From b667a7f7c959afce72745658d7e20b97263b65e7 Mon Sep 17 00:00:00 2001 From: Jun Date: Mon, 25 Oct 2021 14:29:57 +0800 Subject: [PATCH 01/15] refactor: use std::any instead of boost::any Signed-off-by: Jun --- src/codec/NebulaCodecImpl.cpp | 12 +++++----- src/codec/include/NebulaCodec.h | 2 +- src/codec/test/NebulaCodecTest.cpp | 28 ++++++++++++------------ src/common/base/Base.h | 2 +- src/kvstore/plugins/hbase/HBaseStore.cpp | 12 +++++----- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/codec/NebulaCodecImpl.cpp b/src/codec/NebulaCodecImpl.cpp index 71bf136efbd..708885c5a7c 100644 --- a/src/codec/NebulaCodecImpl.cpp +++ b/src/codec/NebulaCodecImpl.cpp @@ -28,17 +28,17 @@ std::string NebulaCodecImpl::encode(std::vector values, RowWriter writer(schema); for (auto& value : values) { if (value.type() == typeid(int32_t)) { - writer << boost::any_cast(value); + writer << std::any_cast(value); } else if (value.type() == typeid(int64_t)) { - writer << boost::any_cast(value); + writer << std::any_cast(value); } else if (value.type() == typeid(std::string)) { - writer << boost::any_cast(value); + writer << std::any_cast(value); } else if (value.type() == typeid(double)) { - writer << boost::any_cast(value); + writer << std::any_cast(value); } else if (value.type() == typeid(float)) { - writer << boost::any_cast(value); + writer << std::any_cast(value); } else if (value.type() == typeid(bool)) { - writer << boost::any_cast(value); + writer << std::any_cast(value); } else { LOG(ERROR) << "Value Type :" << value.type().name() << std::endl; } diff --git a/src/codec/include/NebulaCodec.h b/src/codec/include/NebulaCodec.h index 2fa20fe51d0..4679fbf898c 100644 --- a/src/codec/include/NebulaCodec.h +++ b/src/codec/include/NebulaCodec.h @@ -13,7 +13,7 @@ namespace nebula { class NebulaCodec { public: - typedef boost::any Value; + using Value = std::any; virtual ~NebulaCodec() = default; diff --git a/src/codec/test/NebulaCodecTest.cpp b/src/codec/test/NebulaCodecTest.cpp index 7637b15f41b..876e3e9a861 100644 --- a/src/codec/test/NebulaCodecTest.cpp +++ b/src/codec/test/NebulaCodecTest.cpp @@ -7,25 +7,25 @@ #include #include "codec/NebulaCodecImpl.h" -#include "codec/RowReaderWrapper" +#include "codec/RowReaderWrapper.h" #include "codec/test/SchemaWriter.h" #include "common/base/Base.h" namespace nebula { TEST(NebulaCodec, encode) { - std::vector v; + std::vector v; v.emplace_back(1); v.emplace_back(false); v.emplace_back(3.14F); v.emplace_back(3.14); v.emplace_back(std::string("hi")); - EXPECT_EQ(boost::any_cast(v[0]), 1); - EXPECT_EQ(boost::any_cast(v[1]), false); - EXPECT_EQ(boost::any_cast(v[2]), 3.14F); - EXPECT_EQ(boost::any_cast(v[3]), 3.14); - EXPECT_EQ(boost::any_cast(v[4]), "hi"); + EXPECT_EQ(std::any_cast(v[0]), 1); + EXPECT_EQ(std::any_cast(v[1]), false); + EXPECT_EQ(std::any_cast(v[2]), 3.14F); + EXPECT_EQ(std::any_cast(v[3]), 3.14); + EXPECT_EQ(std::any_cast(v[4]), "hi"); SchemaWriter schemaWriter; schemaWriter.appendCol("i_field", cpp2::SupportedType::INT); @@ -82,7 +82,7 @@ TEST(NebulaCodec, encode) { EXPECT_EQ("hi", sVal.toString()); // check empty values - std::vector emptyV; + std::vector emptyV; std::string emptyEncoded = codec.encode(emptyV); SchemaWriter emptyWriter; @@ -134,12 +134,12 @@ TEST(NebulaCodec, decode) { NebulaCodecImpl codec; auto result = codec.decode(encoded, schema); - EXPECT_TRUE(boost::any_cast(result.value()["b_field"])); - EXPECT_EQ(boost::any_cast(result.value()["i_field"]), 64); - EXPECT_EQ(boost::any_cast(result.value()["v_field"]), 0x1122334455667788L); - EXPECT_EQ(boost::any_cast(result.value()["f_field"]), 3.14F); - EXPECT_EQ(boost::any_cast(result.value()["d_field"]), 2.718); - EXPECT_EQ(boost::any_cast(result.value()["s_field"]), "Hello World!"); + EXPECT_TRUE(std::any_cast(result.value()["b_field"])); + EXPECT_EQ(std::any_cast(result.value()["i_field"]), 64); + EXPECT_EQ(std::any_cast(result.value()["v_field"]), 0x1122334455667788L); + EXPECT_EQ(std::any_cast(result.value()["f_field"]), 3.14F); + EXPECT_EQ(std::any_cast(result.value()["d_field"]), 2.718); + EXPECT_EQ(std::any_cast(result.value()["s_field"]), "Hello World!"); // check empty encoded string auto empty_encoded = codec.decode("", schema); diff --git a/src/common/base/Base.h b/src/common/base/Base.h index aabff0e7b09..5f3e2b6bfac 100644 --- a/src/common/base/Base.h +++ b/src/common/base/Base.h @@ -17,8 +17,8 @@ #include #include +#include #include -#include #include #include #include diff --git a/src/kvstore/plugins/hbase/HBaseStore.cpp b/src/kvstore/plugins/hbase/HBaseStore.cpp index 57e8f7c5c21..3583b89bc0c 100644 --- a/src/kvstore/plugins/hbase/HBaseStore.cpp +++ b/src/kvstore/plugins/hbase/HBaseStore.cpp @@ -124,17 +124,17 @@ std::vector HBaseStore::decode(GraphSpaceID spaceId, NebulaCodec::Value anyValue = result[fieldName]; std::string value; if (anyValue.type() == typeid(int32_t)) { - value = folly::to(boost::any_cast(anyValue)); + value = folly::to(std::any_cast(anyValue)); } else if (anyValue.type() == typeid(std::string)) { - value = folly::to(boost::any_cast(anyValue)); + value = folly::to(std::any_cast(anyValue)); } else if (anyValue.type() == typeid(int64_t)) { - value = folly::to(boost::any_cast(anyValue)); + value = folly::to(std::any_cast(anyValue)); } else if (anyValue.type() == typeid(float)) { - value = folly::to(boost::any_cast(anyValue)); + value = folly::to(std::any_cast(anyValue)); } else if (anyValue.type() == typeid(double)) { - value = folly::to(boost::any_cast(anyValue)); + value = folly::to(std::any_cast(anyValue)); } else if (anyValue.type() == typeid(bool)) { - value = folly::to(boost::any_cast(anyValue)); + value = folly::to(std::any_cast(anyValue)); } else { LOG(ERROR) << "Value Type :" << anyValue.type().name() << std::endl; } From f1148aab528f84f8cb9e949f4166842b930d6a2a Mon Sep 17 00:00:00 2001 From: Jun Date: Mon, 25 Oct 2021 14:38:57 +0800 Subject: [PATCH 02/15] refactor: use std::variant instead of boost::variant Signed-off-by: Jun --- src/common/base/Base.h | 4 ++-- src/parser/AdminSentences.h | 2 +- src/parser/MaintainSentences.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/base/Base.h b/src/common/base/Base.h index 5f3e2b6bfac..46a94cb8b0b 100644 --- a/src/common/base/Base.h +++ b/src/common/base/Base.h @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -48,6 +47,7 @@ #include #include #include +#include #include #if defined(__clang__) && defined(__aarch64__) @@ -108,7 +108,7 @@ namespace nebula { -using VariantType = boost::variant; +using VariantType = std::variant; #ifndef VAR_INT64 #define VAR_INT64 0 diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h index 328414bbf67..1f88385781e 100644 --- a/src/parser/AdminSentences.h +++ b/src/parser/AdminSentences.h @@ -128,7 +128,7 @@ class ShowZonesSentence final : public Sentence { class SpaceOptItem final { public: - using Value = boost::variant; + using Value = std::variant; enum OptionType : uint8_t { PARTITION_NUM, diff --git a/src/parser/MaintainSentences.h b/src/parser/MaintainSentences.h index 603e52cba30..e78e78855cc 100644 --- a/src/parser/MaintainSentences.h +++ b/src/parser/MaintainSentences.h @@ -165,7 +165,7 @@ class ColumnNameList final { class SchemaPropItem final { public: - using Value = boost::variant; + using Value = std::variant; enum PropType : uint8_t { TTL_DURATION, TTL_COL, COMMENT }; From f3820991d7d352e768c5ed0509ba2cc4a75b035d Mon Sep 17 00:00:00 2001 From: Jun Date: Mon, 25 Oct 2021 14:48:50 +0800 Subject: [PATCH 03/15] refactor: use std::optional instead of folly::optional Signed-off-by: Jun --- src/clients/storage/InternalStorageClient.cpp | 6 +++--- src/clients/storage/InternalStorageClient.h | 6 +++--- src/kvstore/raftex/RaftPart.cpp | 8 ++++---- src/kvstore/raftex/RaftPart.h | 2 +- src/kvstore/raftex/test/TestShard.cpp | 2 +- src/kvstore/raftex/test/TestShard.h | 2 +- src/meta/ActiveHostsMan.h | 2 +- src/meta/processors/admin/AdminClient.h | 2 +- src/meta/processors/job/JobUtils.h | 2 +- src/storage/admin/AdminTaskManager.cpp | 2 +- src/storage/exec/EdgeNode.h | 2 +- src/storage/exec/QueryUtils.h | 12 ++++++------ src/storage/exec/StorageIterator.h | 2 +- src/storage/exec/TagNode.h | 2 +- src/storage/exec/UpdateNode.h | 8 ++++---- src/storage/mutate/AddEdgesProcessor.h | 2 +- src/storage/mutate/UpdateEdgeProcessor.h | 4 ++-- src/storage/test/AdminTaskManagerTest.cpp | 2 +- src/storage/test/ChainTestUtils.h | 16 ++++++++-------- .../transaction/ChainAddEdgesProcessorLocal.h | 2 +- .../transaction/ChainUpdateEdgeProcessorLocal.h | 2 +- 21 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/clients/storage/InternalStorageClient.cpp b/src/clients/storage/InternalStorageClient.cpp index 00ef000c4fc..714dbb5cbea 100644 --- a/src/clients/storage/InternalStorageClient.cpp +++ b/src/clients/storage/InternalStorageClient.cpp @@ -39,7 +39,7 @@ ::nebula::cpp2::ErrorCode getErrorCode(T& tryResp) { void InternalStorageClient::chainUpdateEdge(cpp2::UpdateEdgeRequest& reversedRequest, TermID termOfSrc, - folly::Optional optVersion, + std::optional optVersion, folly::Promise<::nebula::cpp2::ErrorCode>&& p, folly::EventBase* evb) { auto spaceId = reversedRequest.get_space_id(); @@ -82,7 +82,7 @@ void InternalStorageClient::chainUpdateEdge(cpp2::UpdateEdgeRequest& reversedReq void InternalStorageClient::chainAddEdges(cpp2::AddEdgesRequest& directReq, TermID termId, - folly::Optional optVersion, + std::optional optVersion, folly::Promise&& p, folly::EventBase* evb) { auto spaceId = directReq.get_space_id(); @@ -119,7 +119,7 @@ void InternalStorageClient::chainAddEdges(cpp2::AddEdgesRequest& directReq, cpp2::ChainAddEdgesRequest InternalStorageClient::makeChainAddReq(const cpp2::AddEdgesRequest& req, TermID termId, - folly::Optional ver) { + std::optional ver) { cpp2::ChainAddEdgesRequest ret; ret.set_space_id(req.get_space_id()); ret.set_parts(req.get_parts()); diff --git a/src/clients/storage/InternalStorageClient.h b/src/clients/storage/InternalStorageClient.h index 6ef772cb4f5..1303a14bd99 100644 --- a/src/clients/storage/InternalStorageClient.h +++ b/src/clients/storage/InternalStorageClient.h @@ -33,20 +33,20 @@ class InternalStorageClient : public StorageClientBase optVersion, + std::optional optVersion, folly::Promise<::nebula::cpp2::ErrorCode>&& p, folly::EventBase* evb = nullptr); virtual void chainAddEdges(cpp2::AddEdgesRequest& req, TermID termId, - folly::Optional optVersion, + std::optional optVersion, folly::Promise<::nebula::cpp2::ErrorCode>&& p, folly::EventBase* evb = nullptr); private: cpp2::ChainAddEdgesRequest makeChainAddReq(const cpp2::AddEdgesRequest& req, TermID termId, - folly::Optional optVersion); + std::optional optVersion); }; } // namespace storage diff --git a/src/kvstore/raftex/RaftPart.cpp b/src/kvstore/raftex/RaftPart.cpp index f98e1978994..e9285f82697 100644 --- a/src/kvstore/raftex/RaftPart.cpp +++ b/src/kvstore/raftex/RaftPart.cpp @@ -46,7 +46,7 @@ using nebula::wal::FileBasedWal; using nebula::wal::FileBasedWalInfo; using nebula::wal::FileBasedWalPolicy; -using OpProcessor = folly::Function(AtomicOp op)>; +using OpProcessor = folly::Function(AtomicOp op)>; class AppendLogsIterator final : public LogIterator { public: @@ -171,7 +171,7 @@ class AppendLogsIterator final : public LogIterator { bool valid_{true}; LogType lastLogType_{LogType::NORMAL}; LogType currLogType_{LogType::NORMAL}; - folly::Optional opResult_; + std::optional opResult_; LogID firstLogId_; TermID termId_; LogID logId_; @@ -674,7 +674,7 @@ folly::Future RaftPart::appendLogAsync(ClusterID source, AppendLogsIterator it(firstId, termId, std::move(swappedOutLogs), - [this](AtomicOp opCB) -> folly::Optional { + [this](AtomicOp opCB) -> std::optional { CHECK(opCB != nullptr); auto opRet = opCB(); if (!opRet.hasValue()) { @@ -913,7 +913,7 @@ void RaftPart::processAppendLogResponses(const AppendLogResponses& resps, firstLogId, currTerm, std::move(logs_), - [this](AtomicOp op) -> folly::Optional { + [this](AtomicOp op) -> std::optional { auto opRet = op(); if (!opRet.hasValue()) { // Failed diff --git a/src/kvstore/raftex/RaftPart.h b/src/kvstore/raftex/RaftPart.h index 9d3505626f0..d4ff76f6946 100644 --- a/src/kvstore/raftex/RaftPart.h +++ b/src/kvstore/raftex/RaftPart.h @@ -72,7 +72,7 @@ class AppendLogsIterator; * should be applied atomically. You could implement CAS, READ-MODIFY-WRITE * operations though it. * */ -using AtomicOp = folly::Function(void)>; +using AtomicOp = folly::Function(void)>; class RaftPart : public std::enable_shared_from_this { friend class AppendLogsIterator; diff --git a/src/kvstore/raftex/test/TestShard.cpp b/src/kvstore/raftex/test/TestShard.cpp index ec24b716b03..4d091e6979a 100644 --- a/src/kvstore/raftex/test/TestShard.cpp +++ b/src/kvstore/raftex/test/TestShard.cpp @@ -52,7 +52,7 @@ HostAddr decodeLearner(const folly::StringPiece& log) { return deserializeHostAddr(rawlog); } -folly::Optional compareAndSet(const std::string& log) { +std::optional compareAndSet(const std::string& log) { switch (log[0]) { case 'T': return log.substr(1); diff --git a/src/kvstore/raftex/test/TestShard.h b/src/kvstore/raftex/test/TestShard.h index 13bc27fd619..e6a83f52eb7 100644 --- a/src/kvstore/raftex/test/TestShard.h +++ b/src/kvstore/raftex/test/TestShard.h @@ -28,7 +28,7 @@ std::string encodeLearner(const HostAddr& addr); HostAddr decodeLearner(const folly::StringPiece& log); -folly::Optional compareAndSet(const std::string& log); +std::optional compareAndSet(const std::string& log); std::string encodeTransferLeader(const HostAddr& addr); diff --git a/src/meta/ActiveHostsMan.h b/src/meta/ActiveHostsMan.h index 0f2ec18f7f0..b8e1b88765a 100644 --- a/src/meta/ActiveHostsMan.h +++ b/src/meta/ActiveHostsMan.h @@ -35,7 +35,7 @@ struct HostInfo { cpp2::HostRole role_{cpp2::HostRole::UNKNOWN}; std::string gitInfoSha_; // version of binary - folly::Optional version_; + std::optional version_; static HostInfo decode(const folly::StringPiece& data) { if (data.size() == sizeof(int64_t)) { diff --git a/src/meta/processors/admin/AdminClient.h b/src/meta/processors/admin/AdminClient.h index 61ae5157f22..d0ff7272e7b 100644 --- a/src/meta/processors/admin/AdminClient.h +++ b/src/meta/processors/admin/AdminClient.h @@ -21,7 +21,7 @@ namespace meta { using HostLeaderMap = std::unordered_map>>; -using HandleResultOpt = folly::Optional>; +using HandleResultOpt = std::optional>; static const HostAddr kRandomPeer("", 0); diff --git a/src/meta/processors/job/JobUtils.h b/src/meta/processors/job/JobUtils.h index 317ce9290b0..fe07b21c0e6 100644 --- a/src/meta/processors/job/JobUtils.h +++ b/src/meta/processors/job/JobUtils.h @@ -7,11 +7,11 @@ #ifndef META_JOBUTIL_H_ #define META_JOBUTIL_H_ -#include #include #include #include +#include #include #include #include diff --git a/src/storage/admin/AdminTaskManager.cpp b/src/storage/admin/AdminTaskManager.cpp index d93bf6cdf7c..d9028178aea 100644 --- a/src/storage/admin/AdminTaskManager.cpp +++ b/src/storage/admin/AdminTaskManager.cpp @@ -230,7 +230,7 @@ void AdminTaskManager::schedule() { std::chrono::milliseconds interval{20}; // 20ms while (!shutdown_.load(std::memory_order_acquire)) { LOG(INFO) << "waiting for incoming task"; - folly::Optional optTaskHandle{folly::none}; + std::optional optTaskHandle{folly::none}; while (!optTaskHandle && !shutdown_.load(std::memory_order_acquire)) { optTaskHandle = taskQueue_.try_take_for(interval); } diff --git a/src/storage/exec/EdgeNode.h b/src/storage/exec/EdgeNode.h index e368f550c3d..71258df0a6e 100644 --- a/src/storage/exec/EdgeNode.h +++ b/src/storage/exec/EdgeNode.h @@ -65,7 +65,7 @@ class EdgeNode : public IterateNode { Expression* exp_; const std::vector>* schemas_ = nullptr; - folly::Optional> ttl_; + std::optional> ttl_; std::string edgeName_; }; diff --git a/src/storage/exec/QueryUtils.h b/src/storage/exec/QueryUtils.h index 9b42303f841..6af5e980ecd 100644 --- a/src/storage/exec/QueryUtils.h +++ b/src/storage/exec/QueryUtils.h @@ -198,9 +198,9 @@ class QueryUtils final { } // return none if no valid ttl, else return the ttl property name and time - static folly::Optional> getEdgeTTLInfo(EdgeContext* edgeContext, - EdgeType edgeType) { - folly::Optional> ret; + static std::optional> getEdgeTTLInfo(EdgeContext* edgeContext, + EdgeType edgeType) { + std::optional> ret; auto edgeFound = edgeContext->ttlInfo_.find(std::abs(edgeType)); if (edgeFound != edgeContext->ttlInfo_.end()) { ret.emplace(edgeFound->second.first, edgeFound->second.second); @@ -209,9 +209,9 @@ class QueryUtils final { } // return none if no valid ttl, else return the ttl property name and time - static folly::Optional> getTagTTLInfo(TagContext* tagContext, - TagID tagId) { - folly::Optional> ret; + static std::optional> getTagTTLInfo(TagContext* tagContext, + TagID tagId) { + std::optional> ret; auto tagFound = tagContext->ttlInfo_.find(tagId); if (tagFound != tagContext->ttlInfo_.end()) { ret.emplace(tagFound->second.first, tagFound->second.second); diff --git a/src/storage/exec/StorageIterator.h b/src/storage/exec/StorageIterator.h index e5d281f1d20..d5f141b5d88 100644 --- a/src/storage/exec/StorageIterator.h +++ b/src/storage/exec/StorageIterator.h @@ -40,7 +40,7 @@ class SingleEdgeIterator : public StorageIterator { std::unique_ptr iter, EdgeType edgeType, const std::vector>* schemas, - const folly::Optional>* ttl) + const std::optional>* ttl) : context_(context), iter_(std::move(iter)), edgeType_(edgeType), schemas_(schemas) { CHECK(!!iter_); if (ttl->hasValue()) { diff --git a/src/storage/exec/TagNode.h b/src/storage/exec/TagNode.h index cf8f161bed0..610fba7dae0 100644 --- a/src/storage/exec/TagNode.h +++ b/src/storage/exec/TagNode.h @@ -106,7 +106,7 @@ class TagNode final : public IterateNode { StorageExpressionContext* expCtx_; Expression* exp_; const std::vector>* schemas_ = nullptr; - folly::Optional> ttl_; + std::optional> ttl_; std::string tagName_; bool valid_ = false; diff --git a/src/storage/exec/UpdateNode.h b/src/storage/exec/UpdateNode.h index f36e284c082..86e0fcc54a0 100644 --- a/src/storage/exec/UpdateNode.h +++ b/src/storage/exec/UpdateNode.h @@ -313,7 +313,7 @@ class UpdateTagNode : public UpdateNode { return nebula::cpp2::ErrorCode::SUCCEEDED; } - folly::Optional updateAndWriteBack(const PartitionID partId, const VertexID vId) { + std::optional updateAndWriteBack(const PartitionID partId, const VertexID vId) { ObjectPool pool; for (auto& updateProp : updatedProps_) { auto propName = updateProp.get_name(); @@ -477,7 +477,7 @@ class UpdateEdgeNode : public UpdateNode { return nebula::cpp2::ErrorCode::E_DATA_CONFLICT_ERROR; } - auto op = [&partId, &edgeKey, this]() -> folly::Optional { + auto op = [&partId, &edgeKey, this]() -> std::optional { this->exeResult_ = RelNode::doExecute(partId, edgeKey); if (this->exeResult_ == nebula::cpp2::ErrorCode::SUCCEEDED) { if (*edgeKey.edge_type_ref() != this->edgeType_) { @@ -637,8 +637,8 @@ class UpdateEdgeNode : public UpdateNode { return nebula::cpp2::ErrorCode::SUCCEEDED; } - folly::Optional updateAndWriteBack(const PartitionID partId, - const cpp2::EdgeKey& edgeKey) { + std::optional updateAndWriteBack(const PartitionID partId, + const cpp2::EdgeKey& edgeKey) { ObjectPool pool; for (auto& updateProp : updatedProps_) { auto propName = updateProp.get_name(); diff --git a/src/storage/mutate/AddEdgesProcessor.h b/src/storage/mutate/AddEdgesProcessor.h index ec509cb2f89..1cee9de1349 100644 --- a/src/storage/mutate/AddEdgesProcessor.h +++ b/src/storage/mutate/AddEdgesProcessor.h @@ -55,7 +55,7 @@ class AddEdgesProcessor : public BaseProcessor { /// this is a hook function to keep out-edge and in-edge consist using ConsistOper = std::function*)>; - folly::Optional consistOp_; + std::optional consistOp_; }; } // namespace storage diff --git a/src/storage/mutate/UpdateEdgeProcessor.h b/src/storage/mutate/UpdateEdgeProcessor.h index 5911af3918e..6392a920d94 100644 --- a/src/storage/mutate/UpdateEdgeProcessor.h +++ b/src/storage/mutate/UpdateEdgeProcessor.h @@ -73,8 +73,8 @@ class UpdateEdgeProcessor // update std::vector updatedProps_; - folly::Optional> returnProps_; - folly::Optional condition_; + std::optional> returnProps_; + std::optional condition_; // return props expression std::vector returnPropsExp_; diff --git a/src/storage/test/AdminTaskManagerTest.cpp b/src/storage/test/AdminTaskManagerTest.cpp index eb017750b6b..d573e1b2f74 100644 --- a/src/storage/test/AdminTaskManagerTest.cpp +++ b/src/storage/test/AdminTaskManagerTest.cpp @@ -125,7 +125,7 @@ TEST(TaskManagerTest, component_IOThreadPool) { { int totalTask = 100; - using Para = folly::Optional; + using Para = std::optional; std::mutex mu; int completed = 0; auto pool = std::make_unique(numThreads); diff --git a/src/storage/test/ChainTestUtils.h b/src/storage/test/ChainTestUtils.h index c4ef8a0a222..38f64dbfac5 100644 --- a/src/storage/test/ChainTestUtils.h +++ b/src/storage/test/ChainTestUtils.h @@ -131,11 +131,11 @@ class FakeChainAddEdgesProcessorLocal : public ChainAddEdgesProcessorLocal { return ChainAddEdgesProcessorLocal::reverseRequest(req); } - folly::Optional rcPrepareLocal; + std::optional rcPrepareLocal; - folly::Optional rcProcessRemote; + std::optional rcProcessRemote; - folly::Optional rcProcessLocal; + std::optional rcProcessLocal; }; class FakeChainUpdateProcessor : public ChainUpdateEdgeProcessorLocal { @@ -180,9 +180,9 @@ class FakeChainUpdateProcessor : public ChainUpdateEdgeProcessorLocal { void wrapAddUnfinishedEdge(ResumeType type) { addUnfinishedEdge(type); } public: - folly::Optional rcPrepareLocal; - folly::Optional rcProcessRemote; - folly::Optional rcProcessLocal; + std::optional rcPrepareLocal; + std::optional rcProcessRemote; + std::optional rcProcessLocal; }; class MetaClientTestUpdater { @@ -246,7 +246,7 @@ class FakeInternalStorageClient : public InternalStorageClient { void chainUpdateEdge(cpp2::UpdateEdgeRequest& req, TermID termOfSrc, - folly::Optional optVersion, + std::optional optVersion, folly::Promise&& p, folly::EventBase* evb = nullptr) override { cpp2::ChainUpdateEdgeRequest chainReq; @@ -267,7 +267,7 @@ class FakeInternalStorageClient : public InternalStorageClient { void chainAddEdges(cpp2::AddEdgesRequest& req, TermID termId, - folly::Optional optVersion, + std::optional optVersion, folly::Promise<::nebula::cpp2::ErrorCode>&& p, folly::EventBase* evb = nullptr) override { UNUSED(req); diff --git a/src/storage/transaction/ChainAddEdgesProcessorLocal.h b/src/storage/transaction/ChainAddEdgesProcessorLocal.h index 56dc2873972..18dba5f2389 100644 --- a/src/storage/transaction/ChainAddEdgesProcessorLocal.h +++ b/src/storage/transaction/ChainAddEdgesProcessorLocal.h @@ -141,7 +141,7 @@ class ChainAddEdgesProcessorLocal : public BaseProcessor, std::vector kvErased_; std::vector kvAppend_; - folly::Optional edgeVer_{folly::none}; + std::optional edgeVer_{folly::none}; int64_t resumedEdgeVer_{-1}; std::string uuid_; diff --git a/src/storage/transaction/ChainUpdateEdgeProcessorLocal.h b/src/storage/transaction/ChainUpdateEdgeProcessorLocal.h index c31e395bd3a..89e9c1a573e 100644 --- a/src/storage/transaction/ChainUpdateEdgeProcessorLocal.h +++ b/src/storage/transaction/ChainUpdateEdgeProcessorLocal.h @@ -92,7 +92,7 @@ class ChainUpdateEdgeProcessorLocal bool primeInserted_{false}; std::vector kvErased_; std::vector kvAppend_; - folly::Optional ver_{folly::none}; + std::optional ver_{folly::none}; }; } // namespace storage From f0c312b0fbe64981cc4e8875b005a4c5a8a73722 Mon Sep 17 00:00:00 2001 From: Jun Date: Mon, 25 Oct 2021 14:57:54 +0800 Subject: [PATCH 04/15] refactor: replace folly::none with std::nullopt Signed-off-by: Jun --- src/kvstore/raftex/test/LogCASTest.cpp | 2 +- src/kvstore/raftex/test/TestShard.cpp | 2 +- src/meta/processors/admin/AdminClient.cpp | 2 +- src/meta/processors/admin/AdminClient.h | 2 +- src/meta/processors/job/JobDescription.h | 2 +- src/storage/admin/AdminTaskManager.cpp | 2 +- src/storage/exec/UpdateNode.h | 44 +++++++++---------- src/storage/test/AdminTaskManagerTest.cpp | 2 +- .../transaction/ChainAddEdgesProcessorLocal.h | 2 +- .../ChainUpdateEdgeProcessorLocal.h | 2 +- 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/kvstore/raftex/test/LogCASTest.cpp b/src/kvstore/raftex/test/LogCASTest.cpp index 7a72e660ed0..430ac3bebb7 100644 --- a/src/kvstore/raftex/test/LogCASTest.cpp +++ b/src/kvstore/raftex/test/LogCASTest.cpp @@ -220,7 +220,7 @@ TEST_F(LogCASTest, EmptyTest) { { LOG(INFO) << "return none string for atomic operation!"; folly::Baton<> baton; - leader_->atomicOpAsync([log = std::move(log)]() mutable { return folly::none; }) + leader_->atomicOpAsync([log = std::move(log)]() mutable { return std::nullopt; }) .thenValue([&baton](AppendLogResult res) { ASSERT_EQ(AppendLogResult::E_ATOMIC_OP_FAILURE, res); baton.post(); diff --git a/src/kvstore/raftex/test/TestShard.cpp b/src/kvstore/raftex/test/TestShard.cpp index 4d091e6979a..5f3c3c324b6 100644 --- a/src/kvstore/raftex/test/TestShard.cpp +++ b/src/kvstore/raftex/test/TestShard.cpp @@ -57,7 +57,7 @@ std::optional compareAndSet(const std::string& log) { case 'T': return log.substr(1); default: - return folly::none; + return std::nullopt; } } diff --git a/src/meta/processors/admin/AdminClient.cpp b/src/meta/processors/admin/AdminClient.cpp index cbad41e5646..a3928cad1cd 100644 --- a/src/meta/processors/admin/AdminClient.cpp +++ b/src/meta/processors/admin/AdminClient.cpp @@ -431,7 +431,7 @@ void AdminClient::getResponse(std::vector hosts, auto&& adminResp = std::move(t.value()); if (adminResp.result.get_failed_parts().empty()) { // succeeded - if (respGen != folly::none) { + if (respGen != std::nullopt) { auto val = respGen.value(); val(std::move(adminResp)); } diff --git a/src/meta/processors/admin/AdminClient.h b/src/meta/processors/admin/AdminClient.h index d0ff7272e7b..342d5c1d828 100644 --- a/src/meta/processors/admin/AdminClient.h +++ b/src/meta/processors/admin/AdminClient.h @@ -125,7 +125,7 @@ class AdminClient { int32_t retry, folly::Promise pro, int32_t retryLimit, - HandleResultOpt respGen = folly::none); + HandleResultOpt respGen); void getLeaderDist(const HostAddr& host, folly::Promise>&& pro, diff --git a/src/meta/processors/job/JobDescription.h b/src/meta/processors/job/JobDescription.h index 746e8d69e1a..7e2f1a60b72 100644 --- a/src/meta/processors/job/JobDescription.h +++ b/src/meta/processors/job/JobDescription.h @@ -95,7 +95,7 @@ class JobDescription { bool setStatus(Status newStatus); /* - * get a existed job from kvstore, return folly::none if there isn't + * get a existed job from kvstore, return std::nullopt if there isn't * */ static ErrorOr loadJobDescription( JobID iJob, nebula::kvstore::KVStore* kv); diff --git a/src/storage/admin/AdminTaskManager.cpp b/src/storage/admin/AdminTaskManager.cpp index d9028178aea..a594993c936 100644 --- a/src/storage/admin/AdminTaskManager.cpp +++ b/src/storage/admin/AdminTaskManager.cpp @@ -230,7 +230,7 @@ void AdminTaskManager::schedule() { std::chrono::milliseconds interval{20}; // 20ms while (!shutdown_.load(std::memory_order_acquire)) { LOG(INFO) << "waiting for incoming task"; - std::optional optTaskHandle{folly::none}; + std::optional optTaskHandle{std::nullopt}; while (!optTaskHandle && !shutdown_.load(std::memory_order_acquire)) { optTaskHandle = taskQueue_.try_take_for(interval); } diff --git a/src/storage/exec/UpdateNode.h b/src/storage/exec/UpdateNode.h index 86e0fcc54a0..20d8d98fc94 100644 --- a/src/storage/exec/UpdateNode.h +++ b/src/storage/exec/UpdateNode.h @@ -215,7 +215,7 @@ class UpdateTagNode : public UpdateNode { } auto batch = this->updateAndWriteBack(partId, vId); - if (batch == folly::none) { + if (batch == std::nullopt) { return nebula::cpp2::ErrorCode::E_INVALID_DATA; } @@ -320,7 +320,7 @@ class UpdateTagNode : public UpdateNode { auto updateExp = Expression::decode(&pool, updateProp.get_value()); if (!updateExp) { LOG(ERROR) << "Update expression decode failed " << updateProp.get_value(); - return folly::none; + return std::nullopt; } auto updateVal = updateExp->eval(*expCtx_); // update prop value to props_ @@ -333,7 +333,7 @@ class UpdateTagNode : public UpdateNode { auto wRet = rowWriter_->setValue(e.first, e.second); if (wRet != WriteResult::SUCCEEDED) { LOG(ERROR) << "Add field faild "; - return folly::none; + return std::nullopt; } } @@ -342,7 +342,7 @@ class UpdateTagNode : public UpdateNode { auto wRet = rowWriter_->finish(); if (wRet != WriteResult::SUCCEEDED) { LOG(ERROR) << "Add field faild "; - return folly::none; + return std::nullopt; } auto nVal = rowWriter_->moveEncodedStr(); @@ -360,7 +360,7 @@ class UpdateTagNode : public UpdateNode { if (!val_.empty()) { if (!reader_) { LOG(ERROR) << "Bad format row"; - return folly::none; + return std::nullopt; } auto ois = indexKeys(partId, vId, reader_, index); if (!ois.empty()) { @@ -372,7 +372,7 @@ class UpdateTagNode : public UpdateNode { } } else if (context_->env()->checkIndexLocked(iState)) { LOG(ERROR) << "The index has been locked: " << index->get_index_name(); - return folly::none; + return std::nullopt; } else { for (auto& oi : ois) { batchHolder->remove(std::move(oi)); @@ -388,7 +388,7 @@ class UpdateTagNode : public UpdateNode { } if (!nReader) { LOG(ERROR) << "Bad format row"; - return folly::none; + return std::nullopt; } auto nis = indexKeys(partId, vId, nReader.get(), index); if (!nis.empty()) { @@ -402,7 +402,7 @@ class UpdateTagNode : public UpdateNode { } } else if (context_->env()->checkIndexLocked(indexState)) { LOG(ERROR) << "The index has been locked: " << index->get_index_name(); - return folly::none; + return std::nullopt; } else { for (auto& ni : nis) { batchHolder->put(std::move(ni), std::string(niv)); @@ -482,14 +482,14 @@ class UpdateEdgeNode : public UpdateNode { if (this->exeResult_ == nebula::cpp2::ErrorCode::SUCCEEDED) { if (*edgeKey.edge_type_ref() != this->edgeType_) { this->exeResult_ = nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND; - return folly::none; + return std::nullopt; } if (this->context_->resultStat_ == ResultStatus::ILLEGAL_DATA) { this->exeResult_ = nebula::cpp2::ErrorCode::E_INVALID_DATA; - return folly::none; + return std::nullopt; } else if (this->context_->resultStat_ == ResultStatus::FILTER_OUT) { this->exeResult_ = nebula::cpp2::ErrorCode::E_FILTER_OUT; - return folly::none; + return std::nullopt; } if (filterNode_->valid()) { @@ -508,22 +508,22 @@ class UpdateEdgeNode : public UpdateNode { } if (this->exeResult_ != nebula::cpp2::ErrorCode::SUCCEEDED) { - return folly::none; + return std::nullopt; } auto batch = this->updateAndWriteBack(partId, edgeKey); - if (batch == folly::none) { + if (batch == std::nullopt) { // There is an error in updateAndWriteBack this->exeResult_ = nebula::cpp2::ErrorCode::E_INVALID_DATA; } return batch; } else { // If filter out, StorageExpressionContext is set in filterNode - return folly::none; + return std::nullopt; } }; auto batch = op(); - if (batch == folly::none) { + if (batch == std::nullopt) { return this->exeResult_; } @@ -644,7 +644,7 @@ class UpdateEdgeNode : public UpdateNode { auto propName = updateProp.get_name(); auto updateExp = Expression::decode(&pool, updateProp.get_value()); if (!updateExp) { - return folly::none; + return std::nullopt; } auto updateVal = updateExp->eval(*expCtx_); // update prop value to updateContext_ @@ -657,7 +657,7 @@ class UpdateEdgeNode : public UpdateNode { auto wRet = rowWriter_->setValue(e.first, e.second); if (wRet != WriteResult::SUCCEEDED) { VLOG(1) << "Add field faild "; - return folly::none; + return std::nullopt; } } @@ -666,7 +666,7 @@ class UpdateEdgeNode : public UpdateNode { auto wRet = rowWriter_->finish(); if (wRet != WriteResult::SUCCEEDED) { VLOG(1) << "Add field faild "; - return folly::none; + return std::nullopt; } auto nVal = rowWriter_->moveEncodedStr(); @@ -683,7 +683,7 @@ class UpdateEdgeNode : public UpdateNode { if (!val_.empty()) { if (!reader_) { LOG(ERROR) << "Bad format row"; - return folly::none; + return std::nullopt; } auto ois = indexKeys(partId, reader_, edgeKey, index); if (!ois.empty()) { @@ -695,7 +695,7 @@ class UpdateEdgeNode : public UpdateNode { } } else if (context_->env()->checkIndexLocked(iState)) { LOG(ERROR) << "The index has been locked: " << index->get_index_name(); - return folly::none; + return std::nullopt; } else { for (auto& oi : ois) { batchHolder->remove(std::move(oi)); @@ -711,7 +711,7 @@ class UpdateEdgeNode : public UpdateNode { } if (!nReader) { LOG(ERROR) << "Bad format row"; - return folly::none; + return std::nullopt; } auto niks = indexKeys(partId, nReader.get(), edgeKey, index); if (!niks.empty()) { @@ -725,7 +725,7 @@ class UpdateEdgeNode : public UpdateNode { } } else if (context_->env()->checkIndexLocked(indexState)) { LOG(ERROR) << "The index has been locked: " << index->get_index_name(); - return folly::none; + return std::nullopt; } else { for (auto& nik : niks) { batchHolder->put(std::move(nik), std::string(niv)); diff --git a/src/storage/test/AdminTaskManagerTest.cpp b/src/storage/test/AdminTaskManagerTest.cpp index d573e1b2f74..fcf66f91409 100644 --- a/src/storage/test/AdminTaskManagerTest.cpp +++ b/src/storage/test/AdminTaskManagerTest.cpp @@ -147,7 +147,7 @@ TEST(TaskManagerTest, component_IOThreadPool) { }; for (int i = 0; i < totalTask; ++i) { - pool->add(std::bind(f, folly::none)); + pool->add(std::bind(f, std::nullopt)); } pool->join(); diff --git a/src/storage/transaction/ChainAddEdgesProcessorLocal.h b/src/storage/transaction/ChainAddEdgesProcessorLocal.h index 18dba5f2389..d248cb577b7 100644 --- a/src/storage/transaction/ChainAddEdgesProcessorLocal.h +++ b/src/storage/transaction/ChainAddEdgesProcessorLocal.h @@ -141,7 +141,7 @@ class ChainAddEdgesProcessorLocal : public BaseProcessor, std::vector kvErased_; std::vector kvAppend_; - std::optional edgeVer_{folly::none}; + std::optional edgeVer_; int64_t resumedEdgeVer_{-1}; std::string uuid_; diff --git a/src/storage/transaction/ChainUpdateEdgeProcessorLocal.h b/src/storage/transaction/ChainUpdateEdgeProcessorLocal.h index 89e9c1a573e..80624b57932 100644 --- a/src/storage/transaction/ChainUpdateEdgeProcessorLocal.h +++ b/src/storage/transaction/ChainUpdateEdgeProcessorLocal.h @@ -92,7 +92,7 @@ class ChainUpdateEdgeProcessorLocal bool primeInserted_{false}; std::vector kvErased_; std::vector kvAppend_; - std::optional ver_{folly::none}; + std::optional ver_; }; } // namespace storage From e82e23d1700a7dd17f5dd58082eeb635114ff6d3 Mon Sep 17 00:00:00 2001 From: Jun Date: Mon, 25 Oct 2021 15:20:11 +0800 Subject: [PATCH 05/15] refactor: use std::get instead of boost::get Signed-off-by: Jun --- src/meta/test/ConfigManTest.cpp | 18 ++++++------ src/meta/upgrade/MetaDataUpgrade.cpp | 20 ++++++------- src/parser/AdminSentences.cpp | 10 +++---- src/parser/AdminSentences.h | 6 ++-- src/parser/MaintainSentences.cpp | 6 ++-- src/parser/MaintainSentences.h | 6 ++-- src/storage/test/IndexScanTest.cpp | 28 +++++++++---------- src/storage/test/StorageLookupBenchmark.cpp | 2 +- .../storage-perf/StorageIntegrityTool.cpp | 2 +- 9 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/meta/test/ConfigManTest.cpp b/src/meta/test/ConfigManTest.cpp index 72fa9087550..a7b50d1e613 100644 --- a/src/meta/test/ConfigManTest.cpp +++ b/src/meta/test/ConfigManTest.cpp @@ -346,7 +346,7 @@ TEST(ConfigManTest, MetaConfigManTest) { auto getRet = cfgMan.getConfig(module, name).get(); ASSERT_TRUE(getRet.ok()); auto item = toConfigItem(getRet.value().front()); - auto value = boost::get(item.value_); + auto value = std::get(item.value_); ASSERT_EQ(value, 100); sleep(FLAGS_heartbeat_interval_secs + 1); @@ -366,7 +366,7 @@ TEST(ConfigManTest, MetaConfigManTest) { auto getRet = cfgMan.getConfig(module, name).get(); ASSERT_TRUE(getRet.ok()); auto item = toConfigItem(getRet.value().front()); - auto value = boost::get(item.value_); + auto value = std::get(item.value_); ASSERT_EQ(value, 102); // get from cache @@ -386,7 +386,7 @@ TEST(ConfigManTest, MetaConfigManTest) { auto getRet = cfgMan.getConfig(module, name).get(); ASSERT_TRUE(getRet.ok()); auto item = toConfigItem(getRet.value().front()); - auto value = boost::get(item.value_); + auto value = std::get(item.value_); ASSERT_EQ(value, true); // get from cache @@ -406,7 +406,7 @@ TEST(ConfigManTest, MetaConfigManTest) { auto getRet = cfgMan.getConfig(module, name).get(); ASSERT_TRUE(getRet.ok()); auto item = toConfigItem(getRet.value().front()); - auto value = boost::get(item.value_); + auto value = std::get(item.value_); ASSERT_EQ(value, 3.14); // get from cache @@ -427,7 +427,7 @@ TEST(ConfigManTest, MetaConfigManTest) { auto getRet = cfgMan.getConfig(module, name).get(); ASSERT_TRUE(getRet.ok()); auto item = toConfigItem(getRet.value().front()); - auto value = boost::get(item.value_); + auto value = std::get(item.value_); ASSERT_EQ(value, "abc"); // get from cache @@ -448,7 +448,7 @@ TEST(ConfigManTest, MetaConfigManTest) { auto getRet = cfgMan.getConfig(module, name).get(); ASSERT_TRUE(getRet.ok()); auto item = toConfigItem(getRet.value().front()); - auto value = boost::get(item.value_); + auto value = std::get(item.value_); Configuration conf; auto confRet = conf.parseFromString(value); @@ -521,7 +521,7 @@ TEST(ConfigManTest, MockConfigTest) { auto getRet = console.getConfig(module, name).get(); ASSERT_TRUE(getRet.ok()); auto item = toConfigItem(getRet.value().front()); - ASSERT_EQ(boost::get(item.value_), value); + ASSERT_EQ(std::get(item.value_), value); } // check values in ClientBaseGflagsManager @@ -610,7 +610,7 @@ TEST(ConfigManTest, RocksdbOptionsTest) { auto getRet = cfgMan.getConfig(module, name).get(); ASSERT_TRUE(getRet.ok()); auto item = getRet.value().front(); - auto value = boost::get(item.get_value()); + auto value = std::get(item.get_value()); sleep(FLAGS_heartbeat_interval_secs + 3); ASSERT_EQ(FLAGS_rocksdb_db_options, value); @@ -629,7 +629,7 @@ TEST(ConfigManTest, RocksdbOptionsTest) { auto getRet = cfgMan.getConfig(module, name).get(); ASSERT_TRUE(getRet.ok()); auto item = getRet.value().front(); - auto value = boost::get(item.get_value()); + auto value = std::get(item.get_value()); sleep(FLAGS_heartbeat_interval_secs + 3); ASSERT_EQ(FLAGS_rocksdb_column_family_options, value); diff --git a/src/meta/upgrade/MetaDataUpgrade.cpp b/src/meta/upgrade/MetaDataUpgrade.cpp index 3640fa0d7f3..e3b34d987f6 100644 --- a/src/meta/upgrade/MetaDataUpgrade.cpp +++ b/src/meta/upgrade/MetaDataUpgrade.cpp @@ -126,28 +126,28 @@ Status MetaDataUpgrade::rewriteConfigs(const folly::StringPiece &key, switch (item.get_type()) { case meta::v1::cpp2::ConfigType::INT64: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setInt(boost::get(value)); + configVal.setInt(std::get(value)); break; } case meta::v1::cpp2::ConfigType::DOUBLE: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setFloat(boost::get(value)); + configVal.setFloat(std::get(value)); break; } case meta::v1::cpp2::ConfigType::BOOL: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setBool(boost::get(value) ? "True" : "False"); + configVal.setBool(std::get(value) ? "True" : "False"); break; } case meta::v1::cpp2::ConfigType::STRING: { - configVal.setStr(boost::get(item.get_value())); + configVal.setStr(std::get(item.get_value())); break; } case meta::v1::cpp2::ConfigType::NESTED: { auto value = item.get_value(); // transform to map value conf::Configuration conf; - auto status = conf.parseFromString(boost::get(value)); + auto status = conf.parseFromString(std::get(value)); if (!status.ok()) { LOG(ERROR) << "Parse value: " << value << " failed: " << status; return Status::Error("Parse value: %s failed", value.c_str()); @@ -373,28 +373,28 @@ void MetaDataUpgrade::printConfigs(const folly::StringPiece &key, const folly::S switch (item.get_type()) { case meta::v1::cpp2::ConfigType::INT64: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setInt(boost::get(value)); + configVal.setInt(std::get(value)); break; } case meta::v1::cpp2::ConfigType::DOUBLE: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setFloat(boost::get(value)); + configVal.setFloat(std::get(value)); break; } case meta::v1::cpp2::ConfigType::BOOL: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setBool(boost::get(value) ? "True" : "False"); + configVal.setBool(std::get(value) ? "True" : "False"); break; } case meta::v1::cpp2::ConfigType::STRING: { - configVal.setStr(boost::get(item.get_value())); + configVal.setStr(std::get(item.get_value())); break; } case meta::v1::cpp2::ConfigType::NESTED: { auto value = item.get_value(); // transform to map value conf::Configuration conf; - auto status = conf.parseFromString(boost::get(value)); + auto status = conf.parseFromString(std::get(value)); if (!status.ok()) { LOG(ERROR) << "Parse value: " << value << " failed: " << status; return; diff --git a/src/parser/AdminSentences.cpp b/src/parser/AdminSentences.cpp index 0b15b7961c2..5307d251cb3 100644 --- a/src/parser/AdminSentences.cpp +++ b/src/parser/AdminSentences.cpp @@ -45,17 +45,17 @@ std::string ShowZonesSentence::toString() const { return std::string("SHOW ZONES std::string SpaceOptItem::toString() const { switch (optType_) { case OptionType::PARTITION_NUM: - return folly::stringPrintf("partition_num = %ld", boost::get(optValue_)); + return folly::stringPrintf("partition_num = %ld", std::get(optValue_)); case OptionType::REPLICA_FACTOR: - return folly::stringPrintf("replica_factor = %ld", boost::get(optValue_)); + return folly::stringPrintf("replica_factor = %ld", std::get(optValue_)); case OptionType::VID_TYPE: { - auto &typeDef = boost::get(optValue_); + auto &typeDef = std::get(optValue_); return folly::stringPrintf("vid_type = %s", graph::SchemaUtil::typeToString(typeDef).c_str()); } case OptionType::CHARSET: - return folly::stringPrintf("charset = %s", boost::get(optValue_).c_str()); + return folly::stringPrintf("charset = %s", std::get(optValue_).c_str()); case OptionType::COLLATE: - return folly::stringPrintf("collate = %s", boost::get(optValue_).c_str()); + return folly::stringPrintf("collate = %s", std::get(optValue_).c_str()); case OptionType::ATOMIC_EDGE: return folly::stringPrintf("atomic_edge = %s", getAtomicEdge() ? "true" : "false"); case OptionType::GROUP_NAME: diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h index 1f88385781e..cf9bf3d0807 100644 --- a/src/parser/AdminSentences.h +++ b/src/parser/AdminSentences.h @@ -160,12 +160,12 @@ class SpaceOptItem final { optValue_ = val ? 1 : 0; } - int64_t asInt() const { return boost::get(optValue_); } + int64_t asInt() const { return std::get(optValue_); } - const std::string& asString() const { return boost::get(optValue_); } + const std::string& asString() const { return std::get(optValue_); } const meta::cpp2::ColumnTypeDef& asTypeDef() const { - return boost::get(optValue_); + return std::get(optValue_); } bool isInt() const { return optValue_.which() == 0; } diff --git a/src/parser/MaintainSentences.cpp b/src/parser/MaintainSentences.cpp index 7ed8c8887a7..7c64b32d1e1 100644 --- a/src/parser/MaintainSentences.cpp +++ b/src/parser/MaintainSentences.cpp @@ -20,11 +20,11 @@ std::ostream& operator<<(std::ostream& os, meta::cpp2::PropertyType type) { std::string SchemaPropItem::toString() const { switch (propType_) { case TTL_DURATION: - return folly::stringPrintf("ttl_duration = %ld", boost::get(propValue_)); + return folly::stringPrintf("ttl_duration = %ld", std::get(propValue_)); case TTL_COL: - return folly::stringPrintf("ttl_col = \"%s\"", boost::get(propValue_).c_str()); + return folly::stringPrintf("ttl_col = \"%s\"", std::get(propValue_).c_str()); case COMMENT: - return folly::stringPrintf("comment = \"%s\"", boost::get(propValue_).c_str()); + return folly::stringPrintf("comment = \"%s\"", std::get(propValue_).c_str()); } DLOG(FATAL) << "Schema property type illegal"; return "Unknown"; diff --git a/src/parser/MaintainSentences.h b/src/parser/MaintainSentences.h index e78e78855cc..8bdcd86302c 100644 --- a/src/parser/MaintainSentences.h +++ b/src/parser/MaintainSentences.h @@ -215,16 +215,16 @@ class SchemaPropItem final { std::string toString() const; private: - int64_t asInt() { return boost::get(propValue_); } + int64_t asInt() { return std::get(propValue_); } - const std::string &asString() { return boost::get(propValue_); } + const std::string &asString() { return std::get(propValue_); } bool asBool() { switch (propValue_.which()) { case 0: return asInt() != 0; case 1: - return boost::get(propValue_); + return std::get(propValue_); case 2: return asString().empty(); default: diff --git a/src/storage/test/IndexScanTest.cpp b/src/storage/test/IndexScanTest.cpp index 73072fe8ec9..51da915ecb6 100644 --- a/src/storage/test/IndexScanTest.cpp +++ b/src/storage/test/IndexScanTest.cpp @@ -30,7 +30,7 @@ std::string indexStr(RowReader* reader, const nebula::cpp2::ColumnDef& col) { auto&& v = value(std::move(res)); switch (col.get_type().get_type()) { case nebula::cpp2::SupportedType::BOOL: { - auto val = boost::get(v); + auto val = std::get(v); std::string raw; raw.reserve(sizeof(bool)); raw.append(reinterpret_cast(&val), sizeof(bool)); @@ -38,14 +38,14 @@ std::string indexStr(RowReader* reader, const nebula::cpp2::ColumnDef& col) { } case nebula::cpp2::SupportedType::INT: case nebula::cpp2::SupportedType::TIMESTAMP: { - return NebulaKeyUtils::encodeInt64(boost::get(v)); + return NebulaKeyUtils::encodeInt64(std::get(v)); } case nebula::cpp2::SupportedType::FLOAT: case nebula::cpp2::SupportedType::DOUBLE: { - return NebulaKeyUtils::encodeDouble(boost::get(v)); + return NebulaKeyUtils::encodeDouble(std::get(v)); } case nebula::cpp2::SupportedType::STRING: { - return boost::get(v); + return std::get(v); } default: LOG(ERROR) << "Unknown type: " @@ -533,7 +533,7 @@ static cpp2::LookUpEdgeIndexResp checkLookupEdgesDouble(const std::string& filte VertexID dstId = 10; auto eKey = NebulaKeyUtils::edgeKey(partId, srcId, type, 0, dstId); RowWriter ewriter(nullptr); - ewriter << boost::get(1.1) << boost::get(0.0) << boost::get(-1.1); + ewriter << std::get(1.1) << std::get(0.0) << std::get(-1.1); auto eval = ewriter.encode(); auto edgeIndex = genEdgeIndexKey(schemaMan.get(), eval, spaceId, partId, type, eindex, srcId, dstId); @@ -545,7 +545,7 @@ static cpp2::LookUpEdgeIndexResp checkLookupEdgesDouble(const std::string& filte VertexID dstId = 20; auto eKey = NebulaKeyUtils::edgeKey(partId, srcId, type, 0, dstId); RowWriter ewriter(nullptr); - ewriter << boost::get(2.2) << boost::get(0.0) << boost::get(-2.2); + ewriter << std::get(2.2) << std::get(0.0) << std::get(-2.2); auto eval = ewriter.encode(); auto edgeIndex = genEdgeIndexKey(schemaMan.get(), eval, spaceId, partId, type, eindex, srcId, dstId); @@ -620,7 +620,7 @@ static cpp2::LookUpVertexIndexResp checkLookupVerticesDouble(const std::string& VertexID vertexId = 100; auto key = NebulaKeyUtils::vertexKey(partId, vertexId, tagId, version); RowWriter twriter(nullptr); - twriter << boost::get(1.1) << boost::get(0.0) << boost::get(-1.1); + twriter << std::get(1.1) << std::get(0.0) << std::get(-1.1); auto tval = twriter.encode(); auto vIndex = genVertexIndexKey(schemaMan.get(), tval, spaceId, partId, tagId, vindex, vertexId); @@ -631,7 +631,7 @@ static cpp2::LookUpVertexIndexResp checkLookupVerticesDouble(const std::string& VertexID vertexId = 200; auto key = NebulaKeyUtils::vertexKey(partId, vertexId, tagId, version); RowWriter twriter(nullptr); - twriter << boost::get(2.2) << boost::get(0.0) << boost::get(-2.2); + twriter << std::get(2.2) << std::get(0.0) << std::get(-2.2); auto tval = twriter.encode(); auto vIndex = genVertexIndexKey(schemaMan.get(), tval, spaceId, partId, tagId, vindex, vertexId); @@ -1146,7 +1146,7 @@ TEST(IndexScanTest, EdgeDoubleTest) { EXPECT_EQ(3, resp.get_schema()->get_columns().size()); EXPECT_EQ(3, resp.rows.size()); RowWriter ewriter(nullptr); - ewriter << boost::get(1.1) << boost::get(0.0) << boost::get(-1.1); + ewriter << std::get(1.1) << std::get(0.0) << std::get(-1.1); auto eval = ewriter.encode(); for (const auto& row : resp.rows) { EXPECT_EQ(eval, row.get_props()); @@ -1177,7 +1177,7 @@ TEST(IndexScanTest, EdgeDoubleTest) { EXPECT_EQ(3, resp.get_schema()->get_columns().size()); EXPECT_EQ(3, resp.rows.size()); RowWriter ewriter(nullptr); - ewriter << boost::get(1.1) << boost::get(0.0) << boost::get(-1.1); + ewriter << std::get(1.1) << std::get(0.0) << std::get(-1.1); auto eval = ewriter.encode(); for (const auto& row : resp.rows) { EXPECT_EQ(eval, row.get_props()); @@ -1208,7 +1208,7 @@ TEST(IndexScanTest, EdgeDoubleTest) { EXPECT_EQ(3, resp.get_schema()->get_columns().size()); EXPECT_EQ(3, resp.rows.size()); RowWriter ewriter(nullptr); - ewriter << boost::get(2.2) << boost::get(0.0) << boost::get(-2.2); + ewriter << std::get(2.2) << std::get(0.0) << std::get(-2.2); auto eval = ewriter.encode(); for (const auto& row : resp.rows) { EXPECT_EQ(eval, row.get_props()); @@ -1263,7 +1263,7 @@ TEST(IndexScanTest, VertexDoubleTest) { EXPECT_EQ(3, resp.get_schema()->get_columns().size()); EXPECT_EQ(3, resp.rows.size()); RowWriter ewriter(nullptr); - ewriter << boost::get(1.1) << boost::get(0.0) << boost::get(-1.1); + ewriter << std::get(1.1) << std::get(0.0) << std::get(-1.1); auto eval = ewriter.encode(); for (const auto& row : resp.rows) { EXPECT_EQ(eval, row.get_props()); @@ -1291,7 +1291,7 @@ TEST(IndexScanTest, VertexDoubleTest) { EXPECT_EQ(3, resp.get_schema()->get_columns().size()); EXPECT_EQ(3, resp.rows.size()); RowWriter ewriter(nullptr); - ewriter << boost::get(1.1) << boost::get(0.0) << boost::get(-1.1); + ewriter << std::get(1.1) << std::get(0.0) << std::get(-1.1); auto eval = ewriter.encode(); for (const auto& row : resp.rows) { EXPECT_EQ(eval, row.get_props()); @@ -1319,7 +1319,7 @@ TEST(IndexScanTest, VertexDoubleTest) { EXPECT_EQ(3, resp.get_schema()->get_columns().size()); EXPECT_EQ(3, resp.rows.size()); RowWriter ewriter(nullptr); - ewriter << boost::get(2.2) << boost::get(0.0) << boost::get(-2.2); + ewriter << std::get(2.2) << std::get(0.0) << std::get(-2.2); auto eval = ewriter.encode(); for (const auto& row : resp.rows) { EXPECT_EQ(eval, row.get_props()); diff --git a/src/storage/test/StorageLookupBenchmark.cpp b/src/storage/test/StorageLookupBenchmark.cpp index f2cb0a94c1f..58f17997bfe 100644 --- a/src/storage/test/StorageLookupBenchmark.cpp +++ b/src/storage/test/StorageLookupBenchmark.cpp @@ -39,7 +39,7 @@ std::string indexStr(RowReader* reader, const std::string& col) { return ""; } auto&& v = value(std::move(res)); - return NebulaKeyUtils::encodeInt64(boost::get(v)); + return NebulaKeyUtils::encodeInt64(std::get(v)); } IndexValues collectIndexValues(RowReader* reader, diff --git a/src/tools/storage-perf/StorageIntegrityTool.cpp b/src/tools/storage-perf/StorageIntegrityTool.cpp index a5f83002023..b62e125099d 100644 --- a/src/tools/storage-perf/StorageIntegrityTool.cpp +++ b/src/tools/storage-perf/StorageIntegrityTool.cpp @@ -254,7 +254,7 @@ class IntegrityTest { auto tagReader = RowReaderWrapper::getRowReader(iter->data, tagProvider); auto ret = RowReader::getPropByName(tagReader.get(), propName_); CHECK(ok(ret)); - nextId = boost::get(value(ret)); + nextId = std::get(value(ret)); } #endif count++; From b24a7a2de58c2150041d3a7f1b307fc928550f76 Mon Sep 17 00:00:00 2001 From: Jun Date: Mon, 25 Oct 2021 15:23:57 +0800 Subject: [PATCH 06/15] refactor: use std::optional instead of boost::optional Signed-off-by: Jun --- src/common/base/ConcurrentLRUCache.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/base/ConcurrentLRUCache.h b/src/common/base/ConcurrentLRUCache.h index f3c4450ab50..5e46bee177c 100644 --- a/src/common/base/ConcurrentLRUCache.h +++ b/src/common/base/ConcurrentLRUCache.h @@ -9,8 +9,8 @@ #include -#include #include +#include #include #include "common/base/Base.h" @@ -111,7 +111,7 @@ class ConcurrentLRUCache final { StatusOr get(const K& key) { std::lock_guard guard(lock_); auto v = lru_->get(key); - if (v == boost::none) { + if (v == std::nullopt) { return Status::Error(); } return std::move(v).value(); @@ -120,7 +120,7 @@ class ConcurrentLRUCache final { StatusOr putIfAbsent(K&& key, V&& val) { std::lock_guard guard(lock_); auto v = lru_->get(key); - if (v == boost::none) { + if (v == std::nullopt) { lru_->insert(std::forward(key), std::forward(val)); return Status::Inserted(); } @@ -209,13 +209,13 @@ class LRU { } } - boost::optional get(const key_type& key) { + std::optional get(const key_type& key) { // lookup value in the cache total_++; typename map_type::iterator i = map_.find(key); if (i == map_.end()) { // value not in cache - return boost::none; + return std::nullopt; } // return the value, but first update its place in the most From ef96400eb741d53d7bba82a214bcd4d80a2866c3 Mon Sep 17 00:00:00 2001 From: Jun Date: Mon, 25 Oct 2021 17:48:21 +0800 Subject: [PATCH 07/15] refactor: correct std::optional api to has_value() Signed-off-by: Jun --- src/kvstore/raftex/RaftPart.cpp | 8 ++++---- src/storage/exec/EdgeNode.h | 2 +- src/storage/exec/StorageIterator.h | 2 +- src/storage/exec/TagNode.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/kvstore/raftex/RaftPart.cpp b/src/kvstore/raftex/RaftPart.cpp index e9285f82697..03610619724 100644 --- a/src/kvstore/raftex/RaftPart.cpp +++ b/src/kvstore/raftex/RaftPart.cpp @@ -89,7 +89,7 @@ class AppendLogsIterator final : public LogIterator { // Process AtomicOp log CHECK(!!opCB_); opResult_ = opCB_(std::move(std::get<3>(tup))); - if (opResult_.hasValue()) { + if (opResult_.has_value()) { // AtomicOp Succeeded return true; } else { @@ -139,7 +139,7 @@ class AppendLogsIterator final : public LogIterator { folly::StringPiece logMsg() const override { DCHECK(valid()); if (currLogType_ == LogType::ATOMIC_OP) { - CHECK(opResult_.hasValue()); + CHECK(opResult_.has_value()); return opResult_.value(); } else { return std::get<2>(logs_.at(idx_)); @@ -677,7 +677,7 @@ folly::Future RaftPart::appendLogAsync(ClusterID source, [this](AtomicOp opCB) -> std::optional { CHECK(opCB != nullptr); auto opRet = opCB(); - if (!opRet.hasValue()) { + if (!opRet.has_value()) { // Failed sendingPromise_.setOneSingleValue(AppendLogResult::E_ATOMIC_OP_FAILURE); } @@ -915,7 +915,7 @@ void RaftPart::processAppendLogResponses(const AppendLogResponses& resps, std::move(logs_), [this](AtomicOp op) -> std::optional { auto opRet = op(); - if (!opRet.hasValue()) { + if (!opRet.has_value()) { // Failed sendingPromise_.setOneSingleValue(AppendLogResult::E_ATOMIC_OP_FAILURE); } diff --git a/src/storage/exec/EdgeNode.h b/src/storage/exec/EdgeNode.h index 71258df0a6e..8998e535be4 100644 --- a/src/storage/exec/EdgeNode.h +++ b/src/storage/exec/EdgeNode.h @@ -127,7 +127,7 @@ class FetchEdgeNode final : public EdgeNode { void resetReader() { reader_.reset(*schemas_, val_); if (!reader_ || - (ttl_.hasValue() && + (ttl_.has_value() && CommonUtils::checkDataExpiredForTTL( schemas_->back().get(), reader_.get(), ttl_.value().first, ttl_.value().second))) { reader_.reset(); diff --git a/src/storage/exec/StorageIterator.h b/src/storage/exec/StorageIterator.h index d5f141b5d88..7312552dc97 100644 --- a/src/storage/exec/StorageIterator.h +++ b/src/storage/exec/StorageIterator.h @@ -43,7 +43,7 @@ class SingleEdgeIterator : public StorageIterator { const std::optional>* ttl) : context_(context), iter_(std::move(iter)), edgeType_(edgeType), schemas_(schemas) { CHECK(!!iter_); - if (ttl->hasValue()) { + if (ttl->has_value()) { hasTtl_ = true; ttlCol_ = ttl->value().first; ttlDuration_ = ttl->value().second; diff --git a/src/storage/exec/TagNode.h b/src/storage/exec/TagNode.h index 610fba7dae0..beb1e5ac58a 100644 --- a/src/storage/exec/TagNode.h +++ b/src/storage/exec/TagNode.h @@ -90,7 +90,7 @@ class TagNode final : public IterateNode { void resetReader() { reader_.reset(*schemas_, value_); if (!reader_ || - (ttl_.hasValue() && + (ttl_.has_value() && CommonUtils::checkDataExpiredForTTL( schemas_->back().get(), reader_.get(), ttl_.value().first, ttl_.value().second))) { reader_.reset(); From fb8e64e74e159279c3abd5696017bc4a3a61b73d Mon Sep 17 00:00:00 2001 From: Jun Date: Mon, 25 Oct 2021 18:15:28 +0800 Subject: [PATCH 08/15] refactor: correct std::variant api Signed-off-by: Jun --- src/parser/AdminSentences.h | 6 +++--- src/parser/MaintainSentences.h | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h index cf9bf3d0807..91e233f1ca2 100644 --- a/src/parser/AdminSentences.h +++ b/src/parser/AdminSentences.h @@ -168,11 +168,11 @@ class SpaceOptItem final { return std::get(optValue_); } - bool isInt() const { return optValue_.which() == 0; } + bool isInt() const { return optValue_.index() == 0; } - bool isString() const { return optValue_.which() == 1; } + bool isString() const { return optValue_.index() == 1; } - bool isTypeDef() const { return optValue_.which() == 2; } + bool isTypeDef() const { return optValue_.index() == 2; } int64_t getPartitionNum() const { if (isInt()) { diff --git a/src/parser/MaintainSentences.h b/src/parser/MaintainSentences.h index 8bdcd86302c..f5cf824d31f 100644 --- a/src/parser/MaintainSentences.h +++ b/src/parser/MaintainSentences.h @@ -188,7 +188,8 @@ class SchemaPropItem final { if (isInt()) { return asInt(); } else { - LOG(ERROR) << "Ttl_duration value illegal: " << propValue_; + std::visit([](const auto &val) { LOG(ERROR) << "Ttl_duration value illegal: " << val; }, + propValue_); return Status::Error("Ttl_duration value illegal"); } } @@ -197,7 +198,8 @@ class SchemaPropItem final { if (isString()) { return asString(); } else { - LOG(ERROR) << "Ttl_col value illegal: " << propValue_; + std::visit([](const auto &val) { LOG(ERROR) << "Ttl_col value illegal: " << val; }, + propValue_); return Status::Error("Ttl_col value illegal"); } } @@ -220,7 +222,7 @@ class SchemaPropItem final { const std::string &asString() { return std::get(propValue_); } bool asBool() { - switch (propValue_.which()) { + switch (propValue_.index()) { case 0: return asInt() != 0; case 1: @@ -233,11 +235,11 @@ class SchemaPropItem final { return false; } - bool isInt() { return propValue_.which() == 0; } + bool isInt() { return propValue_.index() == 0; } - bool isBool() { return propValue_.which() == 1; } + bool isBool() { return propValue_.index() == 1; } - bool isString() { return propValue_.which() == 2; } + bool isString() { return propValue_.index() == 2; } private: Value propValue_; From 668cba6a7616c29d3e703e73f937dc4c90f6e1e1 Mon Sep 17 00:00:00 2001 From: Jun Date: Mon, 25 Oct 2021 18:45:02 +0800 Subject: [PATCH 09/15] fix: add default parameters Signed-off-by: Jun --- src/meta/processors/admin/AdminClient.h | 4 ++-- src/meta/upgrade/MetaDataUpgrade.cpp | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/meta/processors/admin/AdminClient.h b/src/meta/processors/admin/AdminClient.h index 342d5c1d828..ee3990ab605 100644 --- a/src/meta/processors/admin/AdminClient.h +++ b/src/meta/processors/admin/AdminClient.h @@ -115,7 +115,7 @@ class AdminClient { folly::Future getResponse(const HostAddr& host, Request req, RemoteFunc remoteFunc, - RespGenerator respGen); + RespGenerator respGen = std::nullopt); template void getResponse(std::vector hosts, @@ -125,7 +125,7 @@ class AdminClient { int32_t retry, folly::Promise pro, int32_t retryLimit, - HandleResultOpt respGen); + HandleResultOpt respGen = std::nullopt); void getLeaderDist(const HostAddr& host, folly::Promise>&& pro, diff --git a/src/meta/upgrade/MetaDataUpgrade.cpp b/src/meta/upgrade/MetaDataUpgrade.cpp index e3b34d987f6..3640fa0d7f3 100644 --- a/src/meta/upgrade/MetaDataUpgrade.cpp +++ b/src/meta/upgrade/MetaDataUpgrade.cpp @@ -126,28 +126,28 @@ Status MetaDataUpgrade::rewriteConfigs(const folly::StringPiece &key, switch (item.get_type()) { case meta::v1::cpp2::ConfigType::INT64: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setInt(std::get(value)); + configVal.setInt(boost::get(value)); break; } case meta::v1::cpp2::ConfigType::DOUBLE: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setFloat(std::get(value)); + configVal.setFloat(boost::get(value)); break; } case meta::v1::cpp2::ConfigType::BOOL: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setBool(std::get(value) ? "True" : "False"); + configVal.setBool(boost::get(value) ? "True" : "False"); break; } case meta::v1::cpp2::ConfigType::STRING: { - configVal.setStr(std::get(item.get_value())); + configVal.setStr(boost::get(item.get_value())); break; } case meta::v1::cpp2::ConfigType::NESTED: { auto value = item.get_value(); // transform to map value conf::Configuration conf; - auto status = conf.parseFromString(std::get(value)); + auto status = conf.parseFromString(boost::get(value)); if (!status.ok()) { LOG(ERROR) << "Parse value: " << value << " failed: " << status; return Status::Error("Parse value: %s failed", value.c_str()); @@ -373,28 +373,28 @@ void MetaDataUpgrade::printConfigs(const folly::StringPiece &key, const folly::S switch (item.get_type()) { case meta::v1::cpp2::ConfigType::INT64: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setInt(std::get(value)); + configVal.setInt(boost::get(value)); break; } case meta::v1::cpp2::ConfigType::DOUBLE: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setFloat(std::get(value)); + configVal.setFloat(boost::get(value)); break; } case meta::v1::cpp2::ConfigType::BOOL: { auto value = *reinterpret_cast(item.get_value().data()); - configVal.setBool(std::get(value) ? "True" : "False"); + configVal.setBool(boost::get(value) ? "True" : "False"); break; } case meta::v1::cpp2::ConfigType::STRING: { - configVal.setStr(std::get(item.get_value())); + configVal.setStr(boost::get(item.get_value())); break; } case meta::v1::cpp2::ConfigType::NESTED: { auto value = item.get_value(); // transform to map value conf::Configuration conf; - auto status = conf.parseFromString(std::get(value)); + auto status = conf.parseFromString(boost::get(value)); if (!status.ok()) { LOG(ERROR) << "Parse value: " << value << " failed: " << status; return; From b578abff6ea2a68c4115261ca9ed915c3ee3c5ad Mon Sep 17 00:00:00 2001 From: Jun Date: Mon, 25 Oct 2021 22:32:44 +0800 Subject: [PATCH 10/15] fix: convert folly::Optional to std::optional Signed-off-by: Jun --- src/storage/admin/AdminTaskManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/admin/AdminTaskManager.cpp b/src/storage/admin/AdminTaskManager.cpp index a594993c936..cf97e0459a1 100644 --- a/src/storage/admin/AdminTaskManager.cpp +++ b/src/storage/admin/AdminTaskManager.cpp @@ -232,7 +232,7 @@ void AdminTaskManager::schedule() { LOG(INFO) << "waiting for incoming task"; std::optional optTaskHandle{std::nullopt}; while (!optTaskHandle && !shutdown_.load(std::memory_order_acquire)) { - optTaskHandle = taskQueue_.try_take_for(interval); + optTaskHandle = taskQueue_.try_take_for(interval).value(); } if (shutdown_.load(std::memory_order_acquire)) { From c47b596767ad16a07e2b0fa89b29a46c94d4cb89 Mon Sep 17 00:00:00 2001 From: jiayuehua <3423893+jiayuehua@users.noreply.github.com> Date: Tue, 15 Mar 2022 12:54:43 +0800 Subject: [PATCH 11/15] format files --- src/clients/meta/MetaClient.cpp | 199 +++++++++++----------- src/kvstore/raftex/RaftPart.cpp | 6 +- src/parser/AdminSentences.h | 18 +- src/parser/MaintainSentences.h | 20 ++- src/storage/test/ChainDeleteEdgesTest.cpp | 8 +- 5 files changed, 135 insertions(+), 116 deletions(-) diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index eefbe59aa54..b1e7de2e63d 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -674,106 +674,105 @@ void MetaClient::getResponse(Request req, folly::RWSpinLock::ReadHolder holder(&hostLock_); host = toLeader ? leader_ : active_; } - folly::via( - evb, - [host, - evb, - req = std::move(req), - remoteFunc = std::move(remoteFunc), - respGen = std::move(respGen), - pro = std::move(pro), - toLeader, - retry, - retryLimit, - this]() mutable { - auto client = clientsMan_->client(host, evb, false, FLAGS_meta_client_timeout_ms); - VLOG(1) << "Send request to meta " << host; - remoteFunc(client, req) - .via(evb) - .then([host, - req = std::move(req), - remoteFunc = std::move(remoteFunc), - respGen = std::move(respGen), - pro = std::move(pro), - toLeader, - retry, - retryLimit, - evb, - this](folly::Try&& t) mutable { - // exception occurred during RPC - if (t.hasException()) { - stats::StatsManager::addValue(kNumRpcSentToMetadFailed); - if (toLeader) { - updateLeader(); - } else { - updateActive(); - } - if (retry < retryLimit) { - evb->runAfterDelay( - [req = std::move(req), - remoteFunc = std::move(remoteFunc), - respGen = std::move(respGen), - pro = std::move(pro), - toLeader, - retry, - retryLimit, - this]() mutable { - getResponse(std::move(req), - std::move(remoteFunc), - std::move(respGen), - std::move(pro), - toLeader, - retry + 1, - retryLimit); - }, - FLAGS_meta_client_retry_interval_secs * 1000); - return; - } else { - LOG(ERROR) << "Send request to " << host << ", exceed retry limit"; - LOG(ERROR) << "RpcResponse exception: " << t.exception().what().c_str(); - pro.setValue( - Status::Error("RPC failure in MetaClient: %s", t.exception().what().c_str())); - } - return; - } - - auto&& resp = t.value(); - auto code = resp.get_code(); - if (code == nebula::cpp2::ErrorCode::SUCCEEDED) { - // succeeded - pro.setValue(respGen(std::move(resp))); - return; - } else if (code == nebula::cpp2::ErrorCode::E_LEADER_CHANGED || - code == nebula::cpp2::ErrorCode::E_MACHINE_NOT_FOUND) { - updateLeader(resp.get_leader()); - if (retry < retryLimit) { - evb->runAfterDelay( - [req = std::move(req), - remoteFunc = std::move(remoteFunc), - respGen = std::move(respGen), - pro = std::move(pro), - toLeader, - retry, - retryLimit, - this]() mutable { - getResponse(std::move(req), - std::move(remoteFunc), - std::move(respGen), - std::move(pro), - toLeader, - retry + 1, - retryLimit); - }, - FLAGS_meta_client_retry_interval_secs * 1000); - return; - } - } else if (code == nebula::cpp2::ErrorCode::E_CLIENT_SERVER_INCOMPATIBLE) { - pro.setValue(respGen(std::move(resp))); - return; - } - pro.setValue(this->handleResponse(resp)); - }); // then - }); // via + folly::via(evb, + [host, + evb, + req = std::move(req), + remoteFunc = std::move(remoteFunc), + respGen = std::move(respGen), + pro = std::move(pro), + toLeader, + retry, + retryLimit, + this]() mutable { + auto client = clientsMan_->client(host, evb, false, FLAGS_meta_client_timeout_ms); + VLOG(1) << "Send request to meta " << host; + remoteFunc(client, req) + .via(evb) + .then([host, + req = std::move(req), + remoteFunc = std::move(remoteFunc), + respGen = std::move(respGen), + pro = std::move(pro), + toLeader, + retry, + retryLimit, + evb, + this](folly::Try&& t) mutable { + // exception occurred during RPC + if (t.hasException()) { + stats::StatsManager::addValue(kNumRpcSentToMetadFailed); + if (toLeader) { + updateLeader(); + } else { + updateActive(); + } + if (retry < retryLimit) { + evb->runAfterDelay( + [req = std::move(req), + remoteFunc = std::move(remoteFunc), + respGen = std::move(respGen), + pro = std::move(pro), + toLeader, + retry, + retryLimit, + this]() mutable { + getResponse(std::move(req), + std::move(remoteFunc), + std::move(respGen), + std::move(pro), + toLeader, + retry + 1, + retryLimit); + }, + FLAGS_meta_client_retry_interval_secs * 1000); + return; + } else { + LOG(ERROR) << "Send request to " << host << ", exceed retry limit"; + LOG(ERROR) << "RpcResponse exception: " << t.exception().what().c_str(); + pro.setValue(Status::Error("RPC failure in MetaClient: %s", + t.exception().what().c_str())); + } + return; + } + + auto&& resp = t.value(); + auto code = resp.get_code(); + if (code == nebula::cpp2::ErrorCode::SUCCEEDED) { + // succeeded + pro.setValue(respGen(std::move(resp))); + return; + } else if (code == nebula::cpp2::ErrorCode::E_LEADER_CHANGED || + code == nebula::cpp2::ErrorCode::E_MACHINE_NOT_FOUND) { + updateLeader(resp.get_leader()); + if (retry < retryLimit) { + evb->runAfterDelay( + [req = std::move(req), + remoteFunc = std::move(remoteFunc), + respGen = std::move(respGen), + pro = std::move(pro), + toLeader, + retry, + retryLimit, + this]() mutable { + getResponse(std::move(req), + std::move(remoteFunc), + std::move(respGen), + std::move(pro), + toLeader, + retry + 1, + retryLimit); + }, + FLAGS_meta_client_retry_interval_secs * 1000); + return; + } + } else if (code == nebula::cpp2::ErrorCode::E_CLIENT_SERVER_INCOMPATIBLE) { + pro.setValue(respGen(std::move(resp))); + return; + } + pro.setValue(this->handleResponse(resp)); + }); // then + }); // via } std::vector MetaClient::toSpaceIdName(const std::vector& tIdNames) { diff --git a/src/kvstore/raftex/RaftPart.cpp b/src/kvstore/raftex/RaftPart.cpp index 3c542595f0b..af9be7033cd 100644 --- a/src/kvstore/raftex/RaftPart.cpp +++ b/src/kvstore/raftex/RaftPart.cpp @@ -701,7 +701,7 @@ folly::Future RaftPart::appendLogAsync(ClusterID source firstId, termId, std::move(swappedOutLogs), - [this](AtomicOp opCB) -> std::optional { + [this](AtomicOp opCB) -> std::optional { CHECK(opCB != nullptr); auto opRet = opCB(); if (!opRet.hasValue()) { @@ -964,9 +964,9 @@ void RaftPart::processAppendLogResponses(const AppendLogResponses& resps, iter = AppendLogsIterator(firstLogId, currTerm, std::move(logs_), - [this](AtomicOp op) -> std::optional { + [this](AtomicOp op) -> std::optional { auto opRet = op(); - if (!opRet.has_value()) { + if (!opRet.has_value()) { // Failed sendingPromise_.setOneSingleValue( nebula::cpp2::ErrorCode::E_RAFT_ATOMIC_OP_FAILED); diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h index 273c045ab09..298d8cfb365 100644 --- a/src/parser/AdminSentences.h +++ b/src/parser/AdminSentences.h @@ -189,20 +189,28 @@ class SpaceOptItem final { } int64_t asInt() const { - return boost::get(optValue_); + return std::get(optValue_); } - const std::string& asString() const { return std::get(optValue_); } + const std::string& asString() const { + return std::get(optValue_); + } const meta::cpp2::ColumnTypeDef& asTypeDef() const { return std::get(optValue_); } - bool isInt() const { return optValue_.index() == 0; } + bool isInt() const { + return optValue_.index() == 0; + } - bool isString() const { return optValue_.index() == 1; } + bool isString() const { + return optValue_.index() == 1; + } - bool isTypeDef() const { return optValue_.index() == 2; } + bool isTypeDef() const { + return optValue_.index() == 2; + } int64_t getPartitionNum() const { if (isInt()) { diff --git a/src/parser/MaintainSentences.h b/src/parser/MaintainSentences.h index d68a51fdb7f..cc56f3cdc43 100644 --- a/src/parser/MaintainSentences.h +++ b/src/parser/MaintainSentences.h @@ -242,9 +242,13 @@ class SchemaPropItem final { std::string toString() const; private: - int64_t asInt() { return std::get(propValue_); } + int64_t asInt() { + return std::get(propValue_); + } - const std::string &asString() { return std::get(propValue_); } + const std::string &asString() { + return std::get(propValue_); + } bool asBool() { switch (propValue_.index()) { @@ -260,11 +264,17 @@ class SchemaPropItem final { return false; } - bool isInt() { return propValue_.index() == 0; } + bool isInt() { + return propValue_.index() == 0; + } - bool isBool() { return propValue_.index() == 1; } + bool isBool() { + return propValue_.index() == 1; + } - bool isString() { return propValue_.index() == 2; } + bool isString() { + return propValue_.index() == 2; + } private: Value propValue_; diff --git a/src/storage/test/ChainDeleteEdgesTest.cpp b/src/storage/test/ChainDeleteEdgesTest.cpp index 1aa7148cca6..d9e4597aeb3 100644 --- a/src/storage/test/ChainDeleteEdgesTest.cpp +++ b/src/storage/test/ChainDeleteEdgesTest.cpp @@ -10,6 +10,8 @@ #include #include +#include + #include "common/fs/TempDir.h" #include "mock/MockCluster.h" #include "mock/MockData.h" @@ -39,9 +41,9 @@ class FakeChainDeleteEdgesProcessor : public ChainDeleteEdgesLocalProcessor { int32_t limit = std::numeric_limits::max()); public: - folly::Optional rcPrepareLocal; - folly::Optional rcProcessRemote; - folly::Optional rcProcessLocal; + std::optional rcPrepareLocal; + std::optional rcProcessRemote; + std::optional rcProcessLocal; }; // make sure test utils works From dbeff3712b21b885dcda493def15ab8ac89fe65e Mon Sep 17 00:00:00 2001 From: jiayuehua <3423893+jiayuehua@users.noreply.github.com> Date: Tue, 15 Mar 2022 16:58:45 +0800 Subject: [PATCH 12/15] fix hasValue to has_value --- src/kvstore/raftex/RaftPart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kvstore/raftex/RaftPart.cpp b/src/kvstore/raftex/RaftPart.cpp index af9be7033cd..0d08557d869 100644 --- a/src/kvstore/raftex/RaftPart.cpp +++ b/src/kvstore/raftex/RaftPart.cpp @@ -704,7 +704,7 @@ folly::Future RaftPart::appendLogAsync(ClusterID source [this](AtomicOp opCB) -> std::optional { CHECK(opCB != nullptr); auto opRet = opCB(); - if (!opRet.hasValue()) { + if (!opRet.has_value()) { // Failed sendingPromise_.setOneSingleValue(nebula::cpp2::ErrorCode::E_RAFT_ATOMIC_OP_FAILED); } From 23bf0e4f5738b32a115ea1f289a5dce890e634e2 Mon Sep 17 00:00:00 2001 From: jiayuehua <3423893+jiayuehua@users.noreply.github.com> Date: Wed, 16 Mar 2022 11:28:29 +0800 Subject: [PATCH 13/15] remove optional .value() --- src/storage/admin/AdminTaskManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage/admin/AdminTaskManager.cpp b/src/storage/admin/AdminTaskManager.cpp index 1acfdba5863..9183f7b592d 100644 --- a/src/storage/admin/AdminTaskManager.cpp +++ b/src/storage/admin/AdminTaskManager.cpp @@ -235,9 +235,9 @@ void AdminTaskManager::schedule() { std::chrono::milliseconds interval{20}; // 20ms while (!shutdown_.load(std::memory_order_acquire)) { LOG(INFO) << "waiting for incoming task"; - std::optional optTaskHandle{std::nullopt}; + folly::Optional optTaskHandle{folly::none}; while (!optTaskHandle && !shutdown_.load(std::memory_order_acquire)) { - optTaskHandle = taskQueue_.try_take_for(interval).value(); + optTaskHandle = taskQueue_.try_take_for(interval); } if (shutdown_.load(std::memory_order_acquire)) { From e119eea91ab036baf598ac28f07d60fab8897c87 Mon Sep 17 00:00:00 2001 From: jiayuehua <3423893+jiayuehua@users.noreply.github.com> Date: Wed, 16 Mar 2022 11:41:52 +0800 Subject: [PATCH 14/15] add upstream comment --- src/storage/exec/QueryUtils.h | 16 ++++++++++++++-- src/storage/exec/UpdateNode.h | 12 ++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/storage/exec/QueryUtils.h b/src/storage/exec/QueryUtils.h index 992912b2314..3c1d381ab09 100644 --- a/src/storage/exec/QueryUtils.h +++ b/src/storage/exec/QueryUtils.h @@ -215,7 +215,13 @@ class QueryUtils final { return Status::OK(); } - // return none if no valid ttl, else return the ttl property name and time + /** + * @brief Get the Edge TTL Info object + * + * @param edgeContext + * @param edgeType + * @return return none if no valid ttl, else return the ttl property name and time + */ static std::optional> getEdgeTTLInfo(EdgeContext* edgeContext, EdgeType edgeType) { std::optional> ret; @@ -226,7 +232,13 @@ class QueryUtils final { return ret; } - // return none if no valid ttl, else return the ttl property name and time + /** + * @brief Get the Tag TTL Info object + * + * @param tagContext + * @param tagId + * @return return none if no valid ttl, else return the ttl property name and time + */ static std::optional> getTagTTLInfo(TagContext* tagContext, TagID tagId) { std::optional> ret; diff --git a/src/storage/exec/UpdateNode.h b/src/storage/exec/UpdateNode.h index 59541c6e045..8db6025d0da 100644 --- a/src/storage/exec/UpdateNode.h +++ b/src/storage/exec/UpdateNode.h @@ -314,6 +314,18 @@ class UpdateTagNode : public UpdateNode { return nebula::cpp2::ErrorCode::SUCCEEDED; } + /** + * @brief Calculate updated propertis and indexes + * + * This function will calculate the properties to be updated and those indexes if exist, and + * encode them into key-value format. + * + * @param partId + * @param vId + * @return folly::Optional BatchHolder encode value. + * @see BatchHolder + */ + std::optional updateAndWriteBack(const PartitionID partId, const VertexID vId) { ObjectPool pool; for (auto& updateProp : updatedProps_) { From c77c257081925a67da2b008183082cbdc805531e Mon Sep 17 00:00:00 2001 From: jiayuehua <3423893+jiayuehua@users.noreply.github.com> Date: Wed, 16 Mar 2022 12:14:48 +0800 Subject: [PATCH 15/15] add comment back --- src/storage/exec/UpdateNode.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/storage/exec/UpdateNode.h b/src/storage/exec/UpdateNode.h index f30c390c56e..bea2758a323 100644 --- a/src/storage/exec/UpdateNode.h +++ b/src/storage/exec/UpdateNode.h @@ -732,7 +732,13 @@ class UpdateEdgeNode : public UpdateNode { val_ = reader_->getData(); return nebula::cpp2::ErrorCode::SUCCEEDED; } - + /** + * @brief Calculate updated propertis and indexes + * + * Similar to UpdateTagNode::updateAndWriteBack + * + * @see UpdateTagNode::updateAndWriteBack + */ std::optional updateAndWriteBack(const PartitionID partId, const cpp2::EdgeKey& edgeKey) { ObjectPool pool;