From 7ca48902bcc17bc1872742aebc03ca0536d21644 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Tue, 14 Nov 2023 10:12:31 +0100 Subject: [PATCH 01/22] set temporary marker to -2 --- opencog/persist/rocks/RocksIO.cc | 7 ++++--- opencog/persist/rocks/RocksStorage.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 0866fb9..5dde4c9 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -398,7 +398,7 @@ void RocksStorage::storeAtom(const Handle& h, bool synchronous) storeValue(cid + writeAtom(key), h->getValue(key)); } -void RocksStorage::storeMissingAtom(AtomSpace* as, const Handle& h) +void RocksStorage::storeMissingAtom(AtomSpace* as, const Handle& h, bool tmpMarker) { std::string sid = writeAtom(h, false); @@ -414,7 +414,8 @@ void RocksStorage::storeMissingAtom(AtomSpace* as, const Handle& h) _rfile->Delete(rocksdb::WriteOptions(), marker); // Store an intentionally invalid key. - _rfile->Put(rocksdb::WriteOptions(), skid + "-1", ""); + marker = skid + (tmpMarker ? "-2" : "-1"); + _rfile->Put(rocksdb::WriteOptions(), marker, ""); } void RocksStorage::storeValue(const std::string& skid, @@ -799,7 +800,7 @@ void RocksStorage::removeAtom(AtomSpace* frame, const Handle& h, bool recursive) } // Multi-space Atom remove is done via hiding... - storeMissingAtom(frame, h); + storeMissingAtom(frame, h, true); } void RocksStorage::doRemoveAtom(const Handle& h, bool recursive) diff --git a/opencog/persist/rocks/RocksStorage.h b/opencog/persist/rocks/RocksStorage.h index 6c91a7d..027b476 100644 --- a/opencog/persist/rocks/RocksStorage.h +++ b/opencog/persist/rocks/RocksStorage.h @@ -96,7 +96,7 @@ class RocksStorage : public StorageNode void remFromSidList(const std::string&, const std::string&); void storeValue(const std::string& skid, const ValuePtr& vp); - void storeMissingAtom(AtomSpace*, const Handle&); + void storeMissingAtom(AtomSpace*, const Handle&, bool tmpMarker = false); void doRemoveAtom(const Handle&, bool recursive); ValuePtr getValue(const std::string&); From adff1990e87e79dc1c5028f25ad359855f8107b8 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Wed, 15 Nov 2023 09:12:46 +0100 Subject: [PATCH 02/22] redir preRemoveAtom to removeAtom --- opencog/persist/rocks/RocksStorage.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/opencog/persist/rocks/RocksStorage.h b/opencog/persist/rocks/RocksStorage.h index 027b476..7d1a750 100644 --- a/opencog/persist/rocks/RocksStorage.h +++ b/opencog/persist/rocks/RocksStorage.h @@ -146,6 +146,9 @@ class RocksStorage : public StorageNode void fetchIncomingByType(AtomSpace*, const Handle&, Type t); void storeAtom(const Handle&, bool synchronous = false); void removeAtom(AtomSpace*, const Handle&, bool recursive); + void preRemoveAtom(AtomSpace* as, const Handle& h, bool recursive) { + return removeAtom(as, h, recursive); + } void storeValue(const Handle& atom, const Handle& key); void updateValue(const Handle&, const Handle&, const ValuePtr&); void loadValue(const Handle& atom, const Handle& key); From ae780ee68c60778cf8eefa8b9e78da2783081f79 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Wed, 15 Nov 2023 09:46:45 +0100 Subject: [PATCH 03/22] def RocksStorage::postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 6 ++++++ opencog/persist/rocks/RocksStorage.h | 1 + 2 files changed, 7 insertions(+) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 5dde4c9..ac7b80b 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1019,6 +1019,12 @@ void RocksStorage::removeSatom(const std::string& satom, delete it; } +void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, + bool recursive, bool extracted) +{ + +} + // ========================================================= // Work with the incoming set diff --git a/opencog/persist/rocks/RocksStorage.h b/opencog/persist/rocks/RocksStorage.h index 7d1a750..ad0c591 100644 --- a/opencog/persist/rocks/RocksStorage.h +++ b/opencog/persist/rocks/RocksStorage.h @@ -149,6 +149,7 @@ class RocksStorage : public StorageNode void preRemoveAtom(AtomSpace* as, const Handle& h, bool recursive) { return removeAtom(as, h, recursive); } + void postRemoveAtom(AtomSpace* as, const Handle& h, bool recursive, bool extracted); void storeValue(const Handle& atom, const Handle& key); void updateValue(const Handle&, const Handle&, const ValuePtr&); void loadValue(const Handle& atom, const Handle& key); From 79dce2bef6432734fe1cd89cfa27666014fd138a Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Wed, 15 Nov 2023 10:28:21 +0100 Subject: [PATCH 04/22] loop in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index ac7b80b..b66aee9 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1022,7 +1022,13 @@ void RocksStorage::removeSatom(const std::string& satom, void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, bool recursive, bool extracted) { + std::string pfx = "k@"; + size_t cnt = 0; + auto it = _rfile->NewIterator(rocksdb::ReadOptions()); + for (it->Seek(pfx); it->Valid() and it->key().starts_with(pfx); it->Next()){ + + } } // ========================================================= From 11679b562955af6667390aa6da2568091f1e8ef9 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Fri, 17 Nov 2023 09:56:21 +0100 Subject: [PATCH 05/22] search4 -2 in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index b66aee9..8f4dee9 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1023,10 +1023,11 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, bool recursive, bool extracted) { std::string pfx = "k@"; + std::string sfx = "-2"; size_t cnt = 0; auto it = _rfile->NewIterator(rocksdb::ReadOptions()); - for (it->Seek(pfx); it->Valid() and it->key().starts_with(pfx); it->Next()){ + for (it->Seek(pfx); it->Valid() and it->key().starts_with(pfx) and it->key().ends_with(sfx); it->Next()){ } } From 26f181ced5a7dac51b1008d1b13270ea32088f01 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Fri, 17 Nov 2023 10:44:40 +0100 Subject: [PATCH 06/22] search atom a@... -2 in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 8f4dee9..9c48ee2 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1028,7 +1028,15 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, auto it = _rfile->NewIterator(rocksdb::ReadOptions()); for (it->Seek(pfx); it->Valid() and it->key().starts_with(pfx) and it->key().ends_with(sfx); it->Next()){ + std::string vkey = it->key().ToString(); + vkey[0] = 'a'; + vkey.resize(vkey.find(':') + 1); + std::string satom; + rocksdb::Status s = _rfile->Get(rocksdb::ReadOptions(), vkey, &satom); + if (not s.ok()) + throw IOException(TRACE_INFO, "Internal Error!"); + } } From e66219f3a31b51dd6fb3bf730655bd050f0e1d56 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Tue, 21 Nov 2023 10:42:07 +0100 Subject: [PATCH 07/22] get atom handle in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 9c48ee2..e2f11c9 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1036,7 +1036,11 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, rocksdb::Status s = _rfile->Get(rocksdb::ReadOptions(), vkey, &satom); if (not s.ok()) throw IOException(TRACE_INFO, "Internal Error!"); - + + // don't know if this is enough to get the atom from the correct frame + // it looks like in decode_atom a function decode_frame is called + // but atm this is a wild guess () + Handle h = Sexpr::decode_atom(satom); } } From 0554b0b2ab16c51bfc573afe23719f361e7fa03a Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Tue, 21 Nov 2023 11:25:45 +0100 Subject: [PATCH 08/22] absent check + set to -1 in postRemoveAtom (prelminary) --- opencog/persist/rocks/RocksIO.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index e2f11c9..90de6ab 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1041,6 +1041,18 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, // it looks like in decode_atom a function decode_frame is called // but atm this is a wild guess () Handle h = Sexpr::decode_atom(satom); + + // Atom::isAbsent is private atm, is this a problem ...? + if (h->isAbsent()){ + _rfile->Delete(rocksdb::WriteOptions(), it->key()); + // Store an intentionally invalid key. + std::string newkey = it->key().ToString(); + newkey.substr(); // do some string stuff + _rfile->Put(rocksdb::WriteOptions(), newkey, ""); + } else { + // 1. find the "a@ record and delete" + // 2. delete the "k@" record + } } } From d7e55ba30bab02036731b96e1e738b23c80051fa Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Thu, 23 Nov 2023 12:54:35 +0100 Subject: [PATCH 09/22] comment how to get a@ in DB --- opencog/persist/rocks/RocksIO.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 90de6ab..8acf028 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1050,7 +1050,7 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, newkey.substr(); // do some string stuff _rfile->Put(rocksdb::WriteOptions(), newkey, ""); } else { - // 1. find the "a@ record and delete" + // 1. find the "a@ record and delete" (see lines 1009-1019) // 2. delete the "k@" record } } From f00d94b1d8b6c6a0241501e6305370c03238e6e8 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Thu, 23 Nov 2023 13:08:59 +0100 Subject: [PATCH 10/22] rename key in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 8acf028..09be721 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1028,12 +1028,12 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, auto it = _rfile->NewIterator(rocksdb::ReadOptions()); for (it->Seek(pfx); it->Valid() and it->key().starts_with(pfx) and it->key().ends_with(sfx); it->Next()){ - std::string vkey = it->key().ToString(); - vkey[0] = 'a'; - vkey.resize(vkey.find(':') + 1); + std::string akey = it->key().ToString(); + akey[0] = 'a'; + akey.resize(vkey.find(':') + 1); std::string satom; - rocksdb::Status s = _rfile->Get(rocksdb::ReadOptions(), vkey, &satom); + rocksdb::Status s = _rfile->Get(rocksdb::ReadOptions(), akey, &satom); if (not s.ok()) throw IOException(TRACE_INFO, "Internal Error!"); From 03d8074fb4403d15893fcb924478886012d92db8 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Thu, 23 Nov 2023 13:11:55 +0100 Subject: [PATCH 11/22] rename key in postRemoveAtom 2 --- opencog/persist/rocks/RocksIO.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 09be721..7e934a7 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1030,7 +1030,7 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, for (it->Seek(pfx); it->Valid() and it->key().starts_with(pfx) and it->key().ends_with(sfx); it->Next()){ std::string akey = it->key().ToString(); akey[0] = 'a'; - akey.resize(vkey.find(':') + 1); + akey.resize(akey.find(':') + 1); std::string satom; rocksdb::Status s = _rfile->Get(rocksdb::ReadOptions(), akey, &satom); From bd6f2e3db8c5652acfeb00d96b234b5b5ac28079 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Thu, 23 Nov 2023 13:22:05 +0100 Subject: [PATCH 12/22] absent branch in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 7e934a7..598b546 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1045,9 +1045,9 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, // Atom::isAbsent is private atm, is this a problem ...? if (h->isAbsent()){ _rfile->Delete(rocksdb::WriteOptions(), it->key()); - // Store an intentionally invalid key. + // replace "-2" with "-1" std::string newkey = it->key().ToString(); - newkey.substr(); // do some string stuff + newkey = newkey.substr(newkey.size() - 2) + "-1"; _rfile->Put(rocksdb::WriteOptions(), newkey, ""); } else { // 1. find the "a@ record and delete" (see lines 1009-1019) From a3851e994e64dc7017c8bb29bd13b746135a5676 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Thu, 23 Nov 2023 14:31:35 +0100 Subject: [PATCH 13/22] delete a@ entry in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 598b546..4df19a8 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1051,6 +1051,8 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, _rfile->Put(rocksdb::WriteOptions(), newkey, ""); } else { // 1. find the "a@ record and delete" (see lines 1009-1019) + // do we have to worry also about "n@" : "l@" ? + _rfile->Delete(rocksdb::WriteOptions(), akey); // 2. delete the "k@" record } } From b524456494c0a1db73d262306a4744de7e7430a0 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Tue, 28 Nov 2023 13:12:15 +0100 Subject: [PATCH 14/22] delete k@ entry in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 4df19a8..19a977b 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1052,8 +1052,11 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, } else { // 1. find the "a@ record and delete" (see lines 1009-1019) // do we have to worry also about "n@" : "l@" ? + // do we need do check if this exists ? _rfile->Delete(rocksdb::WriteOptions(), akey); // 2. delete the "k@" record + // have to be careful, we have to delete the DB entry our loop is sitting on ....! + _rfile->Delete(rocksdb::WriteOptions(), it->key()); } } } From 9d30fd277ac064c773fbaabea6588c07c71c74d0 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Wed, 29 Nov 2023 10:42:56 +0100 Subject: [PATCH 15/22] handle extracted in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 19a977b..fa7a3ed 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1043,7 +1043,9 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, Handle h = Sexpr::decode_atom(satom); // Atom::isAbsent is private atm, is this a problem ...? - if (h->isAbsent()){ + // also if extracted is false (some error in As extract function), + // we also set back to -1 in DB (as it was before) + if (not extracted or h->isAbsent()){ _rfile->Delete(rocksdb::WriteOptions(), it->key()); // replace "-2" with "-1" std::string newkey = it->key().ToString(); From 019b20e2dffd3c02434662529414f853ec7f1b97 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Wed, 29 Nov 2023 11:38:00 +0100 Subject: [PATCH 16/22] is absent call changed in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index fa7a3ed..6e30048 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1045,7 +1045,7 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, // Atom::isAbsent is private atm, is this a problem ...? // also if extracted is false (some error in As extract function), // we also set back to -1 in DB (as it was before) - if (not extracted or h->isAbsent()){ + if (not extracted or isAtomAbsent(h)){ _rfile->Delete(rocksdb::WriteOptions(), it->key()); // replace "-2" with "-1" std::string newkey = it->key().ToString(); From 2ebea1b6996769787bce1065df00d2770752c3b3 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Thu, 30 Nov 2023 13:54:41 +0100 Subject: [PATCH 17/22] minoch changes in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 6e30048..415fa01 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1024,7 +1024,7 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, { std::string pfx = "k@"; std::string sfx = "-2"; - size_t cnt = 0; + auto it = _rfile->NewIterator(rocksdb::ReadOptions()); for (it->Seek(pfx); it->Valid() and it->key().starts_with(pfx) and it->key().ends_with(sfx); it->Next()){ @@ -1040,7 +1040,7 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, // don't know if this is enough to get the atom from the correct frame // it looks like in decode_atom a function decode_frame is called // but atm this is a wild guess () - Handle h = Sexpr::decode_atom(satom); + Handle h = Sexpr::decode_atom(satom.substr(2)); // Atom::isAbsent is private atm, is this a problem ...? // also if extracted is false (some error in As extract function), @@ -1054,7 +1054,9 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, } else { // 1. find the "a@ record and delete" (see lines 1009-1019) // do we have to worry also about "n@" : "l@" ? + // yes, I think we should delete "n@", they are the same as "a@" with rev. order! // do we need do check if this exists ? + // or maybe use "removeSatom" ? _rfile->Delete(rocksdb::WriteOptions(), akey); // 2. delete the "k@" record // have to be careful, we have to delete the DB entry our loop is sitting on ....! From 51faaf92150d5f14741d4cb9f994dbda4ce77fe4 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Sun, 3 Dec 2023 11:02:56 +0100 Subject: [PATCH 18/22] call remove function for single frame case in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 415fa01..2445313 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1019,6 +1019,7 @@ void RocksStorage::removeSatom(const std::string& satom, delete it; } +// under construction... void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, bool recursive, bool extracted) { @@ -1052,15 +1053,23 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, newkey = newkey.substr(newkey.size() - 2) + "-1"; _rfile->Put(rocksdb::WriteOptions(), newkey, ""); } else { + // First: try if it we can use the function for the + // single frame case + // just look what happens with the samples + // do we call "removeSatom" or its calling function "doRemoveAtom" ?: + removeSatom(satom, akey, h->is_node(), recursive); + + // alternative: // 1. find the "a@ record and delete" (see lines 1009-1019) // do we have to worry also about "n@" : "l@" ? // yes, I think we should delete "n@", they are the same as "a@" with rev. order! // do we need do check if this exists ? // or maybe use "removeSatom" ? - _rfile->Delete(rocksdb::WriteOptions(), akey); + // _rfile->Delete(rocksdb::WriteOptions(), akey); // 2. delete the "k@" record // have to be careful, we have to delete the DB entry our loop is sitting on ....! - _rfile->Delete(rocksdb::WriteOptions(), it->key()); + // _rfile->Delete(rocksdb::WriteOptions(), it->key()); + } } } From 71c877adc6684971e8f925096fec3e38b816e2a7 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Tue, 5 Dec 2023 15:07:07 +0100 Subject: [PATCH 19/22] fix string error in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 2445313..8819e70 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1041,7 +1041,7 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, // don't know if this is enough to get the atom from the correct frame // it looks like in decode_atom a function decode_frame is called // but atm this is a wild guess () - Handle h = Sexpr::decode_atom(satom.substr(2)); + Handle h = Sexpr::decode_atom(satom); // Atom::isAbsent is private atm, is this a problem ...? // also if extracted is false (some error in As extract function), From fcc947f49ac4bc8966df8da3af44233d1e5c0695 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Thu, 7 Dec 2023 13:28:05 +0100 Subject: [PATCH 20/22] delete before put in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index 8819e70..c5c8db8 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1047,10 +1047,10 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, // also if extracted is false (some error in As extract function), // we also set back to -1 in DB (as it was before) if (not extracted or isAtomAbsent(h)){ + std::string newkey = it->key().ToString(); + // replace "-2" with "-1" + newkey = newkey.substr(newkey.size() - 2) + "-1"; _rfile->Delete(rocksdb::WriteOptions(), it->key()); - // replace "-2" with "-1" - std::string newkey = it->key().ToString(); - newkey = newkey.substr(newkey.size() - 2) + "-1"; _rfile->Put(rocksdb::WriteOptions(), newkey, ""); } else { // First: try if it we can use the function for the From 59244f217e0e43262e87e42d1361eacf0eff1817 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Thu, 7 Dec 2023 14:27:00 +0100 Subject: [PATCH 21/22] improve messed up loop in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index c5c8db8..c350bee 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1028,7 +1028,10 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, auto it = _rfile->NewIterator(rocksdb::ReadOptions()); - for (it->Seek(pfx); it->Valid() and it->key().starts_with(pfx) and it->key().ends_with(sfx); it->Next()){ + for (it->Seek(pfx); it->Valid() and it->key().starts_with(pfx); it->Next()){ + if (not it->key().ends_with(sfx)) + continue; + std::string akey = it->key().ToString(); akey[0] = 'a'; akey.resize(akey.find(':') + 1); From 5efa6320c40c85d5e205ad93fe00fa36dc2180a5 Mon Sep 17 00:00:00 2001 From: sikefield3 Date: Fri, 8 Dec 2023 11:09:52 +0100 Subject: [PATCH 22/22] alternative deletion in postRemoveAtom --- opencog/persist/rocks/RocksIO.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/opencog/persist/rocks/RocksIO.cc b/opencog/persist/rocks/RocksIO.cc index c350bee..e808d8e 100644 --- a/opencog/persist/rocks/RocksIO.cc +++ b/opencog/persist/rocks/RocksIO.cc @@ -1060,7 +1060,7 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, // single frame case // just look what happens with the samples // do we call "removeSatom" or its calling function "doRemoveAtom" ?: - removeSatom(satom, akey, h->is_node(), recursive); + // removeSatom(satom, akey, h->is_node(), recursive); // alternative: // 1. find the "a@ record and delete" (see lines 1009-1019) @@ -1068,11 +1068,15 @@ void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h, // yes, I think we should delete "n@", they are the same as "a@" with rev. order! // do we need do check if this exists ? // or maybe use "removeSatom" ? + // also maybe hash has to be removed // _rfile->Delete(rocksdb::WriteOptions(), akey); + std::string nlpfx = h->is_node() ? "n@" : "l@"; + _rfile->Delete(rocksdb::WriteOptions(), nlpfx + satom); + _rfile->Delete(rocksdb::WriteOptions(), akey); + // 2. delete the "k@" record // have to be careful, we have to delete the DB entry our loop is sitting on ....! - // _rfile->Delete(rocksdb::WriteOptions(), it->key()); - + _rfile->Delete(rocksdb::WriteOptions(), it->key()); } } }