|
@@ -15,6 +15,7 @@
|
|
|
#include <memory>
|
|
#include <memory>
|
|
|
#include <optional>
|
|
#include <optional>
|
|
|
#include <stdexcept>
|
|
#include <stdexcept>
|
|
|
|
|
+#include <map>
|
|
|
#include <string>
|
|
#include <string>
|
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
|
|
|
|
|
@@ -434,6 +435,69 @@ void test_vector_mirror_via_memory_store() {
|
|
|
check(healthy.load() && drift.load() == 0, "vector via memstore: clean");
|
|
check(healthy.load() && drift.load() == 0, "vector via memstore: clean");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// v2.13.0 - every kind of write leaves a definite has-vector marker. Found by
|
|
|
|
|
+// smartbotic-vectorapi's pre-release run: patch did not stamp an unmarked
|
|
|
|
|
+// (pre-2.13.0) row, so a legacy row only ever patched stayed Unknown forever -
|
|
|
|
|
+// and could never report Missing if its vector were later lost. The legacy
|
|
|
|
|
+// rows are planted directly (no marker in LMDB or in memory), and the vector
|
|
|
|
|
+// is deliberately NOT loaded into memory, as for a row evicted and reloaded:
|
|
|
|
|
+// the stamp must come from the LMDB vector sub-db, the durable copy.
|
|
|
|
|
+void test_patch_stamps_unmarked_rows() {
|
|
|
|
|
+ TmpEnv tmp("patch-stamp");
|
|
|
|
|
+ LmdbDocumentStore doc_store(tmp.env);
|
|
|
|
|
+ std::atomic<bool> healthy{true};
|
|
|
|
|
+ std::atomic<uint64_t> drift{0};
|
|
|
|
|
+ MemoryStore::Config cfg;
|
|
|
|
|
+ cfg.nodeId = "test-node";
|
|
|
|
|
+ cfg.maxMemoryBytes = 64ULL * 1024 * 1024;
|
|
|
|
|
+ MemoryStore mem(cfg);
|
|
|
|
|
+ mem.setDocumentStoreMirror([&doc_store](std::string_view) { return &doc_store; },
|
|
|
|
|
+ &healthy, &drift);
|
|
|
|
|
+ smartbotic::database::CollectionOptions opts;
|
|
|
|
|
+ opts.vectorDimension = 4;
|
|
|
|
|
+ mem.createCollection("emb", opts);
|
|
|
|
|
+
|
|
|
|
|
+ auto legacy = [&](const std::string& id, bool withVector) {
|
|
|
|
|
+ Document d;
|
|
|
|
|
+ d.id = id;
|
|
|
|
|
+ d.collection = "emb";
|
|
|
|
|
+ d.set_data({{"label", id}});
|
|
|
|
|
+ doc_store.put("emb", id, d); // no marker on disk
|
|
|
|
|
+ if (withVector) doc_store.put_vector("emb", id, {1.f, 2.f, 3.f, 4.f});
|
|
|
|
|
+ mem.loadDocument("emb", d); // no marker, no vector in memory
|
|
|
|
|
+ };
|
|
|
|
|
+ legacy("L1", true);
|
|
|
|
|
+ legacy("L0", false);
|
|
|
|
|
+ check(!doc_store.get("emb", "L1")->hasVector && !doc_store.get("emb", "L0")->hasVector,
|
|
|
|
|
+ "patch stamp: the planted rows really are unmarked");
|
|
|
|
|
+
|
|
|
|
|
+ check(mem.patchDocument("emb", "L1", {{"p", 1}}) > 0, "patch stamp: patch L1");
|
|
|
|
|
+ check(mem.patchDocument("emb", "L0", {{"p", 1}}) > 0, "patch stamp: patch L0");
|
|
|
|
|
+
|
|
|
|
|
+ auto m1 = mem.get("emb", "L1");
|
|
|
|
|
+ auto m0 = mem.get("emb", "L0");
|
|
|
|
|
+ check(m1 && m1->hasVector == true, "patch stamp: in memory, the row with a stored vector -> true");
|
|
|
|
|
+ check(m0 && m0->hasVector == false, "patch stamp: in memory, the row without one -> false");
|
|
|
|
|
+ check(doc_store.get("emb", "L1")->hasVector == true, "patch stamp: on disk, L1 -> true");
|
|
|
|
|
+ check(doc_store.get("emb", "L0")->hasVector == false, "patch stamp: on disk, L0 -> false");
|
|
|
|
|
+ check(doc_store.get_vector("emb", "L1").has_value(), "patch stamp: the vector itself is untouched");
|
|
|
|
|
+
|
|
|
|
|
+ // The point of the marker: a vector lost AFTER the stamp is reported as
|
|
|
|
|
+ // lost, not as "unknown".
|
|
|
|
|
+ doc_store.del_vector("emb", "L1");
|
|
|
|
|
+ std::map<std::string, DocumentStore::ExportVectorState> states;
|
|
|
|
|
+ doc_store.export_scan("emb", "", true, {}, [](uint64_t) {},
|
|
|
|
|
+ [&](Document&& d, DocumentStore::ExportVectorState st, const float*, size_t) {
|
|
|
|
|
+ states[d.id] = st;
|
|
|
|
|
+ return true;
|
|
|
|
|
+ });
|
|
|
|
|
+ check(states["L1"] == DocumentStore::ExportVectorState::Missing,
|
|
|
|
|
+ "patch stamp: a stamped row whose vector is then lost reports MISSING");
|
|
|
|
|
+ check(states["L0"] == DocumentStore::ExportVectorState::None,
|
|
|
|
|
+ "patch stamp: a stamped row that never had one reports NONE");
|
|
|
|
|
+ check(healthy.load() && drift.load() == 0, "patch stamp: clean");
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// Simulates DatabaseService::backfillIntoDocStore — populate MemoryStore
|
|
// Simulates DatabaseService::backfillIntoDocStore — populate MemoryStore
|
|
|
// without a persist callback (no live mirror), then walk listCollections +
|
|
// without a persist callback (no live mirror), then walk listCollections +
|
|
|
// getAllDocuments and feed each doc into applyDualWriteMirror with
|
|
// getAllDocuments and feed each doc into applyDualWriteMirror with
|
|
@@ -548,6 +612,7 @@ int main() {
|
|
|
test_vector_mirror_empty_is_noop_on_insert();
|
|
test_vector_mirror_empty_is_noop_on_insert();
|
|
|
test_vector_mirror_system_collection_skipped();
|
|
test_vector_mirror_system_collection_skipped();
|
|
|
test_vector_mirror_via_memory_store();
|
|
test_vector_mirror_via_memory_store();
|
|
|
|
|
+ test_patch_stamps_unmarked_rows();
|
|
|
test_backfill_iteration_pattern();
|
|
test_backfill_iteration_pattern();
|
|
|
test_scan_vectors_round_trip();
|
|
test_scan_vectors_round_trip();
|
|
|
|
|
|