[Mulgara-general] Two Database instances in the same process?
Karsten Huneycutt
kph at skuld.us
Sun Sep 27 20:06:53 UTC 2009
Hello --
First: Does Mulgara 2.1.3 allow one to have two distinct Database
instances (and therefore two distinct XA1.1 StringPools, etc) in the
same process?
If it doesn't, then I'll stop trying to do that. If it does, then I
must be doing something incorrectly...
A bit of background as to why I'm trying to do this: I need to have
something that applies rules to a set of graphs (that the consuming
application accesses via a view) in the background that doesn't stop
modification of the original graphs while the rules are being
applied. Each modification of the original graphs triggers a
background reasoning run, so any entailments that are invalidated by
the modifications will be corrected on the next pass of the reasoner;
for me, this temporary inaccuracy is an acceptable trade-off for the
responsiveness of modification that I require.
I first tried to copy the sub-graphs over which I wanted to reason
into a separate graph in the same database, do the reasoning into a
separate entailments graph, and then copy the results back into an
entailments graph in the view. That didn't work, of course -- as I
learned, the "apply" command write-locks the entire database, not just
the graphs on which it's applying, which holds up modification of the
original graphs for the three to five minutes while the entailments
are being calculated.
So, I went down the road of copying the graphs to a separate database
in the same process.
The following example code shows what I'm trying to do:
public class TwoDatabases {
public static void main(String[] args) {
Database db1 = null;
Database db2 = null;
try {
URL l4j = TwoDatabases.class.getClassLoader().getResource("conf/
log4j-mulgara.xml");
org.apache.log4j.xml.DOMConfigurator.configure(l4j);
MulgaraUserConfig cfg1 = new MulgaraUserConfig("file:///tmp/mulgara-config1.xml
");
MulgaraUserConfig cfg2 = new MulgaraUserConfig("file:///tmp/mulgara-config2.xml
");
File path1 = new File("/tmp/path1");
File path2 = new File("/tmp/path2");
URI uri1 = new URI("local:db1");
URI uri2 = new URI("local:db2");
db1 = DatabaseFactory.newDatabase(uri1, path1, cfg1);
db2 = DatabaseFactory.newDatabase(uri2, path2, cfg2);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (db1 != null) db1.close();
if (db2 != null) db2.close();
}
}
}
/tmp/mulgara-config1.xml is:
<MulgaraConfig>
<PersistencePath>/tmp/path1</PersistencePath>
</MulgaraConfig>
and /tmp/mulgara-config2.xml is
<MulgaraConfig>
<PersistencePath>/tmp/path2</PersistencePath>
</MulgaraConfig>
db1 is created normally, and all is well with it. However, when
DatabaseFactory attempts to create db2, I get the following exception:
java.io.IOException: Lock file busy (internal): /tmp/path1/
xaStringPool/xa11.sp.lock
at org.mulgara.store.xa.LockFile.lockInternal(LockFile.java:151)
at org.mulgara.store.xa.LockFile.<init>(LockFile.java:95)
at org.mulgara.store.xa.LockFile.createLockFile(LockFile.java:137)
at org.mulgara.store.xa.LockFile.createLockFile(LockFile.java:123)
at org.mulgara.store.stringpool.xa11.XA11StringPoolImpl.<init>
(XA11StringPoolImpl.java:166)
at
org.mulgara.store.stringpool.xa11.XA11StringPoolFactory.newStringPool
(XA11StringPoolFactory.java:91)
at org.mulgara.resolver.StringPoolSessionFactory.<init>
(StringPoolSessionFactory.java:134)
at org.mulgara.resolver.Database.<init>(Database.java:867)
at org.mulgara.resolver.Database.<init>(Database.java:629)
at org.mulgara.resolver.DatabaseFactory.newDatabase
(DatabaseFactory.java:97)
at TwoDatabases.main(TwoDatabases.java:27)
org.mulgara.store.stringpool.StringPoolException: Couldn't construct
string pool
at
org.mulgara.store.stringpool.xa11.XA11StringPoolFactory.newStringPool
(XA11StringPoolFactory.java:95)
at org.mulgara.resolver.StringPoolSessionFactory.<init>
(StringPoolSessionFactory.java:134)
at org.mulgara.resolver.Database.<init>(Database.java:867)
at org.mulgara.resolver.Database.<init>(Database.java:629)
at org.mulgara.resolver.DatabaseFactory.newDatabase
(DatabaseFactory.java:97)
at TwoDatabases.main(TwoDatabases.java:27)
Caused by: java.io.IOException: Lock file busy (internal): /tmp/path1/
xaStringPool/xa11.sp.lock
at org.mulgara.store.xa.LockFile.lockInternal(LockFile.java:151)
at org.mulgara.store.xa.LockFile.<init>(LockFile.java:95)
at org.mulgara.store.xa.LockFile.createLockFile(LockFile.java:137)
at org.mulgara.store.xa.LockFile.createLockFile(LockFile.java:123)
at org.mulgara.store.stringpool.xa11.XA11StringPoolImpl.<init>
(XA11StringPoolImpl.java:166)
at
org.mulgara.store.stringpool.xa11.XA11StringPoolFactory.newStringPool
(XA11StringPoolFactory.java:91)
... 5 more
Note in particular that it says "/tmp/path1/...", which was correct
for db1 but not for db2! What am I doing incorrectly?
I'm currently shipping the reasoning off to a separate Mulgara
process, using temporary files and RMI, but that seems inefficient,
and I'd like to keep it all in the same process.
Alternately, is there a better way to do what I described than using a
separate database (be it in the same process or a separate process)?
(Note that, for now, I don't care so much about memory use or disk use.)
My apologies if these questions have already been asked and answered;
I couldn't find the answer in the archives of the lists or in the wiki.
Thanks!
KH
--
Karsten Huneycutt
kph at skuld.us
More information about the Mulgara-general
mailing list