|
@@ -24,6 +24,7 @@
|
|
|
#include <cstring>
|
|
#include <cstring>
|
|
|
#include <fstream>
|
|
#include <fstream>
|
|
|
#include <iterator>
|
|
#include <iterator>
|
|
|
|
|
+#include <chrono>
|
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
#include <sstream>
|
|
#include <sstream>
|
|
|
#include <string>
|
|
#include <string>
|
|
@@ -78,6 +79,9 @@ void printUsage() {
|
|
|
<< " " << C_CYAN << "unlock" << C_RESET << " Unlock database (accept writes)\n"
|
|
<< " " << C_CYAN << "unlock" << C_RESET << " Unlock database (accept writes)\n"
|
|
|
<< " " << C_CYAN << "status" << C_RESET << " Show read-only + recovery status\n"
|
|
<< " " << C_CYAN << "status" << C_RESET << " Show read-only + recovery status\n"
|
|
|
<< " " << C_CYAN << "server-info" << C_RESET << " Server version, commit and feature names (2.15.0+)\n"
|
|
<< " " << C_CYAN << "server-info" << C_RESET << " Server version, commit and feature names (2.15.0+)\n"
|
|
|
|
|
+ << " " << C_CYAN << "configure" << C_RESET << " <collection> [--versioning on|off] [--max-versions N]\n"
|
|
|
|
|
+ << " " << C_DIM << "versioning off stops NEW history; --max-versions N prunes existing history to the newest N" << C_RESET << "\n"
|
|
|
|
|
+ << " " << C_DIM << "per document (writes recording history in that collection wait while it runs)" << C_RESET << "\n"
|
|
|
<< " " << C_CYAN << "encryption-verify" << C_RESET << " [collection] Audit encryption at rest (exit 1 on any finding).\n"
|
|
<< " " << C_CYAN << "encryption-verify" << C_RESET << " [collection] Audit encryption at rest (exit 1 on any finding).\n"
|
|
|
<< " Against a 2.17.0 SERVER it stalls history-recording writes\n"
|
|
<< " Against a 2.17.0 SERVER it stalls history-recording writes\n"
|
|
|
<< " server-wide while it reads history; 2.17.1+ does not.\n"
|
|
<< " server-wide while it reads history; 2.17.1+ does not.\n"
|
|
@@ -637,6 +641,73 @@ bool execCommand(smartbotic::database::Client& client,
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // v2.18.1 - collection administration an operator could not reach
|
|
|
|
|
+ // from the CLI (asked by smartbotic-vectorapi before a production
|
|
|
|
|
+ // prune): versioning on/off, and maxVersions with its history prune.
|
|
|
|
|
+ if (cmd == "configure") {
|
|
|
|
|
+ if (params.size() < 3) {
|
|
|
|
|
+ printError("usage: configure <collection> [--versioning on|off] [--max-versions N]");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ const std::string coll = params[0];
|
|
|
|
|
+ std::optional<bool> versioning;
|
|
|
|
|
+ std::optional<uint32_t> maxVersions;
|
|
|
|
|
+ for (size_t i = 1; i < params.size(); ++i) {
|
|
|
|
|
+ if (params[i] == "--versioning" && i + 1 < params.size()) {
|
|
|
|
|
+ const std::string v = params[++i];
|
|
|
|
|
+ if (v != "on" && v != "off") { printError("--versioning takes on or off"); return false; }
|
|
|
|
|
+ versioning = (v == "on");
|
|
|
|
|
+ } else if (params[i] == "--max-versions" && i + 1 < params.size()) {
|
|
|
|
|
+ long long n = 0;
|
|
|
|
|
+ try { n = std::stoll(params[++i]); } catch (...) { n = -1; }
|
|
|
|
|
+ if (n < 1 || n > 1000000) {
|
|
|
|
|
+ printError("--max-versions takes 1..1000000. 0 means UNLIMITED history, not off: "
|
|
|
|
|
+ "to stop recording history use --versioning off");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ maxVersions = static_cast<uint32_t>(n);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ printError("unknown option " + params[i]);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!versioning && !maxVersions) { printError("nothing to change"); return false; }
|
|
|
|
|
+ const auto before = client.getCollectionInfo(coll);
|
|
|
|
|
+ if (!before) { printError("collection not found: " + coll); return false; }
|
|
|
|
|
+ if (versioning) {
|
|
|
|
|
+ smartbotic::database::Client::CollectionConfig cfg;
|
|
|
|
|
+ cfg.timestampPrecision = ""; // "" = leave precision unchanged
|
|
|
|
|
+ cfg.versioningEnabled = *versioning;
|
|
|
|
|
+ if (!client.configureCollection(coll, cfg)) { printError("configureCollection failed"); return false; }
|
|
|
|
|
+ std::cout << "versioning: " << (*versioning ? "on" : "OFF (no new history is recorded; "
|
|
|
|
|
+ "history already written stays, see --max-versions)") << "\n";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (maxVersions) {
|
|
|
|
|
+ // createCollection on an existing collection re-applies its
|
|
|
|
|
+ // options, and a default TTL of 0 is a real value: pass the
|
|
|
|
|
+ // current one back so the prune cannot clear it. encrypted=false
|
|
|
|
|
+ // never downgrades; a vector dimension of 0 is ignored.
|
|
|
|
|
+ const bool prunes = before->maxVersions == 0 || *maxVersions < before->maxVersions;
|
|
|
|
|
+ const auto t0 = std::chrono::steady_clock::now();
|
|
|
|
|
+ (void)client.createCollection(coll, before->defaultTtlSeconds, false, *maxVersions, 0);
|
|
|
|
|
+ const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
|
+ std::chrono::steady_clock::now() - t0).count();
|
|
|
|
|
+ const auto after = client.getCollectionInfo(coll);
|
|
|
|
|
+ std::cout << "max_versions: " << before->maxVersions
|
|
|
|
|
+ << (before->maxVersions == 0 ? " (unlimited)" : "") << " -> "
|
|
|
|
|
+ << (after ? after->maxVersions : *maxVersions) << "\n"
|
|
|
|
|
+ << "default_ttl_seconds kept: " << before->defaultTtlSeconds
|
|
|
|
|
+ << (after && after->defaultTtlSeconds != before->defaultTtlSeconds ? " ⚠ CHANGED" : "") << "\n"
|
|
|
|
|
+ << (prunes ? "history pruned to the newest " + std::to_string(*maxVersions) +
|
|
|
|
|
+ " version(s) per document"
|
|
|
|
|
+ : std::string("cap raised: nothing pruned"))
|
|
|
|
|
+ << " in " << ms << " ms\n"
|
|
|
|
|
+ << " (the history file's size is not visible over the API: compare "
|
|
|
|
|
+ "<data_directory>/history/<collection>.hlog before and after)\n";
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (cmd == "info") {
|
|
if (cmd == "info") {
|
|
|
if (params.empty()) { printError("usage: info <collection>"); return false; }
|
|
if (params.empty()) { printError("usage: info <collection>"); return false; }
|
|
|
auto info = client.getCollectionInfo(params[0]);
|
|
auto info = client.getCollectionInfo(params[0]);
|
|
@@ -645,9 +716,12 @@ bool execCommand(smartbotic::database::Client& client,
|
|
|
<< " documents: " << info->documentCount << "\n"
|
|
<< " documents: " << info->documentCount << "\n"
|
|
|
<< " size: " << info->sizeBytes << " bytes\n"
|
|
<< " size: " << info->sizeBytes << " bytes\n"
|
|
|
<< " encrypted: " << (info->encrypted ? "yes" : "no") << "\n"
|
|
<< " encrypted: " << (info->encrypted ? "yes" : "no") << "\n"
|
|
|
- << " max_versions: " << info->maxVersions << "\n";
|
|
|
|
|
- if (info->defaultTtlSeconds > 0)
|
|
|
|
|
- std::cout << " ttl: " << info->defaultTtlSeconds << "s\n";
|
|
|
|
|
|
|
+ << " max_versions: " << info->maxVersions
|
|
|
|
|
+ << (info->maxVersions == 0 ? " (unlimited)" : "") << "\n"
|
|
|
|
|
+ // v2.18.1 - always printed: `configure --max-versions`
|
|
|
|
|
+ // re-applies it, and an operator must be able to see it.
|
|
|
|
|
+ << " default_ttl_seconds: " << info->defaultTtlSeconds
|
|
|
|
|
+ << (info->defaultTtlSeconds == 0 ? " (none)" : "") << "\n";
|
|
|
// v2.11.4 - relations_enforced is not part of CollectionInfo (it
|
|
// v2.11.4 - relations_enforced is not part of CollectionInfo (it
|
|
|
// is a changeable setting, served by GetCollectionConfig), and
|
|
// is a changeable setting, served by GetCollectionConfig), and
|
|
|
// its absence here read as "the server cannot report it". Always
|
|
// its absence here read as "the server cannot report it". Always
|