OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace-cog commits / 47d2c7d

Updates to selectively revise remote storage
47d2c7d17abb59899437ee57e8736bc1d10eb4f5
by Linas Vepstas <linasvepstas@gmail.com> · 2025-12-13T05:37:24.000Z

Changed files (16) +76 -40

tests/persist/TestCogServer.h +34 -0
……@@ -1,9 +1,43 @@
11#include <opencog/atomspace/AtomSpace.h>
2#include <opencog/atoms/atom_types/atom_types.h>
23#include <opencog/atoms/value/FloatValue.h>
34#include <opencog/atoms/value/VoidValue.h>
45#include <opencog/atoms/atom_types/atom_names.h>
56#include <opencog/cogserver/atoms/CogServerNode.h>
67#include <opencog/cogserver/types/atom_types.h>
8#include <opencog/persist/api/StorageNode.h>
9
10using namespace opencog;
11
12// Selectively clear test data from the remote atomspace without
13// removing the CogServerNode itself. This replaces kill_data() which
14// would destroy the CogServerNode and cause segfaults.
15inline void kill_data(StorageNode* store, AtomSpace* asp)
16{
17 // Load all nodes from remote storage
18 store->fetch_all_atoms_of_type(NODE, asp);
19 store->barrier();
20
21 HandleSeq nodes;
22 asp->get_handles_by_type(nodes, NODE, true);
23 for (const Handle& h : nodes)
24 {
25 Type t = h->get_type();
26 // Keep the CogServerNode
27 if (t == COG_SERVER_NODE) continue;
28 // Keep infrastructure PredicateNodes (those starting with "*-")
29#if 0
30 if (t == PREDICATE_NODE)
31 {
32 const std::string& name = h->get_name();
33 if (name.size() > 2 && name[0] == '*' && name[1] == '-')
34 continue;
35 }
36#endif
37 store->remove_atom(asp, h, true);
38 }
39 store->barrier();
40}
741
842#define DECLARE_TEST_COGSERVER \
943 AtomSpacePtr _test_asp; \
tests/persist/cog-simple/SimpleAlphaEquivUTest.cxxtest +2 -2
……@@ -108,8 +108,8 @@ void AlphaEquivUTest::kill_data(void)
108108 exit(1);
109109 }
110110
111 // Trash the contents of the database.
112 astore->kill_data();
111 // Selectively clear test data (preserves CogServerNode)
112 ::kill_data(astore, _test_asp.get());
113113
114114 // Destructor also logs out of database
115115 delete astore;
tests/persist/cog-simple/SimpleBasicSaveUTest.cxxtest +3 -3
……@@ -217,7 +217,7 @@ void BasicSaveUTest::single_atom_save_restore(std::string id)
217217 atomCompare(l, hl, "Single link save-restore");
218218 printf("Done fetching single link\n");
219219
220 store->kill_data();
220 kill_data(store, _test_asp.get());
221221 delete store;
222222}
223223
……@@ -353,7 +353,7 @@ void BasicSaveUTest::test_fresh_atom(void)
353353 if (he) printf("Got %s\n", he->to_string().c_str());
354354 atomCompare(le, he, "Empty Fresh");
355355
356 store->kill_data();
356 kill_data(store, _test_asp.get());
357357 delete store;
358358
359359 logger().debug("END TEST: %s", __FUNCTION__);
……@@ -417,7 +417,7 @@ void BasicSaveUTest::test_table()
417417 check_table(idx++, as2, "ddd ");
418418 check_table(idx++, as2, "eee ");
419419
420 store->kill_data();
420 kill_data(store, _test_asp.get());
421421 delete store;
422422
423423 logger().debug("END TEST: %s", __FUNCTION__);
tests/persist/cog-simple/SimpleLargeFlatUTest.cxxtest +2 -2
……@@ -127,8 +127,8 @@ void LargeFlatUTest::kill_data(void)
127127 exit(1);
128128 }
129129
130 // Trash the contents of the database.
131 astore->kill_data();
130 // Selectively clear test data (preserves CogServerNode)
131 ::kill_data(astore, _test_asp.get());
132132
133133 // Destructor also logs out
134134 delete astore;
tests/persist/cog-simple/SimpleLargeZipfUTest.cxxtest +2 -2
……@@ -115,8 +115,8 @@ void LargeZipfUTest::kill_data(void)
115115 exit(1);
116116 }
117117
118 // Trash the contents of the database.
119 astore->kill_data();
118 // Selectively clear test data (preserves CogServerNode)
119 ::kill_data(astore, _test_asp.get());
120120
121121 // Destructor also logs out
122122 delete astore;
tests/persist/cog-simple/SimpleMultiDeleteUTest.cxxtest +4 -3
……@@ -158,7 +158,7 @@ void SimpleMultiDeleteUTest::test_add_delete(void)
158158 TS_ASSERT(store->connected())
159159
160160 // Clear out left-over junk, just in case.
161 store->erase();
161 ::kill_data(store.get(), _test_asp.get());
162162
163163 printf("Start creating %d threads\n", n_threads);
164164
……@@ -201,14 +201,15 @@ void SimpleMultiDeleteUTest::test_add_delete(void)
201201
202202 // Size should be 20: the 18 from before plus
203203 // (Predicate "*-TruthValueKey-*") and (Predicate "*-IsKeyFlag-*")
204 size_t expected_size = 4 + 6 + n_threads;
204 // Plus 9 more from CogServerNode gorp
205 size_t expected_size = 9 + 4 + 6 + n_threads;
205206 if (as->get_size() != expected_size)
206207 printf("Error: Bad size! AtomSpace contents =\n%s\n",
207208 as->to_string().c_str());
208209
209210 TS_ASSERT_EQUALS(as->get_size(), expected_size);
210211
211 store->erase();
212 ::kill_data(store.get(), _test_asp.get());
212213 store->close();
213214 store = nullptr;
214215
tests/persist/cog-simple/SimpleQueryPersistUTest.cxxtest +2 -2
……@@ -104,8 +104,8 @@ void SimpleQueryPersistUTest::kill_data(void)
104104 astore->open();
105105 TS_ASSERT(astore->connected())
106106
107 // Trash the contents of the database.
108 astore->kill_data();
107 // Selectively clear test data (preserves CogServerNode)
108 ::kill_data(astore, _test_asp.get());
109109
110110 // Destructor also logs out of database
111111 delete astore;
tests/persist/cog-simple/SimpleValueSaveUTest.cxxtest +1 -1
……@@ -277,7 +277,7 @@ void SimpleValueSaveUTest::test_load_by_type()
277277 TS_ASSERT(store->connected())
278278
279279 // Clear out left-over junk, just in case.
280 store->erase();
280 ::kill_data(store.get(), _test_asp.get());
281281
282282 Handle key = as->add_node(PREDICATE_NODE, "some pred key");
283283 Handle af = as->add_node(CONCEPT_NODE, "float node");
tests/persist/cog-storage/AlphaEquivUTest.cxxtest +2 -2
……@@ -108,8 +108,8 @@ void AlphaEquivUTest::kill_data(void)
108108 exit(1);
109109 }
110110
111 // Trash the contents of the database.
112 astore->kill_data();
111 // Selectively clear test data (preserves CogServerNode)
112 ::kill_data(astore, _test_asp.get());
113113
114114 // Destructor also logs out of database
115115 delete astore;
tests/persist/cog-storage/BasicDeleteUTest.cxxtest +8 -8
……@@ -106,7 +106,7 @@ void BasicDeleteUTest::test_duplicates(void)
106106 TS_ASSERT(store->connected())
107107
108108 // Clear out left-over junk, just in case.
109 store->erase();
109 ::kill_data(store.get(), _test_asp.get());
110110
111111 Handle ha(as->add_node(CONCEPT_NODE, "a"));
112112 Handle hb(as->add_node(CONCEPT_NODE, "b"));
……@@ -132,7 +132,7 @@ void BasicDeleteUTest::test_duplicates(void)
132132 // +1 for *-IsKeyFlag-*
133133 TS_ASSERT_EQUALS(as->get_size(), 5);
134134
135 store->erase();
135 ::kill_data(store.get(), _test_asp.get());
136136 store->close();
137137
138138 logger().debug("END TEST: %s", __FUNCTION__);
……@@ -153,7 +153,7 @@ void BasicDeleteUTest::test_recursive(void)
153153 TS_ASSERT(store->connected())
154154
155155 // Clear out left-over junk, just in case.
156 store->erase();
156 ::kill_data(store.get(), _test_asp.get());
157157
158158 Handle ha(as->add_node(CONCEPT_NODE, "a"));
159159 Handle hb(as->add_node(CONCEPT_NODE, "b"));
……@@ -258,7 +258,7 @@ void BasicDeleteUTest::test_recursive(void)
258258 TS_ASSERT_EQUALS(as->get_size(), 4);
259259
260260 // --------------------------------------
261 store->erase();
261 ::kill_data(store.get(), _test_asp.get());
262262 store->close();
263263
264264 logger().debug("END TEST: %s", __FUNCTION__);
……@@ -280,7 +280,7 @@ void BasicDeleteUTest::test_key_deletion(void)
280280 TS_ASSERT(store->connected())
281281
282282 // Clear out left-over junk, just in case.
283 store->erase();
283 ::kill_data(store.get(), _test_asp.get());
284284
285285 Handle ha(as->add_node(CONCEPT_NODE, "a"));
286286 Handle ka(as->add_node(PREDICATE_NODE, "key-a"));
……@@ -363,7 +363,7 @@ void BasicDeleteUTest::test_key_deletion(void)
363363 printf("key=%s\n", k->get_name().c_str());
364364 TS_ASSERT_EQUALS(hs.size(), 3);
365365
366 store->erase();
366 ::kill_data(store.get(), _test_asp.get());
367367 store->close();
368368
369369 logger().debug("END TEST: %s", __FUNCTION__);
……@@ -387,7 +387,7 @@ void BasicDeleteUTest::test_key_corruption(void)
387387 TS_ASSERT(store->connected())
388388
389389 // Clear out left-over junk, just in case.
390 store->erase();
390 ::kill_data(store.get(), _test_asp.get());
391391
392392 Handle hb(as->add_node(CONCEPT_NODE, "b"));
393393 Handle hx(as->add_node(CONCEPT_NODE, "x"));
……@@ -497,7 +497,7 @@ void BasicDeleteUTest::test_key_corruption(void)
497497 }
498498 TS_ASSERT_EQUALS(hs.size(), 2);
499499
500 store->erase();
500 ::kill_data(store.get(), _test_asp.get());
501501 store->close();
502502
503503 logger().debug("END TEST: %s", __FUNCTION__);
tests/persist/cog-storage/BasicSaveUTest.cxxtest +3 -3
……@@ -220,7 +220,7 @@ void BasicSaveUTest::single_atom_save_restore(std::string id)
220220 atomCompare(l, hl, "Single link save-restore");
221221 printf("Done fetching single link\n");
222222
223 store->kill_data();
223 kill_data(store, _test_asp.get());
224224 store->close();
225225 delete store;
226226}
……@@ -358,7 +358,7 @@ void BasicSaveUTest::test_fresh_atom(void)
358358 if (he) printf("Got %s\n", he->to_string().c_str());
359359 atomCompare(le, he, "Empty Fresh");
360360
361 store->kill_data();
361 kill_data(store, _test_asp.get());
362362 store->close();
363363 delete store;
364364
……@@ -426,7 +426,7 @@ void BasicSaveUTest::test_table()
426426 check_table(idx++, table2, "ddd ");
427427 check_table(idx++, table2, "eee ");
428428
429 store->kill_data();
429 kill_data(store, _test_asp.get());
430430 store->close();
431431 delete store;
432432
tests/persist/cog-storage/LargeFlatUTest.cxxtest +2 -2
……@@ -127,8 +127,8 @@ void LargeFlatUTest::kill_data(void)
127127 exit(1);
128128 }
129129
130 // Trash the contents of the database.
131 astore->kill_data();
130 // Selectively clear test data (preserves CogServerNode)
131 ::kill_data(astore, _test_asp.get());
132132
133133 // Destructor also logs out
134134 delete astore;
tests/persist/cog-storage/LargeZipfUTest.cxxtest +2 -2
……@@ -116,8 +116,8 @@ void LargeZipfUTest::kill_data(void)
116116 exit(1);
117117 }
118118
119 // Trash the contents of the database.
120 astore->kill_data();
119 // Selectively clear test data (preserves CogServerNode)
120 ::kill_data(astore, _test_asp.get());
121121
122122 // Destructor also logs out
123123 delete astore;
tests/persist/cog-storage/MultiDeleteUTest.cxxtest +5 -4
……@@ -156,7 +156,7 @@ void MultiDeleteUTest::test_add_delete(void)
156156 TS_ASSERT(store->connected())
157157
158158 // Clear out left-over junk, just in case.
159 store->erase();
159 ::kill_data(store.get(), _test_asp.get());
160160
161161 printf("Start creating %d threads\n", n_threads);
162162
……@@ -199,11 +199,12 @@ void MultiDeleteUTest::test_add_delete(void)
199199
200200 // Size should be 20: the 18 from before plus that annoying
201201 // (Predicate "*-TruthValueKey-*") And also *-IsKeyFlag-*
202 // And 9 more from CogServerNode gorp
202203 // Well, actually, there is no guarantee that the removes will
203204 // happen after the stores. Best we can do is check lower and
204205 // upper bounds of 20 and 36:
205 size_t min_size = 4 + n_threads + 6;
206 size_t max_size = 4 + 2*(n_threads + 6);
206 size_t min_size = 9 + 4 + n_threads + 6;
207 size_t max_size = 9 + 4 + 2*(n_threads + 6);
207208 if (as->get_size() < min_size or max_size < as->get_size())
208209 printf("Error: Bad size! AtomSpace contents =\n%s\n",
209210 as->to_string().c_str());
……@@ -211,7 +212,7 @@ void MultiDeleteUTest::test_add_delete(void)
211212 TS_ASSERT(as->get_size() >= min_size);
212213 TS_ASSERT(as->get_size() <= max_size);
213214
214 store->erase();
215 ::kill_data(store.get(), _test_asp.get());
215216 store->close();
216217 store = nullptr;
217218
tests/persist/cog-storage/QueryPersistUTest.cxxtest +2 -2
……@@ -104,8 +104,8 @@ void QueryPersistUTest::kill_data(void)
104104 astore->open();
105105 TS_ASSERT(astore->connected())
106106
107 // Trash the contents of the database.
108 astore->kill_data();
107 // Selectively clear test data (preserves CogServerNode)
108 ::kill_data(astore, _test_asp.get());
109109 astore->barrier();
110110 astore->close();
111111
tests/persist/cog-storage/ValueSaveUTest.cxxtest +2 -2
……@@ -260,7 +260,7 @@ void ValueSaveUTest::test_save_restore(bool fkey)
260260
261261 check_one(pvl2, fkey);
262262
263 store->erase();
263 ::kill_data(store.get(), _test_asp.get());
264264 as = nullptr;
265265
266266 logger().info("END TEST: %s", __FUNCTION__);
……@@ -282,7 +282,7 @@ void ValueSaveUTest::test_load_by_type()
282282 TS_ASSERT(store->connected())
283283
284284 // Clear out left-over junk, just in case.
285 store->erase();
285 ::kill_data(store.get(), _test_asp.get());
286286
287287 Handle key = as->add_node(PREDICATE_NODE, "some pred key");
288288 Handle af = as->add_node(CONCEPT_NODE, "float node");