On 30/01/14 14:35, Jean-Marc Vanel wrote:
So, close is discouraged, and seems no more useful.
Then, is one of TDB.sync() useful to call, or is TDB imune to sudden power
off ?
If you use transactions, then it's immune to power off, JVM crahses or
"kill -9". You are not using transactions in that test case -- no
.begin/.commit/.end
http://jena.apache.org/documentation/tdb/tdb_transactions.html
If you use it non-transactionally, use TDB.sync at least before exiting
the JVM, but better every so often, but it's not proof against crashes
that way when updates have happened but TDB.sync has not returned. A
crash during TDB.sync can corrupt the DB. (It is OK for read-only use -
but read transactions are very cheap so use them).
Andy
2014-01-30 Andy Seaborne <[email protected]>
Hi Jean-Marc,
Thank you for the report - especially a link to the complete code as well
as the in-email description and discussion.
This is JENA-571, or rather it's reverse. It looks like there is a bad
side effect due to caching. The closed graph is still in the DatasetGraph
cache and also in the DatasetCache.
I've reopened JENA-571. I suspect that caching of graphs (and models
higher up) is not nearly as import as it once was.
Workaround is to not close models (or datasets).
In TDB, the true state is on-disk and also in a single system wide object
for the location. This is shared, which is essential because it avoids a
lot of disk I/O on opening.creating. .close() isn't really doing anything
much.
Andy
On 29/01/14 12:30, Jean-Marc Vanel wrote:
Hi
Jena 2.11.1 TBD throws ClosedException: "already closed", when 2.11.0 did
not.
The test below involves adding a triple in a named model,
closing the model,
re-opening the dataset and the same model.
Note that closing the whole dataset instead of the model works fine.
Here is the test (sorry , it's in Scala):
@Test def storeTripleinNamedDatasetandRetrieve() {
val directory = new File("bbtest");
directory.mkdirs();
val dataset = TDBFactory.createDataset(directory.getAbsolutePath());
val modelName = "test" // "<test>"
val model = dataset.getNamedModel(modelName);
val obj = "a"
val subject = "c"
val predicate = model.createProperty("p");
val subjectResource = model.createResource(subject);
val objectResource = model.createResource(obj);
model.add(model.createStatement(subjectResource, predicate,
objectResource))
if (!model.isClosed()) {
model.close(); // com.hp.hpl.jena.shared.ClosedException: already
closed
// dataset.close(); // OK!
System.out.println("Test TDB: model closed:\t" + dataset)
}
{
val dataset = TDBFactory.createDataset(
directory.getAbsolutePath());
val model = dataset.getNamedModel(modelName);
System.out.println("Test TDB: model reopened:\t" + dataset)
println(
"model.size() " +
model.size())
val sIter = model.listStatements()
for (st <- sIter) {
println(st)
}
assertTrue("model.size == 1", model.size == 1);
}
Complete code:
http://svn.code.sf.net/p/eulergui/code/trunk/eulergui/
src/test/scala/eulergui/jena/JenaTDBTest.scala