[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Data concurrency  XML
Forum Index -> Ehcache
Author Message
siddhart

neo

Joined: 09/07/2010 00:34:45
Messages: 6
Offline

I have started to explore EHCache, Now While I testing data concurrency , Have some doubts

Parallel transaction updates record, which is not desirable behavoiour for my application, need to fail subsequent transaction on same records
Here I am reading Same record from two different session objects

Time Read Write

1 Tx1 (Read database Record,will fetch from database)

2 Tx2 (Read same database record, will be served from 2LC (EHCache), New instance object as different session is used)

3 Tx1 (Database update successful)

4 Tx2 (Again database update successful , This should not happen in case of repeatable read as before writing transaction must have track the fetch version and intermediate commit has been done on time 3 is done, so one this event exception must arise)

Cache is transaction configured, I think repeatable read should work over here and next update should get failed as data already updated

Is there any configuration missed ?
alexsnaps

consul

Joined: 06/19/2009 09:06:00
Messages: 484
Offline

I'm not sure I follow everything, but R_R isn't supported. Only R_C is.
Now you are using ehcache with Hibernate right ? You did configure everything properly ?
Also I'm confused about you expecting the cache to throw an exception while the database isn't... Do you want to run the two in different isolation ?

Alex Snaps (Terracotta engineer)
siddhart

neo

Joined: 09/07/2010 00:34:45
Messages: 6
Offline

No, I am not using two different isolation levels

Let me share configuration

Code

session = sessionFactory.openSession();
Transaction t = session.beginTransaction();
Contact con = (Contact)session.load(Contact.class, new Long(4));
System.out.println("Session last name : "+con.getLastName());
con.setLastName(request.getParameter("a"));

session1 = sessionFactory.openSession();
Transaction t1 = session1.beginTransaction();
Contact con1 = (Contact)session1.load(Contact.class, new Long(4));
System.out.println("Session1 last name : "+con1.getLastName());
con1.setLastName(request.getParameter("b"));

if(con == con1){
System.out.println("objects are same");
}else{
System.out.println("objects are different");
}

session.save(con);
t.commit();

try{
Thread.sleep(1000);
}catch (InterruptedException e) {
}
session1.save(con1);
t1.commit();



Hibernate Conf

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://host:port/corporate</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">passwd</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">100</property>

<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory</property>

<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="contact.hbm.xml" />
</session-factory>
</hibernate-configuration>


contact.hbm.xml - OR Mapping

<hibernate-mapping>
<class name="bean.Contact" table="CONTACT" lazy="true" >
<cache usage="read-write" />
<id name="id" type="long" column="ID" >
<generator class="sequence" >
<param name="sequence">contact_id</param>
</generator>
</id>
<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName" lazy="true">
<column name="LASTNAME"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>

and Default EHCache Configuration

Please let me know if any configuration is missed
Any locking related configuration in hibernate / EHCache configuration file ?

I want to prevent write of next parallel, operation MVCC is needed
alexsnaps

consul

Joined: 06/19/2009 09:06:00
Messages: 484
Offline

I'm really confused now. Are you trying to use a Transactional cache here ?
Cause there are a couple of things wrong in that case:
1. Cache strategy isn't Transactional
2. Are you using a proper configured XA TransactionManager?
3. Is the cache region configured as transactional in your ehcache.xml ?!

I think I'm slightly confused about what you are exactly trying to achieve here. Maybe I got it all wrong to begin with... Anyways currently, with the read-write cache strategy, on write (and flush iirc), Hibernate would replace the cache entry with a SoftLock. Upon hit, another transaction would then fall back to reading data from the database... Which, in case of PostgreSQL, is R_C iirc again.
Or is versioning at Hibernate's level what you are looking for ? Sorry I'm confused!

Alex Snaps (Terracotta engineer)
siddhart

neo

Joined: 09/07/2010 00:34:45
Messages: 6
Offline

Hi Alex

Thanks for reply
Yes, I need transactional cache and further needs to deploy in cluster based environment (Active - Active mode)

Have started with standalone deployment

echcahe.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true" monitoring="autodetect" dynamicConfig="true">

<diskStore path="java.io.tmpdir"/>

<transactionManagerLookup class="net.sf.ehcache.transaction.manager.DefaultTransactionManagerLookup"
properties="jndiName=java:/PostgresDS" propertySeparator=";" />

<cacheManagerEventListenerFactory class="" properties=""/>

<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskSpoolBufferSizeMB="5"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
statistics="false"
transactionalMode="xa"
/>
<terracotta clustered="flase"/>
</ehcache>

Have created datasource PostgresDS as well need to supply database connectivity properties in hibernate

So will single JNDI based lookup (XA Transaction) will be serve hibernate & EHCache then how to do it ?

and need to test concurrency in standalone mode first so what's misconfiguration is here

any guide reference for configuring in distributed mode

Thanks,
Siddharth


alexsnaps

consul

Joined: 06/19/2009 09:06:00
Messages: 484
Offline

What's at java:/PostgresDS ? The datasource or the TransactionManager ? I'd expect the former, given the name.
Now, you need to configure Hibernate to use the proper TransactionManager and to use Transactional caches...
I think your setup isn't entirely correct yet. Also please keep in mind that Ehcache doesn't have support for R_R.

Alex Snaps (Terracotta engineer)
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team