ReadThruProxy

From OpenCog

The ReadThruProxyNode is a ProxyNode that passes on requests involving the reading of Atoms and Values. This includes `fetch-atom`, `fetch-value`, `fetch-incoming-set` and `fetch-incoming-by-type`. This is a load-balancing proxy: if there are multiple providers, it will pick one and use that for a given request.

Example

Suppose you want to load-balance data reads from three different databases. The following will create a proxy that will round-robin between the three:

  (ProxyParameters
     (ReadThruProxy "read-thru load balancer")
     (List
        (RocksStorageNode "rocks:///tmp/foo.rdb")
        (RocksStorageNode "rocks:///tmp/bar.rdb")
        (RocksStorageNode "rocks:///tmp/fizz-buzz.rdb"))))

Reading will proceed by round-robin: the first data source will be used for the first read; the second data source for the second read, and so on, looping back to the beginning. To actually use this, open the proxy just like any other StorageNode:

(cog-open (ReadThruProxy "read-thru load balancer"))

Then you can fetch data:

(fetch-atom (Concept "foo"))

which will fetch the TruthValue on (Concept "foo"), and all other Values as well, assuming that it was in the database.

The StorageNodes in the list can be any other StorageNodes, or even other Proxies. So, for example, this will work:

  (ProxyParameters
     (ReadThruProxy "another read-thru proxy")
     (List
        (RocksStorageNode "rocks:///tmp/foo.rdb")
        (CogStorageNode "cog://example.com:17001")
        (ReadThruProxy "up to your imagination"))))

Of course, if these three do not contain identical data, then the a round-robin will be very confusing to understand. To avoid this, use the SequentialReadProxy.

See /examples/atomspace/persist-proxy.scm for a working example involving the CogServer.

See also