Skip to content

Commit d18cff8

Browse files
committed
gRPC: Implement a subset of fdbcli as gRPC service
1 parent 8b7ac8a commit d18cff8

26 files changed

+2388
-141
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,5 @@ temp/
108108
/.ccls-cache
109109
.clangd/
110110
.stignore
111+
112+
/tests/loopback_cluster/

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ include(GetMsgpack)
211211
add_subdirectory(contrib)
212212
add_subdirectory(flow)
213213
add_subdirectory(fdbrpc)
214+
add_subdirectory(fdbcli_lib)
214215
add_subdirectory(fdbclient)
215216
add_subdirectory(fdbserver)
216217
add_subdirectory(fdbcli)

fdbcli/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ fdb_find_sources(FDBCLI_SRCS)
33

44
add_flow_target(EXECUTABLE NAME fdbcli SRCS ${FDBCLI_SRCS})
55
target_include_directories(fdbcli PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include")
6-
target_link_libraries(fdbcli PRIVATE fdbclient metacluster SimpleOpt)
6+
target_link_libraries(fdbcli PRIVATE fdbcli_lib fdbclient metacluster SimpleOpt)
7+
78
if (USE_UBSAN)
89
# The intent is to put typeinfo symbols in the dynamic symbol table so that
910
# the types in fdbcli and external libfdb_c clients agree for ubsan's vptr

fdbcli/ExcludeCommand.actor.cpp

Lines changed: 7 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "fdbclient/Knobs.h"
2626
#include "fdbclient/ManagementAPI.actor.h"
2727
#include "fdbclient/Schemas.h"
28+
#include "fdbcli_lib/CliCommands.h"
2829

2930
#include "flow/Arena.h"
3031
#include "flow/FastRef.h"
@@ -85,107 +86,6 @@ ACTOR Future<bool> excludeServersAndLocalities(Reference<IDatabase> db,
8586
}
8687
}
8788

88-
ACTOR Future<std::vector<std::string>> getExcludedServers(Reference<IDatabase> db) {
89-
state Reference<ITransaction> tr = db->createTransaction();
90-
loop {
91-
try {
92-
state ThreadFuture<RangeResult> resultFuture =
93-
tr->getRange(fdb_cli::excludedServersSpecialKeyRange, CLIENT_KNOBS->TOO_MANY);
94-
state RangeResult r = wait(safeThreadFutureToFuture(resultFuture));
95-
ASSERT(!r.more && r.size() < CLIENT_KNOBS->TOO_MANY);
96-
97-
std::vector<std::string> exclusions;
98-
for (const auto& i : r) {
99-
auto addr = i.key.removePrefix(fdb_cli::excludedServersSpecialKeyRange.begin).toString();
100-
exclusions.push_back(addr);
101-
}
102-
return exclusions;
103-
} catch (Error& e) {
104-
TraceEvent(SevWarn, "GetExcludedServersError").error(e);
105-
wait(safeThreadFutureToFuture(tr->onError(e)));
106-
}
107-
}
108-
}
109-
110-
// Get the list of excluded localities by reading the keys.
111-
ACTOR Future<std::vector<std::string>> getExcludedLocalities(Reference<IDatabase> db) {
112-
state Reference<ITransaction> tr = db->createTransaction();
113-
loop {
114-
try {
115-
state ThreadFuture<RangeResult> resultFuture =
116-
tr->getRange(fdb_cli::excludedLocalitySpecialKeyRange, CLIENT_KNOBS->TOO_MANY);
117-
state RangeResult r = wait(safeThreadFutureToFuture(resultFuture));
118-
ASSERT(!r.more && r.size() < CLIENT_KNOBS->TOO_MANY);
119-
120-
std::vector<std::string> excludedLocalities;
121-
for (const auto& i : r) {
122-
auto locality = i.key.removePrefix(fdb_cli::excludedLocalitySpecialKeyRange.begin).toString();
123-
excludedLocalities.push_back(locality);
124-
}
125-
return excludedLocalities;
126-
} catch (Error& e) {
127-
wait(safeThreadFutureToFuture(tr->onError(e)));
128-
}
129-
}
130-
}
131-
132-
ACTOR Future<std::vector<std::string>> getFailedServers(Reference<IDatabase> db) {
133-
state Reference<ITransaction> tr = db->createTransaction();
134-
loop {
135-
try {
136-
state ThreadFuture<RangeResult> resultFuture =
137-
tr->getRange(fdb_cli::failedServersSpecialKeyRange, CLIENT_KNOBS->TOO_MANY);
138-
state RangeResult r = wait(safeThreadFutureToFuture(resultFuture));
139-
ASSERT(!r.more && r.size() < CLIENT_KNOBS->TOO_MANY);
140-
141-
std::vector<std::string> exclusions;
142-
for (const auto& i : r) {
143-
auto addr = i.key.removePrefix(fdb_cli::failedServersSpecialKeyRange.begin).toString();
144-
exclusions.push_back(addr);
145-
}
146-
return exclusions;
147-
} catch (Error& e) {
148-
wait(safeThreadFutureToFuture(tr->onError(e)));
149-
}
150-
}
151-
}
152-
153-
// Get the list of failed localities by reading the keys.
154-
ACTOR Future<std::vector<std::string>> getFailedLocalities(Reference<IDatabase> db) {
155-
state Reference<ITransaction> tr = db->createTransaction();
156-
loop {
157-
try {
158-
state ThreadFuture<RangeResult> resultFuture =
159-
tr->getRange(fdb_cli::failedLocalitySpecialKeyRange, CLIENT_KNOBS->TOO_MANY);
160-
state RangeResult r = wait(safeThreadFutureToFuture(resultFuture));
161-
ASSERT(!r.more && r.size() < CLIENT_KNOBS->TOO_MANY);
162-
163-
std::vector<std::string> excludedLocalities;
164-
for (const auto& i : r) {
165-
auto locality = i.key.removePrefix(fdb_cli::failedLocalitySpecialKeyRange.begin).toString();
166-
excludedLocalities.push_back(locality);
167-
}
168-
return excludedLocalities;
169-
} catch (Error& e) {
170-
TraceEvent(SevWarn, "GetExcludedLocalitiesError").error(e);
171-
wait(safeThreadFutureToFuture(tr->onError(e)));
172-
}
173-
}
174-
}
175-
176-
ACTOR Future<std::set<NetworkAddress>> getInProgressExclusion(Reference<ITransaction> tr) {
177-
ThreadFuture<RangeResult> resultFuture =
178-
tr->getRange(fdb_cli::exclusionInProgressSpecialKeyRange, CLIENT_KNOBS->TOO_MANY);
179-
RangeResult result = wait(safeThreadFutureToFuture(resultFuture));
180-
ASSERT(!result.more && result.size() < CLIENT_KNOBS->TOO_MANY);
181-
std::set<NetworkAddress> inProgressExclusion;
182-
for (const auto& addr : result) {
183-
inProgressExclusion.insert(
184-
NetworkAddress::parse(addr.key.removePrefix(fdb_cli::exclusionInProgressSpecialKeyRange.begin).toString()));
185-
}
186-
return inProgressExclusion;
187-
}
188-
18989
ACTOR Future<std::set<NetworkAddress>> checkForExcludingServers(Reference<IDatabase> db,
19090
std::set<AddressExclusion> exclusions,
19191
bool waitForAllExcluded) {
@@ -196,7 +96,7 @@ ACTOR Future<std::set<NetworkAddress>> checkForExcludingServers(Reference<IDatab
19696
loop {
19797
inProgressExclusion.clear();
19898
try {
199-
std::set<NetworkAddress> result = wait(getInProgressExclusion(tr));
99+
std::set<NetworkAddress> result = wait(fdbcli_lib::utils::getInProgressExclusion(tr));
200100
if (result.empty())
201101
return inProgressExclusion;
202102
inProgressExclusion = result;
@@ -281,15 +181,13 @@ const KeyRef excludedForceOptionSpecialKey = "\xff\xff/management/options/exclud
281181
const KeyRef failedForceOptionSpecialKey = "\xff\xff/management/options/failed/force"_sr;
282182
const KeyRef excludedLocalityForceOptionSpecialKey = "\xff\xff/management/options/excluded_locality/force"_sr;
283183
const KeyRef failedLocalityForceOptionSpecialKey = "\xff\xff/management/options/failed_locality/force"_sr;
284-
const KeyRangeRef exclusionInProgressSpecialKeyRange("\xff\xff/management/in_progress_exclusion/"_sr,
285-
"\xff\xff/management/in_progress_exclusion0"_sr);
286184

287185
ACTOR Future<bool> excludeCommandActor(Reference<IDatabase> db, std::vector<StringRef> tokens, Future<Void> warn) {
288186
if (tokens.size() <= 1) {
289-
state std::vector<std::string> excludedAddresses = wait(getExcludedServers(db));
290-
state std::vector<std::string> excludedLocalities = wait(getExcludedLocalities(db));
291-
state std::vector<std::string> failedAddresses = wait(getFailedServers(db));
292-
state std::vector<std::string> failedLocalities = wait(getFailedLocalities(db));
187+
state std::vector<std::string> excludedAddresses = wait(fdbcli_lib::utils::getExcludedServers(db));
188+
state std::vector<std::string> excludedLocalities = wait(fdbcli_lib::utils::getExcludedLocalities(db));
189+
state std::vector<std::string> failedAddresses = wait(fdbcli_lib::utils::getFailedServers(db));
190+
state std::vector<std::string> failedLocalities = wait(fdbcli_lib::utils::getFailedLocalities(db));
293191

294192
if (!excludedAddresses.size() && !excludedLocalities.size() && !failedAddresses.size() &&
295193
!failedLocalities.size()) {
@@ -327,7 +225,7 @@ ACTOR Future<bool> excludeCommandActor(Reference<IDatabase> db, std::vector<Stri
327225
printf("\n");
328226

329227
Reference<ITransaction> tr = db->createTransaction();
330-
std::set<NetworkAddress> inProgressExclusion = wait(getInProgressExclusion(tr));
228+
std::set<NetworkAddress> inProgressExclusion = wait(fdbcli_lib::utils::getInProgressExclusion(tr));
331229
printf("There are currently %zu processes for which exclusion is in progress:\n", inProgressExclusion.size());
332230
for (const auto& addr : inProgressExclusion) {
333231
printf("%s\n", addr.toString().c_str());

fdbcli/Util.actor.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
#include "fdbcli/fdbcli.actor.h"
22+
#include "fdbcli_lib/CliCommands.h"
2223
#include "fdbclient/ManagementAPI.actor.h"
2324
#include "fdbclient/Schemas.h"
2425
#include "fdbclient/Status.h"
@@ -55,20 +56,8 @@ void printLongDesc(StringRef command) {
5556
fprintf(stderr, "ERROR: Unknown command `%s'\n", command.toString().c_str());
5657
}
5758

58-
ACTOR Future<std::string> getSpecialKeysFailureErrorMessage(Reference<ITransaction> tr) {
59-
// hold the returned standalone object's memory
60-
state ThreadFuture<Optional<Value>> errorMsgF = tr->get(fdb_cli::errorMsgSpecialKey);
61-
Optional<Value> errorMsg = wait(safeThreadFutureToFuture(errorMsgF));
62-
// Error message should be present
63-
ASSERT(errorMsg.present());
64-
// Read the json string
65-
auto valueObj = readJSONStrictly(errorMsg.get().toString()).get_obj();
66-
// verify schema
67-
auto schema = readJSONStrictly(JSONSchemas::managementApiErrorSchema.toString()).get_obj();
68-
std::string errorStr;
69-
ASSERT(schemaMatch(schema, valueObj, errorStr, SevError, true));
70-
// return the error message
71-
return valueObj["message"].get_str();
59+
Future<std::string> getSpecialKeysFailureErrorMessage(Reference<ITransaction> tr) {
60+
return fdbcli_lib::utils::getSpecialKeysFailureErrorMessage(tr);
7261
}
7362

7463
void addInterfacesFromKVs(RangeResult& kvs,

fdbcli/include/fdbcli/fdbcli.actor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void printUsage(StringRef command);
151151
void printLongDesc(StringRef command);
152152
// Pre: tr failed with special_keys_api_failure error
153153
// Read the error message special key and return the message
154-
ACTOR Future<std::string> getSpecialKeysFailureErrorMessage(Reference<ITransaction> tr);
154+
Future<std::string> getSpecialKeysFailureErrorMessage(Reference<ITransaction> tr);
155155
// Using \xff\xff/worker_interfaces/ special key, get all worker interfaces.
156156
// A worker list will be returned from CC.
157157
// If verify, we will try to establish connections to all workers returned.

fdbcli_lib/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fdb_find_sources(FDBCLI_LIB_SRCS)
2+
3+
add_flow_target(STATIC_LIBRARY NAME fdbcli_lib
4+
SRCS ${FDBCLI_LIB_SRCS})
5+
target_include_directories(fdbcli_lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include")
6+
target_link_libraries(fdbcli_lib PRIVATE fdbclient)
7+
8+
if (WITH_GRPC)
9+
generate_grpc_protobuf(fdbcli_lib.cli_service protos/cli_service.proto)
10+
target_link_libraries(fdbcli_lib PUBLIC proto_fdbcli_lib_cli_service)
11+
endif()
12+
13+
if (USE_UBSAN)
14+
target_link_options(fdbcli_lib PRIVATE "-rdynamic")
15+
endif()

0 commit comments

Comments
 (0)