Search code examples
eclipsegoogle-app-enginegwtjdodatanucleus

App-Engine JDO consistent reading not working, maybe caching?


Today it's the first time I'm using GWT and JDO. I am running it with Eclipse in the local debug mode.

I do the following thing:

    public Collection<MyObject> add(MyObject o) {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
    pm.makePersistent(o);
    Query query = pm.newQuery(MyObject.class);// fetch all objects incl. o. But o only sometimes comes...
List<MyObject> rs = (List<MyObject>) query.execute();
ArrayList<MyObject> list= new ArrayList<MyObject>();
for (MyObject r : rs) {
    list.add(r);
}
return list; 
} finally {
    pm.close();
}
}

I already set <property name="datanucleus.appengine.datastoreReadConsistency" value="STRONG" /> in my jdoconfig.xml. Do I have to set some other transaction stuff in the config? Was somebody got a working jdoconfig.xml? Or is the problem somewhere else? Some caching inbetween?

EDIT: Things I have tried:

  • Setting NontransactionalRead/Write to false
  • Using the same/a different PersistenceManager though calling PMF.get().getPersistenceManager() multiple times
  • Using transactions
  • ignoreCache = true on PersistenceManager
  • calling flush and checkConsistency

The jdoconfig:

    <persistence-manager-factory name="transactions-optional">
<property name="datanucleus.appengine.datastoreReadConsistency" value="STRONG" />
    <property name="javax.jdo.PersistenceManagerFactoryClass"
        value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
    <property name="javax.jdo.option.ConnectionURL" value="appengine"/>
    <property name="javax.jdo.option.NontransactionalRead" value="true"/>
    <property name="javax.jdo.option.NontransactionalWrite" value="true"/>
    <property name="javax.jdo.option.RetainValues" value="true"/>
    <property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
</persistence-manager-factory>

I must be missing something central here because all approaches fail...

EDIT2: When I split the job into two transaction the log says that the write transaction fished and then the read transaction starts. But it doesn't find the just persited object. It always says Level 1 Cache of type "weak" initialised aswell. Is week bad or good?

It about 30% of requests that go wrong... Might I be some lazy query loading issue?


Solution

  • Franz, the Default read consistency in the JDO Config is STRONG. so if you are trying to approach it in that direction, it wont lead you anywhere

    Check this out as i think it mentions something similar to the scenario which you are encountering, with the committed data not returned back in the query. It isnt concurrent as mentioned, but it explains the commit process.

    http://code.google.com/appengine/articles/transaction_isolation.html

    Also, another approach would be to query using Extents and find out if that solves the particular use case you are looking at, since i believe you are pulling out all the records in the table.

    EDIT :

    Since in the code snippet that you have mentioned, it queries the entire table. And if that is what you need, you can use an Extent... The way to use it is by calling

    Extent ext = getExtent(<Entity Class name>)

    on the persistenceManager singleton object. You can then iterate through the Extent

    Check out the documentation and search for Extents on the page here. http://code.google.com/appengine/docs/java/datastore/jdo/queries.html