ClusteredTimestampsRegionImpl keeps a localCache that's not updated right after calling its put method. Calling the get just after the put will not return the value that was just added to the region. I understand that the value will not be available for other nodes of the cluster, but I was expecting that the value would be available, at least, to the cluster node that executed the put method. Is this by design?
region.put("some_key", 1L);
Long actual = (Long) region.get("some_key");
The affected scenario: I have 2 cluster nodes, but I'm accessing only 1 of them. For the same transaction and "hibernate session", if I do the following:
- Execute a query for entity A (that will be cached locally local-query)
- Persist a new instance of entity A
- Flush the entity manager/session
- Execute the very same query again
- Then I'll get old results. The persisted entity A is not returned, but it should be returned.
If I add a sleep of 100ms after the flush, the query will return the correct results. While debugging I realized that ClusteredTimestampsRegionImpl doesn't update its local cache right away during put and only after nodeModified is called, the local cache is updated. All these operations are executed in just one cluster node. The infinispan configuration:
<local-cache name="entity">
<transaction mode="NON_XA" auto-commit="false" complete-timeout="600000" transaction-manager-lookup="com.our.custom.TransactionManagerLookup"/>
<eviction strategy="NONE"/>
</local-cache>
<local-cache name="local-query">
<transaction mode="NONE"/>
<eviction strategy="NONE"/>
</local-cache>
<local-cache name="timestamps">
<transaction mode="NONE"/>
<eviction strategy="NONE"/>
</local-cache>
The pseudo code for the test case:
@Test
public void localQueryShouldBeInvalidatedAfterFlush() {
Query query = entityManager.createQuery("select e from MyEntity e");
query.setHint(QueryHints.HINT_CACHEABLE, Boolean.TRUE);
List firstResults = query.getResultList();
MyEntity newEntity = new MyEntity();
newEntity.setName("abc");
entityManager.persist(newEntity);
entityManager.flush();
List finalResults = query.getResultList();
assertEquals(firstResults.size() + 1, finalResults.size());
}
|