sleyzerzon / soar

Automatically exported from code.google.com/p/soar
1 stars 0 forks source link

EpMem and SMem Database Enhancement - Multiple Agents Same System #147

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Currently CSoar does not support multiple agents in the same database nor does 
it support epmem and smem in the same database.  This is a feature request for 
both of these.  Theoretically smem and epmem are set up to support being in the 
same database, the only issue is that currently they both try to connect to the 
database even if it is open in the other memory (ie. epmem has open 
/csoar.sqlite and smem tries to connect again to /csoar.sqlite).  This will 
fail because you cannot have multiple connections to the same sqlite database.

The second part of this feature requests is multiple agents in the same 
database.  The reason you would want to do this is in an embedded system 
because typically these will have little space on an hdd and if you want CSoar 
to run for a long time with an smem and epmem db you will want to write it to a 
file and will run out of space eventually.  The solution to this is to support 
multiple connections to a db over the network (either via TCP or fancy file 
system hacks, ie. network drive mounting).  Support for this actually isn't too 
hard to implement, it just requires the following:

1. Change the statements from a hardcoded epmem_ or smem_ prefix to a variable 
(as in JSoar) and then support replacing say "@PREFIX@" in those statements 
with the prefix.  JSoar already does this and so you can just copy the 
statements from JSoar and look at how JSoar does this replacement for an 
example and for code which already works.

2. Change how the database is loaded.  You would have to check whether smem and 
epmem are trying to connect to the same database, and if they are, use the 
existing connection.  You also have to have code which, once the database is 
loaded, polls for the latest prefix.  To do this, you could do something like 
the following:

Have a table called 'prefix' (without a prefix, just like the versions table) 
and in the table have the following format:

| id | system | count |
-----------------------
| 1  | epmem  |   1   |
| 2  | smem   |   1   |
| 3  | smem   |   2   |
-----------------------

So to get the latest prefix, you would have a sql statement like "SELECT count 
FROM prefix WHERE system='epmem' ORDER BY DESC" which would return as the first 
result, the last epmem schema count.

3. Then once you get the last count you have a statement which sets the prefix 
based on the count, so you have 'epmem_' for a count of '0' and 'epmem2_' for a 
count of '1' and so on ((++count) > 1 ? count : "");

The only issue in CSoar is that if you wanted to have multiple agents outside 
of one kernel connecting to the same database, you would need to use something 
other than sqlite because it isn't designed to allow multiple connections that 
support read/write.  You would need to add support for networked databases for 
instance via a mysql driver or postgresql driver or something like that.  In 
CSoar this might be a bit of a problem to provide an abstraction around the 
databases but I haven't looked in CSoar too much at how one might do that.  I 
would bet though that it wouldn't be too hard to do that, you would need to 
handle differences between supported drivers though.

Original issue reported on code.google.com by alex.tur...@soartech.com on 6 Aug 2013 at 2:00

GoogleCodeExporter commented 9 years ago

Original comment by pawngam...@gmail.com on 6 Aug 2013 at 2:01