Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not hide atoms #24

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7ca4890
set temporary marker to -2
sikefield3 Nov 14, 2023
adff199
redir preRemoveAtom to removeAtom
sikefield3 Nov 15, 2023
ae780ee
def RocksStorage::postRemoveAtom
sikefield3 Nov 15, 2023
79dce2b
loop in postRemoveAtom
sikefield3 Nov 15, 2023
11679b5
search4 -2 in postRemoveAtom
sikefield3 Nov 17, 2023
26f181c
search atom a@... -2 in postRemoveAtom
sikefield3 Nov 17, 2023
e66219f
get atom handle in postRemoveAtom
sikefield3 Nov 21, 2023
0554b0b
absent check + set to -1 in postRemoveAtom (prelminary)
sikefield3 Nov 21, 2023
d7e55ba
comment how to get a@ in DB
sikefield3 Nov 23, 2023
f00d94b
rename key in postRemoveAtom
sikefield3 Nov 23, 2023
03d8074
rename key in postRemoveAtom 2
sikefield3 Nov 23, 2023
bd6f2e3
absent branch in postRemoveAtom
sikefield3 Nov 23, 2023
a3851e9
delete a@ entry in postRemoveAtom
sikefield3 Nov 23, 2023
b524456
delete k@ entry in postRemoveAtom
sikefield3 Nov 28, 2023
9d30fd2
handle extracted in postRemoveAtom
sikefield3 Nov 29, 2023
019b20e
is absent call changed in postRemoveAtom
sikefield3 Nov 29, 2023
2ebea1b
minoch changes in postRemoveAtom
sikefield3 Nov 30, 2023
51faaf9
call remove function for single frame case in postRemoveAtom
sikefield3 Dec 3, 2023
71c877a
fix string error in postRemoveAtom
sikefield3 Dec 5, 2023
fcc947f
delete before put in postRemoveAtom
sikefield3 Dec 7, 2023
59244f2
improve messed up loop in postRemoveAtom
sikefield3 Dec 7, 2023
5efa632
alternative deletion in postRemoveAtom
sikefield3 Dec 8, 2023
8516464
Merge branch 'not_hide_atoms'
sikefield3 Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions opencog/persist/rocks/RocksIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
Expand Down Expand Up @@ -806,7 +807,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)
Expand Down Expand Up @@ -1025,6 +1026,68 @@ void RocksStorage::removeSatom(const std::string& satom,
delete it;
}

// under construction...
void RocksStorage::postRemoveAtom(AtomSpace* as, const Handle& h,
bool recursive, bool extracted)
{
std::string pfx = "k@";
std::string sfx = "-2";

auto it = _rfile->NewIterator(rocksdb::ReadOptions());

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);

std::string satom;
rocksdb::Status s = _rfile->Get(rocksdb::ReadOptions(), akey, &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);

// 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 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());
_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" ?
// 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());
}
}
}

// =========================================================
// Work with the incoming set

Expand Down
6 changes: 5 additions & 1 deletion opencog/persist/rocks/RocksStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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&);
Expand Down Expand Up @@ -147,6 +147,10 @@ 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 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);
Expand Down