Selaa lähdekoodia

fix: 2.12.2 - dropping a collection or project forgets what was declared on it, and a dropped project's documents are gone

Reported by smartbotic-vectorapi against 2.12.1: dropCollection removed the
documents but not the collection's config record in _collection_meta (indexed
fields, unique fields, composite constraints, relations_enforced, versioning,
precision), nor its index and composite sub-dbs, and the store stayed armed to
maintain them. A later collection of the same name silently inherited a unique
constraint nobody declared: a legitimate write refused as a duplicate, and
re-declaring it answered already_existed instead of validating the new data.
Once the collection's project was gone the record could not be removed: DropIndex
refused without an LMDB store, dropCollection said false.

purgeCollectionDeclarations() disarms the store, removes the config record and
drops the sub-dbs. DropCollection runs it even when the collection no longer
exists, so it also repairs a poisoned name, and DropIndex undeclares with or
without project storage.

dropProject was worse, found by the test: it removed the project's LMDB env, but
its collections stayed in MemoryStore and the WAL, so dropped documents were
still served and a restart would replay them. DropProject now - only after the
drop succeeds, since it refuses `default` - drops each collection like
DropCollection (MemoryStore, a WAL drop record, its declarations), and
dropProject removes every config record under the project prefix, which catches
declarations on collections that never had documents.

No wire or client change: client/ is untouched and the library exports the same
7174 symbols as 2.12.1.

Test: test_drop_cleans_declarations, 26 checks plus 11 after a restart,
including the poisoned state older versions left (a config record for a project
with no storage, loaded at boot). Each part reverted fails it: collection purge
6, DropIndex without storage 2, project-wide config purge 1, project in-memory
drop 1. ctest 23/23, 15/15 e2e suites.
fszontagh 1 kuukausi sitten
vanhempi
sitoutus
5091ccc015

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
CLAUDE.md


+ 1 - 1
VERSION

@@ -1 +1 @@
-2.12.1
+2.12.2

+ 6 - 2
docs/ROADMAP.md

@@ -1,6 +1,6 @@
 # Smartbotic Database - Status and Roadmap
 
-**Released version: 2.12.1** (see `VERSION`). Last reviewed: 2026-10-07.
+**Released version: 2.12.2** (see `VERSION`). Last reviewed: 2026-10-07.
 
 > 2.11.5 was prepared but never released on its own: its work (event actors,
 > `removeAs()`) ships inside 2.12.0. There is no 2.11.5 package.
@@ -56,7 +56,7 @@ Consequences of that substitution, which trip up readers:
 
 ## Shipped
 
-Every item below is in the installed product as of 2.12.1. `CLAUDE.md` has the
+Every item below is in the installed product as of 2.12.2. `CLAUDE.md` has the
 detail and the failure modes.
 
 - JSON document store: collections, version history, field-level encryption, TTL
@@ -81,6 +81,10 @@ detail and the failure modes.
 - Writes reach EVICTED documents (2.12.1 - before it, an evicted document was
   invisible to every write path); a duplicate id on insert is `AlreadyExists`,
   reason `duplicate_id` (2.12.1)
+- Dropping a collection or project forgets everything declared on it, and a
+  dropped project's documents are really gone, including after a restart
+  (2.12.2); `dropIndex` / `dropCollection` repair a name left poisoned by an
+  older version (2.12.2)
 - Conditional partial update (`patchIfVersion`) and atomic increment
   (`increment`) (2.12.0)
 - Event provenance: the actor on every `DatabaseEvent`, `removeAs()`,

+ 8 - 0
docs/integration-guide.md

@@ -433,6 +433,14 @@ one with `dropCompositeUniqueIndex(collection, sameFieldList)`. From the CLI:
 Constraints and indexes are declarations stored with the collection's config:
 they survive restarts and are re-armed at boot.
 
+**Dropping forgets them (2.12.2+).** `dropCollection` removes the collection's
+declared indexes and constraints, and its other settings (`relations_enforced`,
+versioning, precision), so a new collection of the same name starts clean.
+`dropProject` does the same for every collection in the project and removes the
+project's documents. Before 2.12.2 the declarations survived the drop and a
+same-named collection inherited them; on such a name, `dropCollection` (even
+though the collection is gone) or `dropIndex` clears what was left.
+
 ### Batch delete (2.12.0+)
 
 ```cpp

+ 20 - 0
service/src/config/collection_config_manager.cpp

@@ -135,6 +135,26 @@ bool CollectionConfigManager::setConfig(const std::string& collection,
     return true;
 }
 
+bool CollectionConfigManager::removeConfig(const std::string& collection) {
+    const std::string key = canonicalKey(collection);
+    bool had = false;
+    {
+        std::unique_lock<std::shared_mutex> wlock(cacheMutex_);
+        had = cache_.erase(key) > 0;
+    }
+    // The record's id is the canonical key (see setConfig). A record written
+    // before canonicalisation may carry the caller's spelling instead.
+    try {
+        had = store_.remove(SYSTEM_COLLECTION, key) || had;
+        if (collection != key) had = store_.remove(SYSTEM_COLLECTION, collection) || had;
+    } catch (const std::exception& e) {
+        spdlog::warn("CollectionConfigManager: could not remove the config record of '{}': {}",
+                     collection, e.what());
+    }
+    if (had) spdlog::info("CollectionConfigManager: removed the config of '{}'", key);
+    return had;
+}
+
 CollectionCfg CollectionConfigManager::configFor(const std::string& collection) const {
     std::shared_lock<std::shared_mutex> lock(cacheMutex_);
     auto it = cache_.find(canonicalKey(collection));

+ 10 - 0
service/src/config/collection_config_manager.hpp

@@ -116,6 +116,16 @@ public:
      */
     bool setConfig(const std::string& collection, const CollectionCfg& cfg, std::string& errorOut);
 
+    /**
+     * v2.12.2 — forget a collection's config entirely (persisted record and
+     * cache), so the name reverts to defaults. Called when the collection is
+     * dropped: without it the record - declared indexes, unique and composite
+     * constraints, relations_enforced, versioning - outlived the collection and
+     * a later collection of the same name silently inherited all of it.
+     * @return true if there was a record to remove.
+     */
+    bool removeConfig(const std::string& collection);
+
     /**
      * Hot-path lookup used by the write paths in MemoryStore.
      * Returns the configured config, or the default if not explicitly set.

+ 75 - 10
service/src/database_grpc_impl.cpp

@@ -1969,6 +1969,33 @@ grpc::Status DatabaseGrpcImpl::CreateCollection(
     return grpc::Status::OK;
 }
 
+// v2.12.2 — forget everything declared on a collection name: disarm the
+// store (so no write maintains the old indexes), remove the config record,
+// then drop the index and composite-constraint sub-dbs. Safe on a name whose
+// collection - or whole project - no longer exists.
+void DatabaseGrpcImpl::purgeCollectionDeclarations(const std::string& name) {
+    const CollectionCfg cfg = config_manager_.configFor(name);   // before removal
+    smartbotic::db::storage::LmdbDocumentStore* lmdb = nullptr;
+    std::string coll;
+    try {
+        const auto rc = smartbotic::database::resolveCollection(name);
+        coll = rc.collection;
+        lmdb = dynamic_cast<smartbotic::db::storage::LmdbDocumentStore*>(service_.docStore(rc.project));
+    } catch (const std::exception&) {
+        // unresolvable name: nothing armed under it, only the record to remove
+    }
+    if (lmdb != nullptr) {
+        lmdb->set_indexed_fields(coll, {});
+        lmdb->set_unique_fields(coll, {});
+        lmdb->set_composite_uniques(coll, {});
+    }
+    config_manager_.removeConfig(name);
+    if (lmdb != nullptr) {
+        for (const auto& f : cfg.indexedFields) lmdb->drop_index(coll, f);
+        for (const auto& cf : cfg.compositeUniques) lmdb->drop_composite_unique(coll, cf);
+    }
+}
+
 grpc::Status DatabaseGrpcImpl::DropCollection(
     grpc::ServerContext* context,
     const pb::DropCollectionRequest* request,
@@ -2036,6 +2063,14 @@ grpc::Status DatabaseGrpcImpl::DropCollection(
     }
 
     bool dropped = store_.dropCollection(request->name());
+    // v2.12.2 — and everything DECLARED on the name, whether or not the
+    // collection still existed (dropped == false). Before this the config
+    // record survived the drop, so a later collection of the same name
+    // inherited its indexes and unique constraints - a legitimate write refused
+    // as a duplicate of a constraint nobody declared - and once the collection
+    // was gone nothing in the API could clear it. Running on an absent
+    // collection is what lets dropCollection repair such a name.
+    purgeCollectionDeclarations(request->name());
     response->set_dropped(dropped);
 
     if (dropped) {
@@ -2191,8 +2226,35 @@ grpc::Status DatabaseGrpcImpl::DropProject(
     if (service_.isReadOnly()) {
         return readOnlyStatus(context, "DropProject", service_);
     }
+    // v2.12.2 — collect the project's in-memory collections BEFORE the drop.
+    const std::string prefix = request->name() + ":";
+    std::vector<std::string> doomed;
+    for (const auto& c : store_.listCollections()) {
+        if (c.rfind(prefix, 0) == 0) doomed.push_back(c);
+    }
+
     std::string error;
     bool dropped = service_.dropProject(request->name(), error);
+    // v2.12.2 — the project drop removed the project's LMDB env, but its
+    // collections stayed in MemoryStore and in the WAL. So the "dropped" data
+    // was still served (an insert of a dropped id said "already exists"), and a
+    // restart would replay it back. Drop each collection the way DropCollection
+    // does - MemoryStore, a WAL drop record so replay cannot resurrect it, and
+    // its declarations - but only once the project drop has succeeded: it
+    // refuses some names (`default`), and purging first would destroy data the
+    // refused drop was meant to keep.
+    if (dropped) {
+        for (const auto& c : doomed) {
+            if (store_.dropCollection(c)) {
+                persistence_.logDropCollection(c);
+            }
+            purgeCollectionDeclarations(c);
+        }
+        if (!doomed.empty()) {
+            spdlog::info("DropProject '{}': dropped {} in-memory collection(s)",
+                         request->name(), doomed.size());
+        }
+    }
     response->set_dropped(dropped);
     if (!error.empty()) {
         response->set_error(error);
@@ -4153,12 +4215,11 @@ grpc::Status DatabaseGrpcImpl::DropIndex(
     try {
         const auto rc = smartbotic::database::resolveCollection(request->collection());
         auto* ds = service_.docStore(rc.project);
+        // v2.12.2 — may be null: the project's storage is gone (dropped)
+        // while a declaration on one of its names survived. The declaration
+        // lives in the global `_collection_meta`, so it can and must still be
+        // removed - refusing here is what made such a name unrepairable.
         auto* lmdb = dynamic_cast<smartbotic::db::storage::LmdbDocumentStore*>(ds);
-        if (lmdb == nullptr) {
-            response->set_success(false);
-            response->set_error("secondary indexes require the LMDB substrate");
-            return grpc::Status::OK;
-        }
 
         // v2.12.0 — a composite unique constraint, named by its exact field list.
         if (request->fields_size() > 0) {
@@ -4181,8 +4242,10 @@ grpc::Status DatabaseGrpcImpl::DropIndex(
                 }
             }
             // Undeclare first, then drop - same order and reason as below.
-            lmdb->set_composite_uniques(rc.collection, cfg.compositeUniques);
-            lmdb->drop_composite_unique(rc.collection, fields);
+            if (lmdb != nullptr) {
+                lmdb->set_composite_uniques(rc.collection, cfg.compositeUniques);
+                lmdb->drop_composite_unique(rc.collection, fields);
+            }
             response->set_success(true);
             return grpc::Status::OK;
         }
@@ -4218,9 +4281,11 @@ grpc::Status DatabaseGrpcImpl::DropIndex(
                 return grpc::Status::OK;
             }
         }
-        lmdb->set_indexed_fields(rc.collection, cfg.indexedFields);
-        lmdb->set_unique_fields(rc.collection, cfg.uniqueFields);
-        lmdb->drop_index(rc.collection, request->field());
+        if (lmdb != nullptr) {
+            lmdb->set_indexed_fields(rc.collection, cfg.indexedFields);
+            lmdb->set_unique_fields(rc.collection, cfg.uniqueFields);
+            lmdb->drop_index(rc.collection, request->field());
+        }
 
         // Idempotent: dropping an index that is not there is a success, the
         // requested end state having been reached either way.

+ 3 - 0
service/src/database_grpc_impl.hpp

@@ -499,6 +499,9 @@ private:
     //
     // v2.12.0 - `actor` is the deleting caller's; it is reported on the event
     // of the parent AND of every child the cascade deletes or nulls.
+    // v2.12.2 — see the definition.
+    void purgeCollectionDeclarations(const std::string& name);
+
     // v2.12.0 — CreateIndex's composite-unique branch.
     grpc::Status createCompositeUnique(grpc::ServerContext* context,
                                        const pb::CreateIndexRequest* request,

+ 15 - 0
service/src/database_service.cpp

@@ -406,6 +406,21 @@ bool DatabaseService::dropProject(const std::string& name, std::string& error) {
 
     if (!projects_->drop(name, error)) return false;
 
+    // v2.12.2 — collection configs live in the GLOBAL `_collection_meta`, not
+    // in the project's env, so dropping the env left every one of the project's
+    // declarations behind - and a recreated project silently inherited them.
+    // The index sub-dbs went with the env; only the records remain to remove.
+    if (config_manager_) {
+        const std::string prefix = name + ":";
+        size_t removed = 0;
+        for (const auto& [key, cfg] : config_manager_->allConfigs()) {
+            if (key.rfind(prefix, 0) == 0 && config_manager_->removeConfig(key)) ++removed;
+        }
+        if (removed > 0) {
+            spdlog::info("dropProject '{}': removed {} collection config(s)", name, removed);
+        }
+    }
+
     // ---- The drop succeeded; the declarations now point at a namespace that
     // no longer exists. Sweep them out of the global `_relations` collection
     // and un-arm each affected child collection.

+ 153 - 0
tests/load_test/test_drop_cleans_declarations.cpp

@@ -0,0 +1,153 @@
+// v2.12.2 client/server boundary test: dropping a collection (or a project)
+// forgets everything declared on it.
+//
+// Reported by smartbotic-vectorapi against 2.12.1: dropCollection removed the
+// documents but left the collection's CONFIG record - declared indexes, unique
+// and composite constraints, relations_enforced, versioning - plus the index
+// postings. A later collection of the same name silently inherited a unique
+// constraint nobody declared (a legitimate write refused as a duplicate), and
+// re-declaring it answered already_existed instead of validating the new data.
+// Worse, once the collection (or its project) was gone the record could not be
+// removed through the API at all: dropIndex refused without project storage,
+// dropCollection said false.
+//
+// Run twice by the .sh, with a restart between: removing the in-memory cache
+// but not the persisted record would pass every check before a restart and
+// resurrect the poisoned declarations after it.
+
+#include <smartbotic/database/client.hpp>
+#include <iostream>
+#include <string>
+
+using namespace smartbotic::database;
+static int pass = 0, fail = 0;
+static void ck(bool c, const std::string& m) {
+    if (c) { ++pass; } else { ++fail; std::cerr << "FAIL: " << m << "\n"; }
+}
+static const char* ADDR = "127.0.0.1:9020";
+
+static bool hasIndex(Client& c, const std::string& coll, const std::string& field) {
+    for (const auto& i : c.listIndexes(coll)) if (i.field == field) return true;
+    return false;
+}
+static bool throwsDuplicate(Client& c, const std::string& coll, const nlohmann::json& doc, const std::string& id) {
+    try { c.insert(coll, doc, id); return false; } catch (const Client::AlreadyExists&) { return true; }
+}
+
+static void beforeRestart() {
+    Client c({.address = ADDR, .project = "acme"});
+    c.connect();
+
+    // ---- the reported sequence
+    c.upsert("leak", nlohmann::json{{"sku", "Q1"}, {"cat", "a"}}, "a1");
+    ck(c.createUniqueIndex("leak", "sku").success, "declare unique(sku)");
+    ck(c.createIndex("leak", "cat"), "declare index(cat)");
+    ck(c.createCompositeUniqueIndex("leak", {"sku", "cat"}).success, "declare composite(sku, cat)");
+    ck(c.setRelationsEnforced("leak", false), "set relations_enforced=false");
+    ck(c.dropCollection("leak"), "dropCollection");
+    ck(c.listIndexes("leak").empty(), "after drop: no single-field index declared");
+    ck(c.listCompositeUniqueIndexes("leak").empty(), "after drop: no composite constraint declared");
+    ck(!c.hasCollectionConfig("leak"), "after drop: no config record at all");
+    ck(c.tryGetRelationsEnforced("leak") == std::optional<bool>(true),
+       "after drop: relations_enforced back to its default");
+
+    // a new collection of the same name starts clean
+    c.insert("leak", nlohmann::json{{"sku", "Q9"}, {"cat", "a"}}, "b1");
+    ck(!throwsDuplicate(c, "leak", nlohmann::json{{"sku", "Q9"}, {"cat", "a"}}, "b2"),
+       "recreated collection: the old unique(sku) and composite are NOT inherited");
+    c.remove("leak", "b2");
+    auto r = c.createUniqueIndex("leak", "sku");
+    ck(r.success && !r.alreadyExisted, "recreated collection: declaring unique(sku) is a NEW declaration");
+    ck(r.rowsIndexed == 1, "recreated collection: the index holds only the new rows (old postings gone), got " +
+                           std::to_string(r.rowsIndexed));
+
+    // ---- repairing a name whose collection does not exist
+    ck(c.createIndex("ghost", "f"), "declare an index on a collection that does not exist");
+    ck(hasIndex(c, "ghost", "f"), "...it is listed");
+    ck(c.dropIndex("ghost", "f"), "dropIndex on an absent collection succeeds");
+    ck(!hasIndex(c, "ghost", "f"), "...and the declaration is gone");
+
+    ck(c.createUniqueIndex("ghost2", "f").success, "declare a unique index on another absent collection");
+    c.dropCollection("ghost2");   // false: there is no collection - but it must still clean up
+    ck(c.listIndexes("ghost2").empty(), "dropCollection on an absent collection still clears its declarations");
+
+    // ---- dropping a project forgets its collections' configs
+    Client admin({.address = ADDR, .project = "default"});
+    admin.connect();
+    admin.createProject("tmpproj");
+    Client t({.address = ADDR, .project = "tmpproj"});
+    t.connect();
+    t.upsert("c", nlohmann::json{{"sku", "Z"}}, "z1");
+    ck(t.createUniqueIndex("c", "sku").success, "tmpproj: declare unique(sku)");
+    // a declaration on a collection that has NO documents: only the
+    // project-wide config purge can find it, the per-collection one cannot
+    ck(t.createIndex("never", "f"), "tmpproj: declare an index on an empty collection");
+    admin.dropProject("tmpproj");
+    admin.createProject("tmpproj");
+    ck(t.listIndexes("c").empty(), "recreated project: no inherited index declaration");
+    ck(t.listIndexes("never").empty(), "recreated project: no inherited declaration on an empty collection");
+    bool z1Free = true;
+    try { t.insert("c", nlohmann::json{{"sku", "Z"}}, "z1"); } catch (const std::exception&) { z1Free = false; }
+    ck(z1Free, "recreated project: the dropped project's document id is free");
+    ck(!throwsDuplicate(t, "c", nlohmann::json{{"sku", "Z"}}, "z2"), "recreated project: no inherited unique constraint");
+
+    // the POISONED state older versions left behind: a config record for a
+    // project whose storage no longer exists. Written straight into
+    // `_collection_meta` (global, so not project-qualified); the config cache
+    // loads it at the next boot, and after the restart it must be removable.
+    admin.upsert("_collection_meta", nlohmann::json{{"timestamp_precision", "ns"},
+                 {"indexed_fields", {"f"}}, {"unique_fields", {"f"}}}, "ghostproj:c");
+
+    // a dropped project's DOCUMENTS must be gone too - from memory now, and
+    // from the WAL, or a restart replays them back (checked after the restart)
+    admin.createProject("tmpproj2");
+    Client t2({.address = ADDR, .project = "tmpproj2"});
+    t2.connect();
+    t2.insert("c", nlohmann::json{{"v", 1}}, "old1");
+    admin.dropProject("tmpproj2");
+    admin.createProject("tmpproj2");
+    ck(!t2.get("c", "old1").has_value(), "recreated project: the dropped project's document is gone");
+    bool reinsertOk = true;
+    try { t2.insert("c", nlohmann::json{{"v", 2}}, "old1b"); } catch (const std::exception&) { reinsertOk = false; }
+    ck(reinsertOk, "recreated project accepts writes");
+    t2.remove("c", "old1b");
+    admin.dropProject("tmpproj2");
+}
+
+static void afterRestart() {
+    Client c({.address = ADDR, .project = "acme"});
+    c.connect();
+    ck(c.listCompositeUniqueIndexes("leak").empty(), "after restart: the dropped composite did not come back");
+    ck(hasIndex(c, "leak", "sku"), "after restart: the NEW unique(sku) is still declared");
+    ck(!hasIndex(c, "leak", "cat"), "after restart: the dropped index(cat) did not come back");
+    ck(c.tryGetRelationsEnforced("leak") == std::optional<bool>(true), "after restart: relations_enforced still default");
+    ck(c.listIndexes("ghost").empty() && c.listIndexes("ghost2").empty(), "after restart: repaired names stay clean");
+    Client t({.address = ADDR, .project = "tmpproj"});
+    t.connect();
+    ck(t.listIndexes("c").empty(), "after restart: the recreated project still has no inherited declaration");
+
+    Client admin({.address = ADDR, .project = "default"});
+    admin.connect();
+
+    // repair of the poisoned record: a project with no storage
+    Client gp({.address = ADDR, .project = "ghostproj"});
+    gp.connect();
+    ck(hasIndex(gp, "c", "f"), "poisoned name: the leftover declaration is visible (setup worked)");
+    ck(gp.dropIndex("c", "f"), "poisoned name: dropIndex succeeds without project storage");
+    ck(!hasIndex(gp, "c", "f"), "poisoned name: the declaration is gone");
+
+    admin.createProject("tmpproj2");
+    Client t2({.address = ADDR, .project = "tmpproj2"});
+    t2.connect();
+    ck(!t2.get("c", "old1").has_value(), "after restart: a dropped project's documents were not replayed back");
+    bool threw = false;
+    try { t2.insert("c", nlohmann::json{{"v", 3}}, "old1"); } catch (const std::exception&) { threw = true; }
+    ck(!threw, "after restart: the dropped document's id is free");
+}
+
+int main(int argc, char** argv) {
+    const std::string phase = argc > 1 ? argv[1] : "before-restart";
+    if (phase == "before-restart") beforeRestart(); else afterRestart();
+    std::cout << "\n[" << phase << "] passed=" << pass << " failed=" << fail << "\n";
+    return fail == 0 ? 0 : 1;
+}

+ 75 - 0
tests/load_test/test_drop_cleans_declarations.sh

@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+# v2.12.2 client/server boundary e2e - dropping a collection or project forgets
+# what was declared on it, over real gRPC, across a real restart. See
+# test_drop_cleans_declarations.cpp for what each assertion covers.
+
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+cd "$SCRIPT_DIR"
+
+DIR=/tmp/sbdb-drop-cleans
+PORT=9020
+
+rm -rf "$DIR"
+mkdir -p "$DIR/data"
+
+cat > "$DIR/config.json" <<CFG
+{
+  "storage": {
+    "data_directory": "$DIR/data",
+    "bind_address": "127.0.0.1",
+    "rpc_port": $PORT,
+    "encryption": { "enabled": false },
+    "migrations": { "enabled": false },
+    "replication": { "enabled": false }
+  }
+}
+CFG
+
+echo "=== building test binary ==="
+g++ -std=c++20 -O1 -o "$DIR/t" test_drop_cleans_declarations.cpp \
+    -I"$ROOT/client/include" -I"$ROOT/build/client" \
+    -L"$ROOT/build/client" -lsmartbotic-db-client -lspdlog -lfmt -pthread
+
+SERVER_PID=""
+boot() {
+    "$ROOT/build/service/smartbotic-database" --config "$DIR/config.json" \
+        > "$DIR/server-$1.log" 2>&1 &
+    SERVER_PID=$!
+    for _ in $(seq 1 60); do
+        grep -q "Notified systemd: READY" "$DIR/server-$1.log" && return 0
+        sleep 0.5
+    done
+    echo "server failed to become ready; log:"
+    tail -30 "$DIR/server-$1.log"
+    exit 1
+}
+stop() { kill "$SERVER_PID" 2>/dev/null || true; wait "$SERVER_PID" 2>/dev/null || true; }
+trap stop EXIT
+
+run() {   # run <phase>
+    set +e
+    LD_LIBRARY_PATH="$ROOT/build/client" "$DIR/t" "$1"
+    local rc=$?
+    set -e
+    if [[ $rc -ne 0 ]]; then
+        echo ""
+        echo "FAILED in phase $1 - server log tail:"
+        tail -30 "$DIR"/server-*.log | tail -30
+        exit $rc
+    fi
+}
+
+echo "=== phase 1 ==="
+boot 1
+run before-restart
+stop
+
+echo "=== restart: declarations must survive ==="
+boot 2
+run after-restart
+
+echo ""
+echo "OK - drop cleans declarations e2e passed"

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä