Транзакции JDO + много экземпляров GAE = переопределяющие данные

У меня есть очень простой класс PersistenceCapable:

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable
public class TheEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
public Long getId() {
    return id;
}
@Persistent
private int version;
public int getVersion() {
    return version;
}
public void setVersion(int version)
{
    this.version=version;
}
}  

И я просто обновляю версию, увеличивая ее (и я добавил несколько вычислений, чтобы иногда вызывать разогрев GAE)

public void test2(){
    PersistenceManager mgr = getPersistenceManager();
    mgr.currentTransaction().begin();
    TheEntity test = mgr.getObjectById(TheEntity.class, 5081359164899328L);
    test.setVersion(test.getVersion()+1);
    log.log(Level.SEVERE, "VERSION: " + test.getVersion());
        for (int i = 0; i < 10000; i++)
        {
            long x = i*i;
            x++;
        }
    mgr.currentTransaction().commit();
    mgr.close();}

Итак, я набрал код 9 раз, он никогда не подводил. Журналы ниже:

W1. I 02:28:21.331 2015-01-10  200       0 B  6839ms /_ah/warmup
1. I 02:28:38.407 2015-01-10  204       0 B  4343ms /_ah/spi/com.vaktu.MyEndpoint.test1
   188.122.13.128 - - [09/Jan/2015:17:28:38 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=4343 cpu_ms=2940 cpm_usd=0.000022 instance=00c61b117c4063829b2bf7ef35e1e6e8a0e41978 app_engine_release=1.9.17
   I 02:28:38.012 com.vaktu.MyEndpoint test2: VERSION: 1
2. I 02:28:42.493 2015-01-10  204       0 B   115ms /_ah/spi/com.vaktu.MyEndpoint.test1
   188.122.13.128 - - [09/Jan/2015:17:28:42 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=115 cpu_ms=70 instance=00c61b117c4063829b2bf7ef35e1e6e8a0e41978 app_engine_release=1.9.17
   I 02:28:42.444 com.vaktu.MyEndpoint test2: VERSION: 2
W2. I 02:28:42.495 2015-01-10  200       0 B  7061ms /_ah/warmup
3. I 02:28:54.196 2015-01-10  204       0 B  4647ms /_ah/spi/com.vaktu.MyEndpoint.test1
   188.122.13.128 - - [09/Jan/2015:17:28:54 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=4647 cpu_ms=3173 cpm_usd=0.000022 instance=00c61b117c31a94949f82af423e0f1a3c1ac35 app_engine_release=1.9.17
   I 02:28:53.814 com.vaktu.MyEndpoint test2: VERSION: 3
4. I 02:28:59.126 2015-01-10  204       0 B   163ms /_ah/spi/com.vaktu.MyEndpoint.test1
   188.122.13.128 - - [09/Jan/2015:17:28:59 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=163 cpu_ms=70 instance=00c61b117c31a94949f82af423e0f1a3c1ac35 app_engine_release=1.9.17
   I 02:28:59.036 com.vaktu.MyEndpoint test2: VERSION: 4
5. I 02:29:02.426 2015-01-10  204       0 B   119ms /_ah/spi/com.vaktu.MyEndpoint.test1
  188.122.13.128 - - [09/Jan/2015:17:29:02 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=119 cpu_ms=117 instance=00c61b117c31a94949f82af423e0f1a3c1ac35 app_engine_release=1.9.17
   I 02:29:02.373 com.vaktu.MyEndpoint test2: VERSION: 5
6. I 02:29:06.947 2015-01-10  204       0 B   114ms /_ah/spi/com.vaktu.MyEndpoint.test1
  188.122.13.128 - - [09/Jan/2015:17:29:06 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=114 cpu_ms=70 instance=00c61b117c31a94949f82af423e0f1a3c1ac35 app_engine_release=1.9.17
   I 02:29:06.896 com.vaktu.MyEndpoint test2: VERSION: 6
7. I 02:29:11.705 2015-01-10  204       0 B   101ms /_ah/spi/com.vaktu.MyEndpoint.test1
   188.122.13.128 - - [09/Jan/2015:17:29:11 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=101 cpu_ms=47 instance=00c61b117c31a94949f82af423e0f1a3c1ac35 app_engine_release=1.9.17
   I 02:29:11.665 com.vaktu.MyEndpoint test2: VERSION: 7
8. I 02:29:30.133 2015-01-10  204       0 B   111ms /_ah/spi/com.vaktu.MyEndpoint.test1
  188.122.13.128 - - [09/Jan/2015:17:29:30 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=111 cpu_ms=117 instance=00c61b117c4063829b2bf7ef35e1e6e8a0e41978 app_engine_release=1.9.17
   I 02:29:30.085 com.vaktu.MyEndpoint test2: VERSION: 3
9. I 02:29:33.598 2015-01-10  204       0 B   158ms /_ah/spi/com.vaktu.MyEndpoint.test1
  188.122.13.128 - - [09/Jan/2015:17:29:33 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=158 cpu_ms=93 instance=00c61b117c4063829b2bf7ef35e1e6e8a0e41978 app_engine_release=1.9.17
   I 02:29:33.509 com.vaktu.MyEndpoint test2: VERSION: 4

test1 просто вызывает test2, а код test2 находится выше. W1 = прогрев экземпляра 1 W2 = прогрев экземпляра 2 Запросы выполняются в экземпляре 1: 1, 2, 8, 9 Запросы выполняются в экземпляре 2: 3, 4, 5, 6, 7 Теперь, после 9 обновлений, которые должны увеличить версию до 9, у меня есть версия = 4 в моей базе данных. Серьезно, это катастрофа для меня. Любая помощь очень ценится. Если кто-то внедрил JPA и может проверить, работает ли он лучше, пожалуйста, оставьте отзыв.

Мой jdoconfig.xml:

   <property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
   <property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>
   <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"/>
   <property name="datanucleus.appengine.singletonPMFForName" value="true"/>

Мой файл persistence.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence         http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="transactions-optional">
    <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
    <properties>
        <property name="datanucleus.NontransactionalRead" value="true"/>
        <property name="datanucleus.NontransactionalWrite" value="true"/>
        <property name="datanucleus.ConnectionURL" value="appengine"/>
    </properties>
</persistence-unit>
</persistence>

JARS в WEB-INF/lib:

appengine-api-1.0-sdk-1.9.17.jar
appengine-api-labs.jar
appengine-api.jar
appengine-endpoints-deps.jar
appengine-endpoints.jar
appengine-jsr107cache-1.9.17.jar
asm-4.0.jar
datanucleus-api-jdo-3.1.3.jar
datanucleus-api-jpa-3.1.3.jar
datanucleus-appengine-2.1.2.jar
datanucleus-cache-3.1.3.jar //I want to use memcache after I finally make it work without it
datanucleus-core-3.1.3.jar
gcm-server.jar
geronimo-jpa_2.0_spec-1.0.jar
jdo-api-3.0.1.jar
json_simple-1.1.jar
jsr107cache-1.1.jar
jta-1.1.jar

Я буду очень, очень благодарен за помощь...

0 ответов

Другие вопросы по тегам