From ca5556063c5c6fe742ce16804c8cef53506531d9 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Wed, 8 Dec 2021 10:18:48 +0800 Subject: [PATCH] Remove extra field. --- src/clients/storage/StorageClientBase-inl.h | 1 - src/interface/storage.thrift | 3 +-- src/mock/MockCluster.h | 4 +--- src/storage/exec/ScanNode.h | 6 ------ src/storage/query/ScanEdgeProcessor.cpp | 16 +++++++++------- src/storage/query/ScanVertexProcessor.cpp | 16 +++++++++------- src/storage/test/ScanEdgeTest.cpp | 9 +++++---- src/storage/test/ScanVertexTest.cpp | 9 +++++---- 8 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/clients/storage/StorageClientBase-inl.h b/src/clients/storage/StorageClientBase-inl.h index 79435d2252a..dd319fcc9f6 100644 --- a/src/clients/storage/StorageClientBase-inl.h +++ b/src/clients/storage/StorageClientBase-inl.h @@ -357,7 +357,6 @@ StorageClientBase::getHostPartsWithCursor(GraphSpaceID spaceId) cons // TODO support cursor cpp2::ScanCursor c; - c.set_has_next(false); auto parts = status.value(); for (auto partId = 1; partId <= parts; partId++) { auto leader = getLeader(spaceId, partId); diff --git a/src/interface/storage.thrift b/src/interface/storage.thrift index 98c884b5485..51dcdc11aca 100644 --- a/src/interface/storage.thrift +++ b/src/interface/storage.thrift @@ -561,9 +561,8 @@ struct LookupAndTraverseRequest { */ struct ScanCursor { - 3: bool has_next, // next start key of scan, only valid when has_next is true - 4: optional binary next_cursor, + 1: optional binary next_cursor, } struct ScanVertexRequest { diff --git a/src/mock/MockCluster.h b/src/mock/MockCluster.h index 8548a0e51f4..cd8d565a445 100644 --- a/src/mock/MockCluster.h +++ b/src/mock/MockCluster.h @@ -41,9 +41,7 @@ class MockCluster { void startMeta(const std::string& rootPath, HostAddr addr = HostAddr("127.0.0.1", 0)); - void startStorage(HostAddr addr, - const std::string& rootPath, - SchemaVer schemaVerCount = 1); + void startStorage(HostAddr addr, const std::string& rootPath, SchemaVer schemaVerCount = 1); /** * Init a meta client connect to current meta server. diff --git a/src/storage/exec/ScanNode.h b/src/storage/exec/ScanNode.h index 22425dcb90b..6602752b5c2 100644 --- a/src/storage/exec/ScanNode.h +++ b/src/storage/exec/ScanNode.h @@ -92,10 +92,7 @@ class ScanVertexPropNode : public QueryNode { cpp2::ScanCursor c; if (iter->valid()) { - c.set_has_next(true); c.set_next_cursor(iter->key().str()); - } else { - c.set_has_next(false); } cursors_->emplace(partId, std::move(c)); return nebula::cpp2::ErrorCode::SUCCEEDED; @@ -246,10 +243,7 @@ class ScanEdgePropNode : public QueryNode { cpp2::ScanCursor c; if (iter->valid()) { - c.set_has_next(true); c.set_next_cursor(iter->key().str()); - } else { - c.set_has_next(false); } cursors_->emplace(partId, std::move(c)); return nebula::cpp2::ErrorCode::SUCCEEDED; diff --git a/src/storage/query/ScanEdgeProcessor.cpp b/src/storage/query/ScanEdgeProcessor.cpp index 94a6a03a1b2..5e2bc02c43e 100644 --- a/src/storage/query/ScanEdgeProcessor.cpp +++ b/src/storage/query/ScanEdgeProcessor.cpp @@ -135,7 +135,8 @@ void ScanEdgeProcessor::runInSingleThread(const cpp2::ScanEdgeRequest& req) { auto partId = partEntry.first; auto cursor = partEntry.second; - auto ret = plan.go(partId, cursor.get_has_next() ? *cursor.get_next_cursor() : ""); + auto ret = plan.go( + partId, cursor.next_cursor_ref().has_value() ? cursor.next_cursor_ref().value() : ""); if (ret != nebula::cpp2::ErrorCode::SUCCEEDED && failedParts.find(partId) == failedParts.end()) { failedParts.emplace(partId); @@ -157,12 +158,13 @@ void ScanEdgeProcessor::runInMultipleThread(const cpp2::ScanEdgeRequest& req) { size_t i = 0; std::vector>> futures; for (const auto& [partId, cursor] : req.get_parts()) { - futures.emplace_back(runInExecutor(&contexts_[i], - &results_[i], - &cursorsOfPart_[i], - partId, - cursor.get_has_next() ? *cursor.get_next_cursor() : "", - &expCtxs_[i])); + futures.emplace_back( + runInExecutor(&contexts_[i], + &results_[i], + &cursorsOfPart_[i], + partId, + cursor.next_cursor_ref().has_value() ? cursor.next_cursor_ref().value() : "", + &expCtxs_[i])); i++; } diff --git a/src/storage/query/ScanVertexProcessor.cpp b/src/storage/query/ScanVertexProcessor.cpp index bb9b3a705ad..cf1e4058f77 100644 --- a/src/storage/query/ScanVertexProcessor.cpp +++ b/src/storage/query/ScanVertexProcessor.cpp @@ -137,7 +137,8 @@ void ScanVertexProcessor::runInSingleThread(const cpp2::ScanVertexRequest& req) auto partId = partEntry.first; auto cursor = partEntry.second; - auto ret = plan.go(partId, cursor.get_has_next() ? *cursor.get_next_cursor() : ""); + auto ret = plan.go( + partId, cursor.next_cursor_ref().has_value() ? cursor.next_cursor_ref().value() : ""); if (ret != nebula::cpp2::ErrorCode::SUCCEEDED && failedParts.find(partId) == failedParts.end()) { failedParts.emplace(partId); @@ -159,12 +160,13 @@ void ScanVertexProcessor::runInMultipleThread(const cpp2::ScanVertexRequest& req size_t i = 0; std::vector>> futures; for (const auto& [partId, cursor] : req.get_parts()) { - futures.emplace_back(runInExecutor(&contexts_[i], - &results_[i], - &cursorsOfPart_[i], - partId, - cursor.get_has_next() ? *cursor.get_next_cursor() : "", - &expCtxs_[i])); + futures.emplace_back( + runInExecutor(&contexts_[i], + &results_[i], + &cursorsOfPart_[i], + partId, + cursor.next_cursor_ref().has_value() ? cursor.next_cursor_ref().value() : "", + &expCtxs_[i])); i++; } diff --git a/src/storage/test/ScanEdgeTest.cpp b/src/storage/test/ScanEdgeTest.cpp index 381b0df6c33..af6a9a1b282 100644 --- a/src/storage/test/ScanEdgeTest.cpp +++ b/src/storage/test/ScanEdgeTest.cpp @@ -27,8 +27,9 @@ cpp2::ScanEdgeRequest buildRequest(std::vector partIds, CHECK_EQ(partIds.size(), cursors.size()); std::unordered_map parts; for (std::size_t i = 0; i < partIds.size(); ++i) { - c.set_has_next(!cursors[i].empty()); - c.set_next_cursor(cursors[i]); + if (!cursors[i].empty()) { + c.set_next_cursor(cursors[i]); + } parts.emplace(partIds[i], c); } req.set_parts(std::move(parts)); @@ -163,7 +164,7 @@ TEST(ScanEdgeTest, CursorTest) { ASSERT_EQ(0, resp.result.failed_parts.size()); checkResponse(*resp.edge_data_ref(), edge, edge.second.size(), totalRowCount); - hasNext = resp.get_cursors().at(partId).get_has_next(); + hasNext = resp.get_cursors().at(partId).next_cursor_ref().has_value(); if (hasNext) { CHECK(resp.get_cursors().at(partId).next_cursor_ref().has_value()); cursor = *resp.get_cursors().at(partId).next_cursor_ref(); @@ -190,7 +191,7 @@ TEST(ScanEdgeTest, CursorTest) { ASSERT_EQ(0, resp.result.failed_parts.size()); checkResponse(*resp.edge_data_ref(), edge, edge.second.size(), totalRowCount); - hasNext = resp.get_cursors().at(partId).get_has_next(); + hasNext = resp.get_cursors().at(partId).next_cursor_ref().has_value(); if (hasNext) { CHECK(resp.get_cursors().at(partId).next_cursor_ref().has_value()); cursor = *resp.get_cursors().at(partId).next_cursor_ref(); diff --git a/src/storage/test/ScanVertexTest.cpp b/src/storage/test/ScanVertexTest.cpp index ea972dd39e6..457483f32dd 100644 --- a/src/storage/test/ScanVertexTest.cpp +++ b/src/storage/test/ScanVertexTest.cpp @@ -28,8 +28,9 @@ cpp2::ScanVertexRequest buildRequest( CHECK_EQ(partIds.size(), cursors.size()); std::unordered_map parts; for (std::size_t i = 0; i < partIds.size(); ++i) { - c.set_has_next(!cursors[i].empty()); - c.set_next_cursor(cursors[i]); + if (!cursors[i].empty()) { + c.set_next_cursor(cursors[i]); + } parts.emplace(partIds[i], c); } req.set_parts(std::move(parts)); @@ -184,7 +185,7 @@ TEST(ScanVertexTest, CursorTest) { ASSERT_EQ(0, resp.result.failed_parts.size()); checkResponse( *resp.vertex_data_ref(), tag, tag.second.size() + 1 /* kVid */, totalRowCount); - hasNext = resp.get_cursors().at(partId).get_has_next(); + hasNext = resp.get_cursors().at(partId).next_cursor_ref().has_value(); if (hasNext) { CHECK(resp.get_cursors().at(partId).next_cursor_ref()); cursor = *resp.get_cursors().at(partId).next_cursor_ref(); @@ -211,7 +212,7 @@ TEST(ScanVertexTest, CursorTest) { ASSERT_EQ(0, resp.result.failed_parts.size()); checkResponse( *resp.vertex_data_ref(), tag, tag.second.size() + 1 /* kVid */, totalRowCount); - hasNext = resp.get_cursors().at(partId).get_has_next(); + hasNext = resp.get_cursors().at(partId).next_cursor_ref().has_value(); if (hasNext) { CHECK(resp.get_cursors().at(partId).next_cursor_ref()); cursor = *resp.get_cursors().at(partId).next_cursor_ref();