[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]
Cannot get cluster wide locking with EHCACHE + Terracotta + ReentrantReadWriteLock working  XML
Forum Index -> Ehcache
Author Message
jacodw

neo

Joined: 07/05/2011 05:59:32
Messages: 5
Offline

Hi,

I have been trying to get distributed cluster wide locking to work using EHCACHE + Terracotta and ReentrantReadWriteLock.

As far as I am aware you should be able to do this either via adding the necessary roots to the tc-config.xml or marking the fields you want to cluster with @Root annotations.

I have tried both methods and had zero success. I can't even see terracotta loading the roots in the terracotta client logfile.

My simple example test class which does not work is below:

Code:
 package com.pivetal.qspeeq.rest.input.service;
 
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 
 import org.springframework.stereotype.Component;
 import org.terracotta.modules.annotations.Root;
 
 @Component
 @Path("terracotta")
 public class TerracottaDistributedObjectTest {
 
       @Root
       private Long sleep = 10000L;  
       
       @Root
       private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
       
       @Path("sleep/{sleep}")
       @PUT
       public String setSleep(@PathParam("sleep") Long sleep) {
             readWriteLock.writeLock().lock();
             try {
                   this.sleep = sleep;
                   Thread.sleep(sleep);
                   return getSleep();
             } catch (InterruptedException e) {
                   return "-1";
             } finally {
                   readWriteLock.writeLock().unlock();
             }
       }
       
       @Path("sleep")
       @GET
       public String getSleep() {
             readWriteLock.readLock().lock();
             try {
                   return this.sleep.toString();
             } finally {
                   readWriteLock.readLock().unlock();
             }
       }
 }
 


The versions I am using are (and my management are reluctant to upgrade to latest at the moment):

1. ehcache-core-2.0.0-SNAPSHOT
2. ehcache-terracotta-2.1.0-SNAPSHOT
3. tim-annotations-1.5.0

Any ideas as to what I am missing, why it would not be working, or other ways in which I could accomplish the distributed locking?
ari

seraphim

Joined: 05/24/2006 14:23:21
Messages: 1665
Location: San Francisco, CA
Offline

this doesn't look like the right way to do things at all.

1. Your Ehcache is very old
2. You are setting a RWL as a Root in Terracotta

What do you want to get done? Caching? Or distributed locks. Anyways. You want to do the following:

1. Ehcache + Explicit locks (but are you sure you need them...what's the purpose of the locking?). DO NOT USE IDENTITY MODE. Use Express, please.

2. Toolkit locks.

Either way, I would advise against using RWLs by hand and setting them as roots for sure...and TIM-annotations, while supported, isn't updated very frequently. Seems like you just found a hodge-podge of Terracotta stuff and threw it all in.

Can you try option #1 or #2? Or is there a reason you are going down this path?

--Ari
[WWW]
gluck

qaestor

Joined: 09/15/2009 18:01:23
Messages: 179
Location: Brisbane, Australia
Offline

(Also answered your personal email)

Have you used the ExplicitLocking API? We designed it for just this purpose. See http://ehcache.org/documentation/explicitlocking.html

This does not need any TIMs, just Ehcache and Terracotta. It is built in to the download of Ehcache.
jacodw

neo

Joined: 07/05/2011 05:59:32
Messages: 5
Offline

Thanks Ari and Greg...

Gonna give the explicitlocking a go. Did see it before, but thought the path of least resistance would be TC's support of RRWL using TC-Config.xml or @Root annotations as we are already using RRWL for our synchronisation. Also we may have had other code regions (not using EHCACHE) which we needed to synchronise across the cluster, but that is not an issue right now.
ari

seraphim

Joined: 05/24/2006 14:23:21
Messages: 1665
Location: San Francisco, CA
Offline

path of least resistance might appear to be RRWLs as roots. Very understandable conclusion. But, experience dictates that if you have roots in your tc-config.xml and use the bootjar the app will prove harder to maintain over time (as well as to get performance from).

There is another product called the Terracotta toolkit. If you need locks w/o caching, you can get locks "in the sky" from that.

Hope that helps,

--Ari

[WWW]
jacodw

neo

Joined: 07/05/2011 05:59:32
Messages: 5
Offline

Hi Ari,

Thanks for the hint on TC Toolkit. May well look into it as I have just found a couple of occurrences where I need distributed locking and don't have a cache involved.
jacodw

neo

Joined: 07/05/2011 05:59:32
Messages: 5
Offline

Hi Ari

Have upgraded to ehcache 2.4.2 and am using Terracotta 3.3.0 and TerracottaToolkit 1.0 and I am unsuccessfully playing about with the Terracotta Toolkit.

When using the TerracottaClient() from terracotta-toolkit-1.0-runtime-1.0.0.jar it requires me to have a TC Server running to load the config from. This tightly couples my unit testing to a TC Server and I don't want to do that.

So I found TerracottaToolkit() in terracotta-toolkit-1.0-1.0.0.jar which doesn't require you to specify config location. However, when using this instance I get the following error in my unit tests:

Code:
[AppClassLoader@17943a4] error can't determine implemented interfaces of missing type com.tc.object.bytecode.NotClearable
 when processing declare parents org.terracotta.locking.TerracottaReadWriteLock$DsoLock
 when processing type mungers 
 when weaving 
  [Xlint:cantFindType]



This inability to get any of the various methods of distributed locking working is really starting to get to me.
Could you find it in your heart to post a working example of distributed locking( and possibly the maven dependencies and any other config needed) :)

Thanks in advance.
ari

seraphim

Joined: 05/24/2006 14:23:21
Messages: 1665
Location: San Francisco, CA
Offline

Totally reasonable request. I'll get someone to help you by writing a blog on how to do Toolkit RRWLs perhaps this weekend or early part of next week.

Sorry for the difficulty. Note that you might wanna try everything again on Terracotta 3.5 as that's the latest GA release. Also, don't hand-assemble Ehcache together from Ehcache.org with Terracotta from Terracotta.org. You will get best results grabbing the whole kit as one from Terracotta.org and using the ehcache.jar that aligns to the Terracotta kit you just downloaded (it comes together in the tarball).

Cheers,

--Ari
[WWW]
ilevy

consul

Joined: 04/16/2008 10:26:42
Messages: 357
Offline

@jacodw I'd like to know if you looked at the product docs (http://www.terracotta.org/documentation/product-documentation-1page), specifically section 7.1.2e in the chapter on the Terracotta Toolkit. It's not a long section, but it does have a couple of code examples. Any feedback you have is welcome.

Also, I'm not aware as to how you can run a Terracotta client w/o the server, but if there is a way I'd like to know about it.
gyan10

ophanim

Joined: 06/28/2011 23:15:25
Messages: 701
Offline

Here is a sample code using ToolKit and ClusteredLock:

[code]
package Test;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

import org.terracotta.api.*;
import org.terracotta.cluster.*;
import org.terracotta.locking.*;

public class ReadWriteLock {

/**
* @param args
*/
public static void main(String[] args) {

TerracottaClient client = new TerracottaClient("localhost:9510"); //start client
ClusteringToolkit toolkit = client.getToolkit(); //make the toolkit available to you application

ClusterInfo clusterinfo= toolkit.getClusterInfo();
System.out.println("Cluster Info" + toolkit.getClusterInfo());
ClusteredLock mylock = (ClusteredLock) toolkit.createLock("Mylock", LockType.WRITE); //create alock

mylock.lock();

try{

//Do some Clustered Operation.

}finally{
mylock.unlock();
}
}

}
[/code]

Gyan Awasthi
Terracotta -A Software AG company
gyan10

ophanim

Joined: 06/28/2011 23:15:25
Messages: 701
Offline

If you do not want to use URL hard coded as in given sample code. You can set URL as a system property in Ehcache.xml and get the URL using CacheManager.
You can check the samle Ehcache.xml for more information.

Gyan Awasthi
Terracotta -A Software AG company
karthike

journeyman

Joined: 07/14/2011 03:17:31
Messages: 30
Offline

Hello sir,

first time i am implement EH cache so plese help me chow do i configure then another one request for me how get url value for EH cache implemnt. please help me.

Thanks
gyan10

ophanim

Joined: 06/28/2011 23:15:25
Messages: 701
Offline

To get clear idea about how to configure Ehcache.Please visit documentation given on Terracotta site:
http://www.terracotta.org/documentation/product-documentation-1page

Gyan Awasthi
Terracotta -A Software AG company
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team