2021-10-22 07:24:39 +08:00
|
|
|
/*
|
|
|
|
* BlobRangeCommand.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-03-22 04:36:23 +08:00
|
|
|
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
2021-10-22 07:24:39 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fdbcli/fdbcli.actor.h"
|
|
|
|
|
|
|
|
#include "fdbclient/FDBOptions.g.h"
|
|
|
|
#include "fdbclient/IClientApi.h"
|
|
|
|
#include "fdbclient/ManagementAPI.actor.h"
|
2022-08-04 18:21:06 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
2021-10-22 07:24:39 +08:00
|
|
|
|
|
|
|
#include "flow/Arena.h"
|
|
|
|
#include "flow/FastRef.h"
|
|
|
|
#include "flow/ThreadHelper.actor.h"
|
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2022-07-29 23:20:45 +08:00
|
|
|
ACTOR Future<Version> getLatestReadVersion(Database db) {
|
|
|
|
state Transaction tr(db);
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
Version rv = wait(tr.getReadVersion());
|
|
|
|
fmt::print("Resolved latest read version as {0}\n", rv);
|
|
|
|
return rv;
|
|
|
|
} catch (Error& e) {
|
|
|
|
wait(tr.onError(e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// print after delay if not cancelled
|
|
|
|
ACTOR Future<Void> printAfterDelay(double delaySeconds, std::string message) {
|
|
|
|
wait(delay(delaySeconds));
|
|
|
|
fmt::print("{}\n", message);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2023-05-10 02:41:58 +08:00
|
|
|
ACTOR Future<Void> doBlobPurge(Database db,
|
|
|
|
Optional<Reference<Tenant>> tenant,
|
|
|
|
Key startKey,
|
|
|
|
Key endKey,
|
|
|
|
Optional<Version> version,
|
|
|
|
bool force) {
|
2022-07-29 23:20:45 +08:00
|
|
|
state Version purgeVersion;
|
|
|
|
if (version.present()) {
|
|
|
|
purgeVersion = version.get();
|
|
|
|
} else {
|
|
|
|
wait(store(purgeVersion, getLatestReadVersion(db)));
|
|
|
|
}
|
|
|
|
|
2023-05-10 02:41:58 +08:00
|
|
|
state Key purgeKey =
|
|
|
|
wait(db->purgeBlobGranules(KeyRange(KeyRangeRef(startKey, endKey)), purgeVersion, tenant, force));
|
2022-07-29 23:20:45 +08:00
|
|
|
|
|
|
|
fmt::print("Blob purge registered for [{0} - {1}) @ {2}\n", startKey.printable(), endKey.printable(), purgeVersion);
|
|
|
|
|
|
|
|
state Future<Void> printWarningActor = printAfterDelay(
|
|
|
|
5.0, "Waiting for purge to complete. (interrupting this wait with CTRL+C will not cancel the purge)");
|
|
|
|
wait(db->waitPurgeGranulesComplete(purgeKey));
|
|
|
|
|
|
|
|
fmt::print("Blob purge complete for [{0} - {1}) @ {2}\n", startKey.printable(), endKey.printable(), purgeVersion);
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2023-05-10 02:41:58 +08:00
|
|
|
ACTOR Future<Void> doBlobCheck(Database db,
|
|
|
|
Optional<Reference<Tenant>> tenant,
|
|
|
|
Key startKey,
|
|
|
|
Key endKey,
|
|
|
|
Optional<Version> version) {
|
2022-08-09 23:26:28 +08:00
|
|
|
state double elapsed = -timer_monotonic();
|
2022-08-04 07:11:25 +08:00
|
|
|
|
2023-05-10 02:41:58 +08:00
|
|
|
state Version readVersionOut = wait(db->verifyBlobRange(KeyRangeRef(startKey, endKey), version, tenant));
|
2022-08-04 07:11:25 +08:00
|
|
|
|
|
|
|
elapsed += timer_monotonic();
|
|
|
|
|
2022-07-29 23:20:45 +08:00
|
|
|
fmt::print("Blob check complete for [{0} - {1}) @ {2} in {3:.6f} seconds\n",
|
|
|
|
startKey.printable(),
|
|
|
|
endKey.printable(),
|
|
|
|
readVersionOut,
|
|
|
|
elapsed);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2023-05-10 02:41:58 +08:00
|
|
|
ACTOR Future<Void> doBlobFlush(Database db,
|
|
|
|
Optional<Reference<Tenant>> tenant,
|
|
|
|
Key startKey,
|
|
|
|
Key endKey,
|
|
|
|
Optional<Version> version,
|
|
|
|
bool compact) {
|
2023-02-21 00:28:11 +08:00
|
|
|
state double elapsed = -timer_monotonic();
|
|
|
|
state KeyRange keyRange(KeyRangeRef(startKey, endKey));
|
2023-05-10 02:41:58 +08:00
|
|
|
bool result = wait(db->flushBlobRange(keyRange, compact, version, tenant));
|
2023-02-21 00:28:11 +08:00
|
|
|
elapsed += timer_monotonic();
|
2023-01-31 05:00:57 +08:00
|
|
|
|
2023-02-21 00:28:11 +08:00
|
|
|
fmt::print("Blob Flush [{0} - {1}) {2} in {3:.6f} seconds\n",
|
|
|
|
startKey.printable(),
|
|
|
|
endKey.printable(),
|
|
|
|
result ? "succeeded" : "failed",
|
|
|
|
elapsed);
|
2023-01-31 05:00:57 +08:00
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-10-22 07:24:39 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace fdb_cli {
|
|
|
|
|
2022-02-20 07:25:51 +08:00
|
|
|
ACTOR Future<bool> blobRangeCommandActor(Database localDb,
|
|
|
|
Optional<TenantMapEntry> tenantEntry,
|
|
|
|
std::vector<StringRef> tokens) {
|
2021-10-22 07:24:39 +08:00
|
|
|
// enables blob writing for the given range
|
2022-07-29 23:20:45 +08:00
|
|
|
if (tokens.size() != 4 && tokens.size() != 5) {
|
2021-10-22 07:24:39 +08:00
|
|
|
printUsage(tokens[0]);
|
|
|
|
return false;
|
2022-02-20 07:25:51 +08:00
|
|
|
}
|
|
|
|
|
2023-05-10 02:41:58 +08:00
|
|
|
Optional<Reference<Tenant>> tenant;
|
2022-02-20 07:25:51 +08:00
|
|
|
if (tenantEntry.present()) {
|
2023-05-10 02:41:58 +08:00
|
|
|
tenant = Reference<Tenant>(new Tenant(tenantEntry.get().id));
|
2022-02-20 07:25:51 +08:00
|
|
|
}
|
|
|
|
|
2023-05-10 02:41:58 +08:00
|
|
|
Key begin = tokens[2];
|
|
|
|
Key end = tokens[3];
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
if (end > "\xff"_sr) {
|
2021-10-22 07:24:39 +08:00
|
|
|
// TODO is this something we want?
|
2022-07-29 23:20:45 +08:00
|
|
|
fmt::print("Cannot blobbify system keyspace! Problematic End Key: {0}\n", tokens[3].printable());
|
2021-10-22 07:24:39 +08:00
|
|
|
return false;
|
|
|
|
} else if (tokens[2] >= tokens[3]) {
|
2022-07-29 23:20:45 +08:00
|
|
|
fmt::print("Invalid blob range [{0} - {1})\n", tokens[2].printable(), tokens[3].printable());
|
2021-10-22 07:24:39 +08:00
|
|
|
} else {
|
2022-07-29 23:20:45 +08:00
|
|
|
if (tokencmp(tokens[1], "start") || tokencmp(tokens[1], "stop")) {
|
2022-08-04 19:00:23 +08:00
|
|
|
state bool starting = tokencmp(tokens[1], "start");
|
2022-07-29 23:20:45 +08:00
|
|
|
if (tokens.size() > 4) {
|
|
|
|
printUsage(tokens[0]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fmt::print("{0} blobbify range for [{1} - {2})\n",
|
|
|
|
starting ? "Starting" : "Stopping",
|
2022-09-03 06:41:31 +08:00
|
|
|
tokens[2].printable(),
|
|
|
|
tokens[3].printable());
|
2022-08-04 19:00:23 +08:00
|
|
|
state bool success = false;
|
2022-08-04 18:21:06 +08:00
|
|
|
if (starting) {
|
2023-05-10 02:41:58 +08:00
|
|
|
wait(store(success, localDb->blobbifyRange(KeyRangeRef(begin, end), tenant)));
|
2022-08-04 18:21:06 +08:00
|
|
|
} else {
|
2023-05-10 02:41:58 +08:00
|
|
|
wait(store(success, localDb->unblobbifyRange(KeyRangeRef(begin, end), tenant)));
|
2022-08-04 18:21:06 +08:00
|
|
|
}
|
2022-09-03 00:03:21 +08:00
|
|
|
if (success) {
|
2022-09-03 06:41:31 +08:00
|
|
|
fmt::print("{0} updated blob range [{1} - {2}) succeeded\n",
|
|
|
|
starting ? "Starting" : "Stopping",
|
|
|
|
tokens[2].printable(),
|
|
|
|
tokens[3].printable());
|
2022-09-03 00:03:21 +08:00
|
|
|
} else {
|
2022-08-04 19:00:23 +08:00
|
|
|
fmt::print("{0} blobbify range for [{1} - {2}) failed\n",
|
|
|
|
starting ? "Starting" : "Stopping",
|
2022-09-03 06:41:31 +08:00
|
|
|
tokens[2].printable(),
|
|
|
|
tokens[3].printable());
|
2022-08-04 19:00:23 +08:00
|
|
|
}
|
|
|
|
return success;
|
2023-01-31 05:00:57 +08:00
|
|
|
} else if (tokencmp(tokens[1], "purge") || tokencmp(tokens[1], "forcepurge") || tokencmp(tokens[1], "check") ||
|
|
|
|
tokencmp(tokens[1], "flush") || tokencmp(tokens[1], "compact")) {
|
2022-08-12 06:22:32 +08:00
|
|
|
bool purge = tokencmp(tokens[1], "purge") || tokencmp(tokens[1], "forcepurge");
|
|
|
|
bool forcePurge = tokencmp(tokens[1], "forcepurge");
|
2022-07-29 23:20:45 +08:00
|
|
|
|
|
|
|
Optional<Version> version;
|
|
|
|
if (tokens.size() > 4) {
|
|
|
|
Version v;
|
|
|
|
int n = 0;
|
|
|
|
if (sscanf(tokens[4].toString().c_str(), "%" PRId64 "%n", &v, &n) != 1 || n != tokens[4].size()) {
|
|
|
|
printUsage(tokens[0]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
version = v;
|
|
|
|
}
|
|
|
|
|
2022-08-12 06:22:32 +08:00
|
|
|
fmt::print("{0} blob range [{1} - {2}){3}",
|
2023-05-10 02:41:58 +08:00
|
|
|
tokens[1].printable(),
|
2022-07-29 23:20:45 +08:00
|
|
|
tokens[2].printable(),
|
2022-08-12 06:22:32 +08:00
|
|
|
tokens[3].printable(),
|
|
|
|
forcePurge ? " (force)" : "");
|
2022-07-29 23:20:45 +08:00
|
|
|
if (version.present()) {
|
|
|
|
fmt::print(" @ {0}", version.get());
|
|
|
|
}
|
|
|
|
fmt::print("\n");
|
|
|
|
|
|
|
|
if (purge) {
|
2023-05-10 02:41:58 +08:00
|
|
|
wait(doBlobPurge(localDb, tenant, begin, end, version, forcePurge));
|
2022-07-29 23:20:45 +08:00
|
|
|
} else {
|
2023-01-31 05:00:57 +08:00
|
|
|
if (tokencmp(tokens[1], "check")) {
|
2023-05-10 02:41:58 +08:00
|
|
|
wait(doBlobCheck(localDb, tenant, begin, end, version));
|
2023-01-31 05:00:57 +08:00
|
|
|
} else if (tokencmp(tokens[1], "flush")) {
|
2023-05-10 02:41:58 +08:00
|
|
|
wait(doBlobFlush(localDb, tenant, begin, end, version, false));
|
2023-01-31 05:00:57 +08:00
|
|
|
} else if (tokencmp(tokens[1], "compact")) {
|
2023-05-10 02:41:58 +08:00
|
|
|
wait(doBlobFlush(localDb, tenant, begin, end, version, true));
|
2023-01-31 05:00:57 +08:00
|
|
|
} else {
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
2022-07-29 23:20:45 +08:00
|
|
|
}
|
2021-10-22 07:24:39 +08:00
|
|
|
} else {
|
|
|
|
printUsage(tokens[0]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-12 06:22:32 +08:00
|
|
|
CommandFactory blobRangeFactory(
|
|
|
|
"blobrange",
|
2023-01-31 05:00:57 +08:00
|
|
|
CommandHelp("blobrange <start|stop|check|purge|forcepurge|flush|compact> <startkey> <endkey> [version]", "", ""));
|
2021-10-22 07:24:39 +08:00
|
|
|
} // namespace fdb_cli
|