Skip to content

Commit

Permalink
Implement incoming-set fetch
Browse files Browse the repository at this point in the history
Also switch to the new API for loading/storing
  • Loading branch information
linas committed Oct 25, 2019
1 parent c663cb6 commit 01d102f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 59 deletions.
3 changes: 3 additions & 0 deletions examples/restore-ro.scm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
(define ll (List (Concept "foo") (Concept "bar")))
(fetch-incoming-set ll)

; Verify that the EvaluationLink was loaded.
(cog-prt-atomspace)

; Review the stats
(ipfs-stats)

Expand Down
6 changes: 2 additions & 4 deletions opencog/persist/ipfs/IPFSAtomStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,11 @@ class IPFSAtomStorage : public BackingStore
void storeAtom(const Handle&, bool synchronous = false);
void removeAtom(const Handle&, bool recursive);
void loadType(AtomTable&, Type);
void loadAtomSpace(AtomTable&); // Load entire contents
void storeAtomSpace(const AtomTable&); // Store entire contents
void barrier();
void flushStoreQueue();

// Large-scale loads and saves
void loadAtomSpace(AtomSpace*);
void storeAtomSpace(AtomSpace*);
void store(const AtomTable &); // Store entire contents of AtomTable

// Debugging and performance monitoring
void print_stats(void);
Expand Down
15 changes: 4 additions & 11 deletions opencog/persist/ipfs/IPFSBulk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void IPFSAtomStorage::loadType(AtomTable &table, Type atom_type)
}

/// Store all of the atoms in the atom table.
void IPFSAtomStorage::store(const AtomTable &table)
void IPFSAtomStorage::storeAtomSpace(const AtomTable &table)
{
rethrow();

Expand Down Expand Up @@ -176,17 +176,10 @@ void IPFSAtomStorage::store(const AtomTable &table)
printf("\tAtomSpace CID: %s\n", _atomspace_cid.c_str());
}

void IPFSAtomStorage::storeAtomSpace(AtomSpace* atomspace)
void IPFSAtomStorage::loadAtomSpace(AtomTable &table)
{
store(atomspace->get_atomtable());
}

void IPFSAtomStorage::loadAtomSpace(AtomSpace* atomspace)
{
// XXX This is wrong, it should instead do an IPNS resolve
// and load that!
throw SyntaxException(TRACE_INFO, "Not Implemented!\n");
load_atomspace(atomspace, _atomspace_cid);
// XXX FIXME This should probably do an IPNS resolve first ??
load_atomspace(table.getAtomSpace(), _atomspace_cid);
}

/* ============================= END OF FILE ================= */
20 changes: 16 additions & 4 deletions opencog/persist/ipfs/IPFSIncoming.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void IPFSAtomStorage::store_incoming_of(const Handle& atom,
* Retreive the entire incoming set of the indicated atom.
* This fetches only teh Atoms in the incoming set, and not
* the Values associated with them! XXX FIXME Double check,
* I think the intent is to also get teh attached values,
* I think the intent is to also get the attached values,
* but I'm not sure, because the spec is ill-defined on this
* and I'm not sure what postgres is going, here. All backends
* should be compatible on this.
Expand All @@ -72,11 +72,23 @@ void IPFSAtomStorage::getIncomingSet(AtomTable& table, const Handle& h)
{
rethrow();

#if 0
std::string path = _atomspace_cid + "/" + h->to_short_string();

ipfs::Json dag;
ipfs::Client* conn = conn_pool.pop();
conn->DagGet(path, &dag);
conn_pool.push(conn);
std::cout << "The dag is:" << dag.dump(2) << std::endl;

auto iset = dag["incoming"];
for (auto acid: iset)
{
std::cout << "The incoming is:" << acid.dump(2) << std::endl;
table.add(fetch_atom(acid), false);
}

_num_get_insets++;
_num_get_inlinks += iset.size();
#endif
throw SyntaxException(TRACE_INFO, "Not Implemented!\n");
}

/**
Expand Down
20 changes: 0 additions & 20 deletions opencog/persist/ipfs/IPFSPersistSCM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ void IPFSPersistSCM::init(void)
{
define_scheme_primitive("ipfs-open", &IPFSPersistSCM::do_open, this, "persist-ipfs");
define_scheme_primitive("ipfs-close", &IPFSPersistSCM::do_close, this, "persist-ipfs");
define_scheme_primitive("ipfs-load", &IPFSPersistSCM::do_load, this, "persist-ipfs");
define_scheme_primitive("ipfs-store", &IPFSPersistSCM::do_store, this, "persist-ipfs");
define_scheme_primitive("ipfs-stats", &IPFSPersistSCM::do_stats, this, "persist-ipfs");
define_scheme_primitive("ipfs-clear-stats", &IPFSPersistSCM::do_clear_stats, this, "persist-ipfs");

Expand Down Expand Up @@ -119,24 +117,6 @@ void IPFSPersistSCM::do_close(void)
delete backing;
}

void IPFSPersistSCM::do_load(void)
{
if (nullptr == _backing)
throw RuntimeException(TRACE_INFO,
"ipfs-load: Error: Database not open");

_backing->loadAtomSpace(_as);
}

void IPFSPersistSCM::do_store(void)
{
if (nullptr == _backing)
throw RuntimeException(TRACE_INFO,
"ipfs-store: Error: Database not open");

_backing->storeAtomSpace(_as);
}

std::string IPFSPersistSCM::do_atom_cid(const Handle& h)
{
if (nullptr == _backing)
Expand Down
21 changes: 1 addition & 20 deletions opencog/scm/opencog/persist-ipfs.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
(string-append opencog-ext-path-persist-ipfs "libpersist-ipfs")
"opencog_persist_ipfs_init")

(export ipfs-clear-stats ipfs-close ipfs-load ipfs-open
ipfs-store ipfs-stats
(export ipfs-clear-stats ipfs-close ipfs-open ipfs-stats
ipfs-atom-cid ipfs-fetch-atom
ipfs-atomspace-cid ipns-atomspace-cid ipfs-atomspace-resolve)

Expand All @@ -32,15 +31,6 @@
no longer be stored to or fetched from the database.
")

(set-procedure-property! ipfs-load 'documentation
"
ipfs-load - load all atoms in the database.
This will cause ALL of the atoms in the open database to be loaded
into the atomspace. This can be a very time-consuming operation.
In normal operation, it is rarely necessary to load all atoms;
atoms can always be fetched and stored one at a time, on demand.
")

(set-procedure-property! ipfs-open 'documentation
"
ipfs-open URL - Open a connection to an IPFS server.
Expand All @@ -59,15 +49,6 @@
(ipfs-open \"ipfs://localhost:5001/atomspace-test\")
")

(set-procedure-property! ipfs-store 'documentation
"
ipfs-store - Store all atoms in the atomspace to the database.
This will dump the ENTIRE contents of the atomspace to the databse.
Depending on the size of the database, this can potentially take a
lot of time. During normal operation, a bulk-save is rarely
required, as individual atoms can always be stored, one at a time.
")

(set-procedure-property! ipfs-stats 'documentation
"
ipfs-stats - report performance statistics.
Expand Down

0 comments on commit 01d102f

Please sign in to comment.