2017-12-07 1 views
0

Hallo, ich habe einen neuen Eintrag in eine Region eingefügt und eine OQL (SELECT * FROM/some_region_name) beide innerhalb der gleichen Transaktion abgefragt, und ich fand, dass die neue eingefügt Eintrag wurde im OQL-Ergebnis nicht zurückgegeben. Weiß jemand, was damit vor sich ging?Geode/Gemfire OQLs Rückgabedaten sind falsch in der Transaktionsansicht

Hier sind meine Testcode:

ClientCache cache = (ClientCache) EcnSpringContext.getBean("gemfireCache"); 

    Region<String, RUserEntity> userRegion = (Region<String, RUserEntity>) EcnSpringContext.getBean("r_user"); 

    CacheTransactionManager txmgr = cache.getCacheTransactionManager(); 
    EcnGeodeTemplate ecnGeodeTemplate = (EcnGeodeTemplate) EcnSpringContext.getBean("rUserTemplate"); 

    String username = "forrest"; 
    System.out.println("Transaction begin."); 
    txmgr.begin(); 

    System.out.println("checking username[" + username + "] before added."); 
    RUserEntity found = (RUserEntity) userRegion.selectValue("SELECT * FROM /r_user WHERE username = '" + username + "'"); 
    if (found == null) 
     System.out.println("rUserEntity NOT found"); 
    else 
     System.out.println("rUserEntity found"); 


    RUserEntity rUserEntity = new RUserEntity(); 
    rUserEntity.setUsername("forrest"); 
    rUserEntity.setId(username); 
    userRegion.put(username, rUserEntity); 

    System.out.println("checking username[" + username + "] after added."); 
    found = (RUserEntity) userRegion.selectValue("SELECT * FROM /r_user WHERE username = '" + username + "'"); 
    if (found == null) 
     System.out.println("rUserEntity NOT found"); 
    else 
     System.out.println("rUserEntity found"); 


    txmgr.commit(); 
    System.out.println("Transaction end."); 

    System.out.println("checking username[" + username + "] after transaction."); 
    found = (RUserEntity) userRegion.selectValue("SELECT * FROM /r_user WHERE username = '" + username + "'"); 
    if (found == null) 
     System.out.println("rUserEntity NOT found"); 
    else 
     System.out.println("rUserEntity found"); 

ich das Ergebnis erwartet:

Transaction begin. 
checking username[forrest] before added. 
rUserEntity NOT found 
checking username[forrest] after added. 
**rUserEntity found** 
Transaction end. 
checking username[forrest] after transaction. 
rUserEntity found 

Aber leider habe ich dieses Ergebnis:

Transaction begin. 
checking username[forrest] before added. 
rUserEntity NOT found 
checking username[forrest] after added. 
**rUserEntity NOT found** 
Transaction end. 
checking username[forrest] after transaction. 
rUserEntity found 

Antwort

1

Dies ist ein bekannter Einschränkung. From the docs:

Queries and indexes reflect the cache contents and ignore the changes 
made by ongoing transactions. If you do a query from inside a transaction, 
the query does not reflect the changes made inside that transaction.