Ho un'applicazione distribuita nel motore di app di Google. Ricevo dati incoerenti quando richiamo un'entità per ID subito dopo l'aggiornamento di tale entità. Sto usando JDO 3.0 per accedere al datastore del motore dell'app.Fetch incoerente dal datastore del Google App Engine
Ho un dipendente un'entità
@PersistenceCapable(detachable = "true")
public class Employee implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8319851654750418424L;
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY, defaultFetchGroup = "true")
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
@Persistent(defaultFetchGroup = "true")
private String name;
@Persistent(defaultFetchGroup = "true")
private String designation;
@Persistent(defaultFetchGroup = "true")
private Date dateOfJoin;
@Persistent(defaultFetchGroup = "true")
private String email;
@Persistent(defaultFetchGroup = "true")
private Integer age;
@Persistent(defaultFetchGroup = "true")
private Double salary;
@Persistent(defaultFetchGroup = "true")
private HashMap<String, String> experience;
@Persistent(defaultFetchGroup = "true")
private List<Address> address;
/**
* Setters and getters, toString() * */
}
Inizialmente, quando creo un dipendente non stabilire il salario campi ed e-mail.
Aggiornare l'entità Dipendente per aggiungere salario e e-mail in seguito. L'aggiornamento funziona correttamente e i dati vengono mantenuti nel datastore appengine. Tuttavia, quando provo immediatamente a recuperare la stessa entità dipendente dall'ID, a volte ottengo i dati non aggiornati, dove lo stipendio e l'email sono nulli. Di seguito viene fornito il codice che uso per creare e recuperare l'entità dipendente.
public Employee create(Employee object) {
Employee persObj = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = null;
try {
tx = pm.currentTransaction();
tx.begin();
persObj = pm.makePersistent(object);
tx.commit();
} finally {
if ((tx != null) && tx.isActive()) {
tx.rollback();
}
pm.close();
}
return persObj;
}
public Employee findById(Serializable id) {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Employee e = pm.getObjectById(Employee.class, id);
System.out.println("INSIDE EMPLOYEE DAO : " + e.toString());
return e;
} finally {
pm.close();
}
}
public void update(Employee object) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = null;
try {
tx = pm.currentTransaction();
tx.begin();
Employee e = pm.getObjectById(object.getClass(), object.getId());
e.setName(object.getName());
e.setDesignation(object.getDesignation());
e.setDateOfJoin(object.getDateOfJoin());
e.setEmail(object.getEmail());
e.setAge(object.getAge());
e.setSalary(object.getSalary());
tx.commit();
} finally {
if (tx != null && tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Ho impostato il numero di istanze inattive su 5 e ci sono circa 8 istanze in esecuzione alla volta. Quando ho controllato i registri di varie istanze questo è quello che ho trovato.
Perché ottengo dati obsoleti quando la richiesta viene servita da determinate istanze. Posso assicurare che, se la richiesta di recupero viene gestita dall'istanza che inizialmente gestiva la richiesta di aggiornamento, ottengo sempre i dati aggiornati. Ma quando altre istanze gestiscono la richiesta di recupero, i dati non aggiornati possono essere restituiti. Ho impostato in modo esplicito la consistenza di lettura del datastore su strong nel mio jdoconfig.xml.
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd">
<persistence-manager-factory name="transactions-optional">
<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"/>
<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
<property name="datanucleus.query.jdoql.allowAll" value="true"/>
<property name="datanucleus.appengine.datastoreReadConsistency" value="STRONG" />
</persistence-manager-factory>
</jdoconfig>
http://stackoverflow.com/search?q=%5Bgae%5D+eventuale+consistenza di coerenza in "consistenza finale" in base all'aspetto. –
@PaulCollingwood Ho impostato la coerenza di lettura del datastore su STRONG. –
HariShankar
http://stackoverflow.com/questions/8112331/google-app-engine-jdo-makepersistent-latency – arundevma