Skip to content

Commit 86e45df

Browse files
committed
Support white list
1 parent 29f52ae commit 86e45df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2832
-2093
lines changed

src/clients/meta/MetaClient.cpp

+48-15
Original file line numberDiff line numberDiff line change
@@ -3022,17 +3022,48 @@ void MetaClient::loadLeader(const std::vector<cpp2::HostItem>& hostItems,
30223022
}
30233023
}
30243024

3025-
folly::Future<StatusOr<bool>> MetaClient::addZone(std::string zoneName,
3026-
std::vector<HostAddr> nodes) {
3027-
cpp2::AddZoneReq req;
3028-
req.set_zone_name(std::move(zoneName));
3029-
req.set_nodes(std::move(nodes));
3025+
folly::Future<StatusOr<bool>> MetaClient::addHosts(std::vector<HostAddr> hosts) {
3026+
cpp2::AddHostsReq req;
3027+
req.set_hosts(std::move(hosts));
3028+
3029+
folly::Promise<StatusOr<bool>> promise;
3030+
auto future = promise.getFuture();
3031+
getResponse(
3032+
std::move(req),
3033+
[](auto client, auto request) { return client->future_addHosts(request); },
3034+
[](cpp2::ExecResp&& resp) -> bool {
3035+
return resp.get_code() == nebula::cpp2::ErrorCode::SUCCEEDED;
3036+
},
3037+
std::move(promise));
3038+
return future;
3039+
}
3040+
3041+
folly::Future<StatusOr<bool>> MetaClient::dropHosts(std::vector<HostAddr> hosts) {
3042+
cpp2::DropHostsReq req;
3043+
req.set_hosts(std::move(hosts));
3044+
3045+
folly::Promise<StatusOr<bool>> promise;
3046+
auto future = promise.getFuture();
3047+
getResponse(
3048+
std::move(req),
3049+
[](auto client, auto request) { return client->future_dropHosts(request); },
3050+
[](cpp2::ExecResp&& resp) -> bool {
3051+
return resp.get_code() == nebula::cpp2::ErrorCode::SUCCEEDED;
3052+
},
3053+
std::move(promise));
3054+
return future;
3055+
}
30303056

3057+
folly::Future<StatusOr<bool>> MetaClient::mergeZone(std::vector<std::string> zones,
3058+
std::string zoneName) {
3059+
cpp2::MergeZoneReq req;
3060+
req.set_zone_name(zoneName);
3061+
req.set_zones(zones);
30313062
folly::Promise<StatusOr<bool>> promise;
30323063
auto future = promise.getFuture();
30333064
getResponse(
30343065
std::move(req),
3035-
[](auto client, auto request) { return client->future_addZone(request); },
3066+
[](auto client, auto request) { return client->future_mergeZone(request); },
30363067
[](cpp2::ExecResp&& resp) -> bool {
30373068
return resp.get_code() == nebula::cpp2::ErrorCode::SUCCEEDED;
30383069
},
@@ -3056,33 +3087,35 @@ folly::Future<StatusOr<bool>> MetaClient::dropZone(std::string zoneName) {
30563087
return future;
30573088
}
30583089

3059-
folly::Future<StatusOr<bool>> MetaClient::addHostIntoZone(HostAddr node, std::string zoneName) {
3060-
cpp2::AddHostIntoZoneReq req;
3061-
req.set_node(node);
3090+
folly::Future<StatusOr<bool>> MetaClient::splitZone(
3091+
std::string zoneName, std::unordered_map<std::string, std::vector<HostAddr>>) {
3092+
cpp2::SplitZoneReq req;
30623093
req.set_zone_name(zoneName);
3063-
30643094
folly::Promise<StatusOr<bool>> promise;
30653095
auto future = promise.getFuture();
30663096
getResponse(
30673097
std::move(req),
3068-
[](auto client, auto request) { return client->future_addHostIntoZone(request); },
3098+
[](auto client, auto request) { return client->future_splitZone(request); },
30693099
[](cpp2::ExecResp&& resp) -> bool {
30703100
return resp.get_code() == nebula::cpp2::ErrorCode::SUCCEEDED;
30713101
},
30723102
std::move(promise));
30733103
return future;
30743104
}
30753105

3076-
folly::Future<StatusOr<bool>> MetaClient::dropHostFromZone(HostAddr node, std::string zoneName) {
3077-
cpp2::DropHostFromZoneReq req;
3078-
req.set_node(node);
3106+
folly::Future<StatusOr<bool>> MetaClient::addHostsIntoZone(std::vector<HostAddr> hosts,
3107+
std::string zoneName,
3108+
bool isNew) {
3109+
cpp2::AddHostsIntoZoneReq req;
3110+
req.set_hosts(hosts);
30793111
req.set_zone_name(zoneName);
3112+
req.set_is_new(isNew);
30803113

30813114
folly::Promise<StatusOr<bool>> promise;
30823115
auto future = promise.getFuture();
30833116
getResponse(
30843117
std::move(req),
3085-
[](auto client, auto request) { return client->future_dropHostFromZone(request); },
3118+
[](auto client, auto request) { return client->future_addHostsIntoZone(request); },
30863119
[](cpp2::ExecResp&& resp) -> bool {
30873120
return resp.get_code() == nebula::cpp2::ErrorCode::SUCCEEDED;
30883121
},

src/clients/meta/MetaClient.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -595,13 +595,20 @@ class MetaClient {
595595

596596
StatusOr<LeaderInfo> getLeaderInfo();
597597

598-
folly::Future<StatusOr<bool>> addZone(std::string zoneName, std::vector<HostAddr> nodes);
598+
folly::Future<StatusOr<bool>> addHosts(std::vector<HostAddr> hosts);
599+
600+
folly::Future<StatusOr<bool>> dropHosts(std::vector<HostAddr> hosts);
601+
602+
folly::Future<StatusOr<bool>> mergeZone(std::vector<std::string> zones, std::string zoneName);
599603

600604
folly::Future<StatusOr<bool>> dropZone(std::string zoneName);
601605

602-
folly::Future<StatusOr<bool>> addHostIntoZone(HostAddr node, std::string zoneName);
606+
folly::Future<StatusOr<bool>> splitZone(
607+
std::string zoneName, std::unordered_map<std::string, std::vector<HostAddr>> zones);
603608

604-
folly::Future<StatusOr<bool>> dropHostFromZone(HostAddr node, std::string zoneName);
609+
folly::Future<StatusOr<bool>> addHostsIntoZone(std::vector<HostAddr> hosts,
610+
std::string zoneName,
611+
bool isNew);
605612

606613
folly::Future<StatusOr<std::vector<HostAddr>>> getZone(std::string zoneName);
607614

src/common/utils/MetaKeyUtils.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace nebula {
2020
static const std::unordered_map<std::string, std::pair<std::string, bool>> systemTableMaps = {
2121
{"users", {"__users__", true}},
2222
{"hosts", {"__hosts__", false}},
23+
{"machines", {"__machines__", false}},
2324
{"snapshots", {"__snapshots__", false}},
2425
{"configs", {"__configs__", true}},
2526
{"groups", {"__groups__", true}},
@@ -56,7 +57,8 @@ static const std::unordered_map<
5657
// clang-format off
5758
static const std::string kSpacesTable = tableMaps.at("spaces").first; // NOLINT
5859
static const std::string kPartsTable = tableMaps.at("parts").first; // NOLINT
59-
static const std::string kHostsTable = systemTableMaps.at("hosts").first; // NOLINT
60+
static const std::string kHostsTable = systemTableMaps.at("hosts").first; // NOLINT
61+
static const std::string kMachinesTable = systemTableMaps.at("machines").first; // NOLINT
6062
static const std::string kTagsTable = tableMaps.at("tags").first; // NOLINT
6163
static const std::string kEdgesTable = tableMaps.at("edges").first; // NOLINT
6264
static const std::string kIndexesTable = tableMaps.at("indexes").first; // NOLINT
@@ -235,6 +237,21 @@ std::vector<HostAddr> MetaKeyUtils::parsePartValV2(folly::StringPiece val) {
235237
return ret;
236238
}
237239

240+
std::string MetaKeyUtils::machineKey(std::string addr, Port port) {
241+
std::string key;
242+
HostAddr h(addr, port);
243+
key.append(kMachinesTable.data(), kMachinesTable.size())
244+
.append(MetaKeyUtils::serializeHostAddr(h));
245+
return key;
246+
}
247+
248+
const std::string& MetaKeyUtils::machinePrefix() { return kMachinesTable; }
249+
250+
HostAddr MetaKeyUtils::parseMachineKey(folly::StringPiece key) {
251+
key.advance(kMachinesTable.size());
252+
return MetaKeyUtils::deserializeHostAddr(key);
253+
}
254+
238255
std::string MetaKeyUtils::hostKey(std::string addr, Port port) { return hostKeyV2(addr, port); }
239256

240257
std::string MetaKeyUtils::hostKeyV2(std::string addr, Port port) {

src/common/utils/MetaKeyUtils.h

+6
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class MetaKeyUtils final {
110110

111111
static std::vector<HostAddr> parsePartValV2(folly::StringPiece val);
112112

113+
static std::string machineKey(std::string ip, Port port);
114+
115+
static const std::string& machinePrefix();
116+
117+
static HostAddr parseMachineKey(folly::StringPiece key);
118+
113119
static std::string hostKey(std::string ip, Port port);
114120

115121
static std::string hostKeyV2(std::string addr, Port port);

src/common/utils/test/MetaKeyUtilsTest.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ TEST(MetaKeyUtilsTest, storeStrIpCodecTest) {
7575
}
7676
}
7777

78+
{
79+
// kMachinesTable : key
80+
auto key = MetaKeyUtils::machineKey(hostnames[0], ports[0]);
81+
auto host = MetaKeyUtils::parseMachineKey(key);
82+
ASSERT_EQ(host.host, hostnames[0]);
83+
ASSERT_EQ(host.port, ports[0]);
84+
}
7885
{
7986
// kHostsTable : key
8087
auto key = MetaKeyUtils::hostKey(hostnames[0], ports[0]);

src/graph/executor/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ nebula_add_library(
4242
algo/ProduceAllPathsExecutor.cpp
4343
algo/CartesianProductExecutor.cpp
4444
algo/SubgraphExecutor.cpp
45+
admin/AddHostsExecutor.cpp
46+
admin/DropHostsExecutor.cpp
4547
admin/SwitchSpaceExecutor.cpp
4648
admin/CreateUserExecutor.cpp
4749
admin/DropUserExecutor.cpp

src/graph/executor/Executor.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
#include "graph/context/ExecutionContext.h"
1717
#include "graph/context/QueryContext.h"
1818
#include "graph/executor/ExecutionError.h"
19+
#include "graph/executor/admin/AddHostsExecutor.h"
1920
#include "graph/executor/admin/ChangePasswordExecutor.h"
2021
#include "graph/executor/admin/CharsetExecutor.h"
2122
#include "graph/executor/admin/ConfigExecutor.h"
2223
#include "graph/executor/admin/CreateUserExecutor.h"
2324
#include "graph/executor/admin/DownloadExecutor.h"
25+
#include "graph/executor/admin/DropHostsExecutor.h"
2426
#include "graph/executor/admin/DropUserExecutor.h"
2527
#include "graph/executor/admin/GrantRoleExecutor.h"
2628
#include "graph/executor/admin/GroupExecutor.h"
@@ -431,6 +433,12 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) {
431433
case PlanNode::Kind::kSubgraph: {
432434
return pool->add(new SubgraphExecutor(node, qctx));
433435
}
436+
case PlanNode::Kind::kAddHosts: {
437+
return pool->add(new AddHostsExecutor(node, qctx));
438+
}
439+
case PlanNode::Kind::kDropHosts: {
440+
return pool->add(new DropHostsExecutor(node, qctx));
441+
}
434442
case PlanNode::Kind::kAddGroup: {
435443
return pool->add(new AddGroupExecutor(node, qctx));
436444
}
@@ -449,20 +457,20 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) {
449457
case PlanNode::Kind::kShowGroups: {
450458
return pool->add(new ListGroupsExecutor(node, qctx));
451459
}
452-
case PlanNode::Kind::kAddZone: {
453-
return pool->add(new AddZoneExecutor(node, qctx));
460+
case PlanNode::Kind::kMergeZone: {
461+
return pool->add(new MergeZoneExecutor(node, qctx));
454462
}
455463
case PlanNode::Kind::kDropZone: {
456464
return pool->add(new DropZoneExecutor(node, qctx));
457465
}
466+
case PlanNode::Kind::kSplitZone: {
467+
return pool->add(new SplitZoneExecutor(node, qctx));
468+
}
458469
case PlanNode::Kind::kDescribeZone: {
459470
return pool->add(new DescribeZoneExecutor(node, qctx));
460471
}
461-
case PlanNode::Kind::kAddHostIntoZone: {
462-
return pool->add(new AddHostIntoZoneExecutor(node, qctx));
463-
}
464-
case PlanNode::Kind::kDropHostFromZone: {
465-
return pool->add(new DropHostFromZoneExecutor(node, qctx));
472+
case PlanNode::Kind::kAddHostsIntoZone: {
473+
return pool->add(new AddHostsIntoZoneExecutor(node, qctx));
466474
}
467475
case PlanNode::Kind::kShowZones: {
468476
return pool->add(new ListZonesExecutor(node, qctx));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Copyright (c) 2021 vesoft inc. All rights reserved.
2+
*
3+
* This source code is licensed under Apache 2.0 License,
4+
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
5+
*/
6+
7+
#include "graph/executor/admin/AddHostsExecutor.h"
8+
9+
#include "graph/planner/plan/Admin.h"
10+
11+
namespace nebula {
12+
namespace graph {
13+
14+
folly::Future<Status> AddHostsExecutor::execute() {
15+
SCOPED_TIMER(&execTime_);
16+
auto *ahNode = asNode<AddHosts>(node());
17+
return qctx()
18+
->getMetaClient()
19+
->addHosts(ahNode->getHosts())
20+
.via(runner())
21+
.thenValue([this](StatusOr<bool> resp) {
22+
SCOPED_TIMER(&execTime_);
23+
NG_RETURN_IF_ERROR(resp);
24+
if (!resp.value()) {
25+
return Status::Error("Add Hosts failed!");
26+
}
27+
return Status::OK();
28+
});
29+
}
30+
31+
} // namespace graph
32+
} // namespace nebula
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Copyright (c) 2021 vesoft inc. All rights reserved.
2+
*
3+
* This source code is licensed under Apache 2.0 License,
4+
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
5+
*/
6+
7+
#ifndef GRAPH_EXECUTOR_ADMIN_ADD_HOST_EXECUTOR_H_
8+
#define GRAPH_EXECUTOR_ADMIN_ADD_HOST_EXECUTOR_H_
9+
10+
#include "graph/executor/Executor.h"
11+
12+
namespace nebula {
13+
namespace graph {
14+
15+
class AddHostsExecutor final : public Executor {
16+
public:
17+
AddHostsExecutor(const PlanNode *node, QueryContext *qctx)
18+
: Executor("AddHostsExecutor", node, qctx) {}
19+
20+
folly::Future<Status> execute() override;
21+
};
22+
23+
} // namespace graph
24+
} // namespace nebula
25+
26+
#endif // GRAPH_EXECUTOR_ADMIN_ADD_HOST_EXECUTOR_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Copyright (c) 2021 vesoft inc. All rights reserved.
2+
*
3+
* This source code is licensed under Apache 2.0 License,
4+
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
5+
*/
6+
7+
#include "graph/executor/admin/DropHostsExecutor.h"
8+
9+
#include "graph/planner/plan/Admin.h"
10+
11+
namespace nebula {
12+
namespace graph {
13+
14+
folly::Future<Status> DropHostsExecutor::execute() {
15+
auto *dhNode = asNode<DropHosts>(node());
16+
return qctx()
17+
->getMetaClient()
18+
->dropHosts(dhNode->getHosts())
19+
.via(runner())
20+
.thenValue([this](StatusOr<bool> resp) {
21+
SCOPED_TIMER(&execTime_);
22+
NG_RETURN_IF_ERROR(resp);
23+
if (!resp.value()) {
24+
return Status::Error("Drop Hosts failed!");
25+
}
26+
return Status::OK();
27+
});
28+
}
29+
30+
} // namespace graph
31+
} // namespace nebula
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Copyright (c) 2021 vesoft inc. All rights reserved.
2+
*
3+
* This source code is licensed under Apache 2.0 License,
4+
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
5+
*/
6+
7+
#ifndef GRAPH_EXECUTOR_ADMIN_DROP_HOST_EXECUTOR_H_
8+
#define GRAPH_EXECUTOR_ADMIN_DROP_HOST_EXECUTOR_H_
9+
10+
#include "graph/executor/Executor.h"
11+
12+
namespace nebula {
13+
namespace graph {
14+
15+
class DropHostsExecutor final : public Executor {
16+
public:
17+
DropHostsExecutor(const PlanNode *node, QueryContext *qctx)
18+
: Executor("DropHostsExecutor", node, qctx) {}
19+
20+
folly::Future<Status> execute() override;
21+
};
22+
23+
} // namespace graph
24+
} // namespace nebula
25+
26+
#endif // GRAPH_EXECUTOR_ADMIN_DROP_HOST_EXECUTOR_H_

src/graph/executor/admin/ShowHostsExecutor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ class ShowHostsExecutor final : public Executor {
2525
} // namespace graph
2626
} // namespace nebula
2727

28-
#endif
28+
#endif // GRAPH_EXECUTOR_ADMIN_SHOW_HOSTS_EXECUTOR_H_

0 commit comments

Comments
 (0)