Procházet zdrojové kódy

wip: 2.17.0 - the zeus-copy comparison tooling (dump, compare, driver)

Run inside packaging/dev.sh with a nightly backup extracted to build/zc/data
and build/zc/config.json pointing at it (port 9032); the scripts still use
the build/rt and build/zc paths they were developed with.
fszontagh před 1 měsícem
rodič
revize
8e8633ca0b

+ 22 - 0
tests/load_test/migration_copy/compare.py

@@ -0,0 +1,22 @@
+# Compare decrypted dumps: before (2.16.0, fresh), control (2.16.0 after its TTL
+# sweep), after (2.17.0 migrated), after2 (2.17.0 restarted).
+import sys
+from collections import Counter
+Z=sys.argv[1]
+def load(n):
+    d={}
+    for l in open(f"{Z}/{n}.tsv"):
+        if l.startswith('['): continue
+        k1,k2,body=l.rstrip('\n').split('\t',2)
+        d[(k1,k2)]=body
+    return d
+b,c,a,a2=(load(n) for n in ("before","control","after","after2"))
+def cmp(x,y,nx,ny):
+    common=set(x)&set(y)
+    diff=sum(1 for k in common if x[k]!=y[k])
+    only_x=[k for k in x if k not in y]; only_y=[k for k in y if k not in x]
+    print(f"{nx} vs {ny}: {len(x)} / {len(y)} docs, {len(common)} common, {diff} differing bodies, "
+          f"only in {nx}: {dict(Counter(k[0] for k in only_x))}, only in {ny}: {dict(Counter(k[0] for k in only_y))}")
+cmp(b,a,"before","after")
+cmp(c,a,"control","after")
+cmp(a,a2,"after","after2")

+ 33 - 0
tests/load_test/migration_copy/dump.cpp

@@ -0,0 +1,33 @@
+// Dump every document of every collection of every project, decrypted, sorted,
+// one JSON line each: "<project>:<collection>\t<id>\t<body>". For comparing a
+// data directory before and after the 2.17.0 at-rest migration.
+#include <smartbotic/database/client.hpp>
+#include <algorithm>
+#include <iostream>
+#include <map>
+using namespace smartbotic::database;
+int main(int argc, char** argv) {
+    const std::string addr = argv[1];
+    Client::Config base; base.address = addr; base.timeoutMs = 120000;
+    Client root(base); root.connect();
+    std::map<std::string, std::string> lines;
+    size_t colls = 0;
+    for (const auto& p : root.listProjects()) {
+        Client::Config cfg = base; cfg.project = p;
+        Client c(cfg); c.connect();
+        for (const auto& name : c.listCollections()) {
+            if (name.find(':') != std::string::npos || name.empty() || name[0] == '_') continue;
+            ++colls;
+            Client::QueryOptions o; o.limit = 10000000;
+            try {
+                for (const auto& d : c.find(name, o)) {
+                    lines[p + ":" + name + "\t" + d.value("_id", "")] = d.dump();
+                }
+            } catch (const std::exception& e) {
+                lines[p + ":" + name + "\t(error)"] = e.what();
+            }
+        }
+    }
+    for (const auto& [k, v] : lines) std::cout << k << "\t" << v << "\n";
+    std::cerr << "dumped " << lines.size() << " docs from " << colls << " collections\n";
+}

+ 37 - 0
tests/load_test/migration_copy/zeuscopy.sh

@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+# Inside the dev container: the 2.17.0 migration on a copy of zeus's data.
+# Dump everything with the RELEASED 2.16.0 server, migrate with 2.17.0, dump
+# again, verify, restart, dump again; every dump must be identical.
+set -u
+R=/data/dev/smartbotics/smartbotic-database
+Z=$R/build/zc
+OLD=$R/build/old-server-2.16.0/usr/bin/smartbotic-database
+NEW=$R/build/service/smartbotic-database
+export LD_LIBRARY_PATH=$R/build/client
+g++ -std=c++20 -O1 -o $Z/dump $R/build/rt/dump.cpp -I$R/client/include -I$R/build/client -L$R/build/client -lsmartbotic-db-client -lspdlog -lfmt -pthread || exit 1
+BOOTS=0
+start() { "$1" --config $Z/config.json >> $Z/server.log 2>&1 & P=$!; BOOTS=$((BOOTS+1));
+          for _ in $(seq 1 2400); do [[ $(grep -c "Notified systemd: READY" $Z/server.log) -ge $BOOTS ]] && return 0; sleep 0.5; done;
+          echo "no READY"; tail -20 $Z/server.log; exit 1; }
+stop() { kill $P; wait $P; }
+CLI="$R/build/cli/smartbotic-db-cli --address 127.0.0.1:9032"
+echo "== 2.16.0 on the copy"; start $OLD
+$Z/dump 127.0.0.1:9032 > $Z/before.tsv 2> $Z/dump-before.log; cat $Z/dump-before.log
+echo "   control: 2.16.0 keeps running so its own TTL sweep fires"; sleep 150
+$Z/dump 127.0.0.1:9032 > $Z/control.tsv 2>/dev/null; stop
+echo "== 2.17.0 on the copy (migration)"; start $NEW
+grep -E "v2.17|DISARMED|ERROR|error" $Z/server.log | grep -v "^\s*$" | tail -40
+$Z/dump 127.0.0.1:9032 > $Z/after.tsv 2> $Z/dump-after.log; cat $Z/dump-after.log
+$CLI encryption-verify 2>&1 | grep -v "connected to" | grep -vE "^ok  .*plaintext-required 0, double 0, undecryptable 0, history [0-9]+ \(plaintext-required 0, double 0\)$" ; echo "verify exit=$?"
+stop
+echo "== restart"; start $NEW
+$Z/dump 127.0.0.1:9032 > $Z/after2.tsv 2>/dev/null
+$CLI encryption-verify 2>&1 | tail -1
+stop
+echo "== compare (see compare.py)"
+python3 $R/build/rt/compare.py $Z
+exit 0
+echo "== compare"
+cmp -s $Z/before.tsv $Z/after.tsv && echo "IDENTICAL before vs after migration ($(wc -l < $Z/before.tsv) docs)" || { echo "DIFFERENT before vs after"; diff $Z/before.tsv $Z/after.tsv | head -5 | cut -c1-300; }
+cmp -s $Z/after.tsv $Z/after2.tsv && echo "IDENTICAL after vs after restart" || echo "DIFFERENT after vs after restart"
+echo "migration runs: $(grep -c 'one-time migration' $Z/server.log)"