You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Andreas Grünwald <a....@gmail.com> on 2013/11/06 20:03:09 UTC

Jena TDB Sync between different applications fails

Hello,
I have a situation with a very strange behavior which I cannot explain by
myself:

I have 3 different applications, all running in different Java processes,
but all on the same computer.

Whenever I update an existing record with Jena TDB then these updates are
only recognized by the same application. The other applications either do
not recognize the update at all, or only sporadically.

Here is a detailed description:

   - Process A is a very simple unit test. I read the Jena record TDB
   dataset (TDBFactory.createDataset(directory), and the current values. Let's
   say the field 'A.b' of record 'A' has the value 'xxx'. I update the value
   to 'yyy' and persist the change with a commit() followed by end(). During
   the same run I re-read the record and as supposed the value of 'A.b' =
   'yyy'.
   - When I restart Process A the value of 'A.b' is still 'yyy'.
   - However, when I start the second application (let's say B), which is a
   Wicket-Webapp running with Jetty, the value is still 'xxx'.

I tried quite a lot of things: Besides using TDB transactions properly, I
also take care that after each commit() the transaction is ended with
end(). Also, read-transactions are opened with .begin(ReadWrite.READ).
Additionally, I added TDB.sync(tdbDataSet); although I am not sure if this
is necessary when using transactions properly.

I am quite confused how this behaviour can appear. A little explanation of
the underlying transaction handling would be very helpful. Maybe any of you
has an idea what the reason may be?

I also checked the Jena TDB files and can tell you that after updating the
single record, the following files are updated (I don't know if this is
helpful):
* journal.jrnl
* node2id
* nodes.dat
* nodes.dat-jrnl (0 bytes)
* prefixes.dat-jrnl (0 bytes)

I apprechiate any help.
Best, Andreas

Re: Jena TDB Sync between different applications fails

Posted by Andy Seaborne <an...@apache.org>.
Hi Andreas,

TDB databases can not be share dbetween processes in the way you are 
doing it.  One database needs to be controlled and accessed by one java 
process at a time.  There is a lot of caching going on and update via 
one route wil not be seen by another process.  Indeed, eventually, you 
will corrupt the database.

If you want to share database between processes, then you need a 
database server.  Fuseki gives you that ability.

	Andy

On 07/11/13 06:41, Andreas Grünwald wrote:
> Yesterday I sent an example of a sync problem.
> Today I managed to resolve parts of it.
> I did not mention yesterday that I am using an OntModel, which seems to be
> important to reproduce the problem.
>
> By adding TDB.sycn(ontModel) after the tdbDataSet commit I was able to
> solve the problem (partly).
>
> jUnit test:
>
> Dataset tdbDataSet = TDBFactory.createDataset(directory);
> TDB.sync(tdbDataSet);
> tdbDataSet.begin(ReadWrite.WRITE);
> this.model = tdbDataSet.getNamedModel(this.getOntologySchemaIRI());
> this.ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model
> );
> //make some modifications in the ontmodel, e..g change a data property of
> an individual named "A".
>
> tdbDataSet.commit();
> ontModel.commit();
> model.commit();
> TDB.sync(ontModel);
> TDB.sync(model);
> tdbDataSet.close();
>
>
> Web App:
> Dataset tdbDataSet = TDBFactory.createDataset(directory);
> *TDBFactory.reset(); *
> TDB.sync(tdbDataSet);
> tdbDataSet.begin(ReadWrite.READ);
> this.model = tdbDataSet.getNamedModel(this.getOntologySchemaIRI());
> this.ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model
> );
>
> //read data from the ontmodel, e.g.
> OntModel ont = this.con.getOntologyModel();
>
> List<Statement> list = new LinkedList<Statement>();
> Individual linkedIndividual = ont.getIndividual("A");
> com.hp.hpl.jena.rdf.model.StmtIterator it = individual.listProperties();
>
> while (it.hasNext()) {
>     Statement stmt = it.next();
>      ...
>
> }
>
> tdbDataSet.end();
>
> There is still one problem: The data in the Web app is not refreshed until
> I restart the application.
> Adding
> *TDBFactory.reset(); *
> after the initialization of the dtbDataSet solves the problem.
> However, I think using TDBFactory.reset(); is bad practice and I want to
> avoid it.
>
> Any idea how I can do that?
>
> Thanks,
>
> Andreas
>
>
>
>
> On Wed, Nov 6, 2013 at 8:03 PM, Andreas Grünwald <a....@gmail.com> wrote:
>
>> Hello,
>> I have a situation with a very strange behavior which I cannot explain by
>> myself:
>>
>> I have 3 different applications, all running in different Java processes,
>> but all on the same computer.
>>
>> Whenever I update an existing record with Jena TDB then these updates are
>> only recognized by the same application. The other applications either do
>> not recognize the update at all, or only sporadically.
>>
>> Here is a detailed description:
>>
>>     - Process A is a very simple unit test. I read the Jena record TDB
>>     dataset (TDBFactory.createDataset(directory), and the current values. Let's
>>     say the field 'A.b' of record 'A' has the value 'xxx'. I update the value
>>     to 'yyy' and persist the change with a commit() followed by end(). During
>>     the same run I re-read the record and as supposed the value of 'A.b' =
>>     'yyy'.
>>     - When I restart Process A the value of 'A.b' is still 'yyy'.
>>     - However, when I start the second application (let's say B), which is
>>     a Wicket-Webapp running with Jetty, the value is still 'xxx'.
>>
>> I tried quite a lot of things: Besides using TDB transactions properly, I
>> also take care that after each commit() the transaction is ended with
>> end(). Also, read-transactions are opened with .begin(ReadWrite.READ).
>> Additionally, I added TDB.sync(tdbDataSet); although I am not sure if
>> this is necessary when using transactions properly.
>>
>> I am quite confused how this behaviour can appear. A little explanation of
>> the underlying transaction handling would be very helpful. Maybe any of you
>> has an idea what the reason may be?
>>
>> I also checked the Jena TDB files and can tell you that after updating the
>> single record, the following files are updated (I don't know if this is
>> helpful):
>> * journal.jrnl
>> * node2id
>> * nodes.dat
>> * nodes.dat-jrnl (0 bytes)
>> * prefixes.dat-jrnl (0 bytes)
>>
>> I apprechiate any help.
>> Best, Andreas
>>
>
>
>


Re: Jena TDB Sync between different applications fails

Posted by Andreas Grünwald <a....@gmail.com>.
Yesterday I sent an example of a sync problem.
Today I managed to resolve parts of it.
I did not mention yesterday that I am using an OntModel, which seems to be
important to reproduce the problem.

By adding TDB.sycn(ontModel) after the tdbDataSet commit I was able to
solve the problem (partly).

jUnit test:

Dataset tdbDataSet = TDBFactory.createDataset(directory);
TDB.sync(tdbDataSet);
tdbDataSet.begin(ReadWrite.WRITE);
this.model = tdbDataSet.getNamedModel(this.getOntologySchemaIRI());
this.ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model
);
//make some modifications in the ontmodel, e..g change a data property of
an individual named "A".

tdbDataSet.commit();
ontModel.commit();
model.commit();
TDB.sync(ontModel);
TDB.sync(model);
tdbDataSet.close();


Web App:
Dataset tdbDataSet = TDBFactory.createDataset(directory);
*TDBFactory.reset(); *
TDB.sync(tdbDataSet);
tdbDataSet.begin(ReadWrite.READ);
this.model = tdbDataSet.getNamedModel(this.getOntologySchemaIRI());
this.ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model
);

//read data from the ontmodel, e.g.
OntModel ont = this.con.getOntologyModel();

List<Statement> list = new LinkedList<Statement>();
Individual linkedIndividual = ont.getIndividual("A");
com.hp.hpl.jena.rdf.model.StmtIterator it = individual.listProperties();

while (it.hasNext()) {
   Statement stmt = it.next();
    ...

}

tdbDataSet.end();

There is still one problem: The data in the Web app is not refreshed until
I restart the application.
Adding
*TDBFactory.reset(); *
after the initialization of the dtbDataSet solves the problem.
However, I think using TDBFactory.reset(); is bad practice and I want to
avoid it.

Any idea how I can do that?

Thanks,

Andreas




On Wed, Nov 6, 2013 at 8:03 PM, Andreas Grünwald <a....@gmail.com> wrote:

> Hello,
> I have a situation with a very strange behavior which I cannot explain by
> myself:
>
> I have 3 different applications, all running in different Java processes,
> but all on the same computer.
>
> Whenever I update an existing record with Jena TDB then these updates are
> only recognized by the same application. The other applications either do
> not recognize the update at all, or only sporadically.
>
> Here is a detailed description:
>
>    - Process A is a very simple unit test. I read the Jena record TDB
>    dataset (TDBFactory.createDataset(directory), and the current values. Let's
>    say the field 'A.b' of record 'A' has the value 'xxx'. I update the value
>    to 'yyy' and persist the change with a commit() followed by end(). During
>    the same run I re-read the record and as supposed the value of 'A.b' =
>    'yyy'.
>    - When I restart Process A the value of 'A.b' is still 'yyy'.
>    - However, when I start the second application (let's say B), which is
>    a Wicket-Webapp running with Jetty, the value is still 'xxx'.
>
> I tried quite a lot of things: Besides using TDB transactions properly, I
> also take care that after each commit() the transaction is ended with
> end(). Also, read-transactions are opened with .begin(ReadWrite.READ).
> Additionally, I added TDB.sync(tdbDataSet); although I am not sure if
> this is necessary when using transactions properly.
>
> I am quite confused how this behaviour can appear. A little explanation of
> the underlying transaction handling would be very helpful. Maybe any of you
> has an idea what the reason may be?
>
> I also checked the Jena TDB files and can tell you that after updating the
> single record, the following files are updated (I don't know if this is
> helpful):
> * journal.jrnl
> * node2id
> * nodes.dat
> * nodes.dat-jrnl (0 bytes)
> * prefixes.dat-jrnl (0 bytes)
>
> I apprechiate any help.
> Best, Andreas
>



-- 
Andreas Grünwald
Tel.: +43 650 77 82340