25
25
#include " fdbclient/Knobs.h"
26
26
#include " fdbclient/ManagementAPI.actor.h"
27
27
#include " fdbclient/Schemas.h"
28
+ #include " fdbcli_lib/CliCommands.h"
28
29
29
30
#include " flow/Arena.h"
30
31
#include " flow/FastRef.h"
@@ -85,107 +86,6 @@ ACTOR Future<bool> excludeServersAndLocalities(Reference<IDatabase> db,
85
86
}
86
87
}
87
88
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
-
189
89
ACTOR Future<std::set<NetworkAddress>> checkForExcludingServers (Reference<IDatabase> db,
190
90
std::set<AddressExclusion> exclusions,
191
91
bool waitForAllExcluded) {
@@ -196,7 +96,7 @@ ACTOR Future<std::set<NetworkAddress>> checkForExcludingServers(Reference<IDatab
196
96
loop {
197
97
inProgressExclusion.clear ();
198
98
try {
199
- std::set<NetworkAddress> result = wait (getInProgressExclusion (tr));
99
+ std::set<NetworkAddress> result = wait (fdbcli_lib::utils:: getInProgressExclusion (tr));
200
100
if (result.empty ())
201
101
return inProgressExclusion;
202
102
inProgressExclusion = result;
@@ -281,15 +181,13 @@ const KeyRef excludedForceOptionSpecialKey = "\xff\xff/management/options/exclud
281
181
const KeyRef failedForceOptionSpecialKey = " \xff\xff /management/options/failed/force" _sr;
282
182
const KeyRef excludedLocalityForceOptionSpecialKey = " \xff\xff /management/options/excluded_locality/force" _sr;
283
183
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);
286
184
287
185
ACTOR Future<bool > excludeCommandActor (Reference<IDatabase> db, std::vector<StringRef> tokens, Future<Void> warn) {
288
186
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));
293
191
294
192
if (!excludedAddresses.size () && !excludedLocalities.size () && !failedAddresses.size () &&
295
193
!failedLocalities.size ()) {
@@ -327,7 +225,7 @@ ACTOR Future<bool> excludeCommandActor(Reference<IDatabase> db, std::vector<Stri
327
225
printf (" \n " );
328
226
329
227
Reference<ITransaction> tr = db->createTransaction ();
330
- std::set<NetworkAddress> inProgressExclusion = wait (getInProgressExclusion (tr));
228
+ std::set<NetworkAddress> inProgressExclusion = wait (fdbcli_lib::utils:: getInProgressExclusion (tr));
331
229
printf (" There are currently %zu processes for which exclusion is in progress:\n " , inProgressExclusion.size ());
332
230
for (const auto & addr : inProgressExclusion) {
333
231
printf (" %s\n " , addr.toString ().c_str ());
0 commit comments