9 Replies Latest reply: Feb 25, 2008 8:52 AM by Mircea Markus RSS

Manual eviction not working

Damien Newbie

Hi all,

I'm trying to evict manualy all nodes from memory cache to cache loader (mysql datastore).
I'm doing this as I want to keep data from cache even if I shutdown JBoss server, so I want to store physicaly datas , and when I start Jboss another time, it will bring up all datas from cacheloader.

This is the code :

public void backupAllCache() {
 this.log.info("launching backup cache");
 Fqn fqn = Fqn.fromString("/root/");
 try {
 Node root = this.cache.get(new Fqn(fqn, "smu"));
 Map childs = root.getChildren();
 Set keys = childs.keySet();
 for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
 Object object = (Object) iterator.next();
 String k = (String)object;
 Node child = (Node)childs.get(k);
 this.cache.evict(child.getFqn());
 }
 } catch (CacheException e) {
 e.printStackTrace();
 }
 catch (Exception e) {
 e.printStackTrace();
 }
 }


The nodes are deleted from memory but doesn't go to cache loader.

Here is my config cache :
<?xml version="1.0" encoding="UTF-8" ?>
<server>
 <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar" />
 <mbean code="org.jboss.cache.aop.PojoCache" name="jboss.cache:service=PojoCache">
 <depends>jboss:service=Naming</depends>
 <depends>jboss:service=TransactionManager</depends>
 <depends>jboss.jca:service=DataSourceBinding,name=my-ds</depends>

 <attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute>
 <attribute name="NodeLockingScheme">PESSIMISTIC</attribute>
 <attribute name="IsolationLevel">REPEATABLE_READ</attribute>

 <attribute name="CacheMode">LOCAL</attribute>

 <attribute name="LockAcquisitionTimeout">15000</attribute>
<attribute name="EvictionPolicyClass">org.jboss.cache.aop.eviction.AopLRUPolicy</attribute>
 <attribute name="EvictionPolicyConfig">
 <config>
 <attribute name="wakeUpIntervalSeconds">2</attribute>
 <!-- Cache wide default -->
 <region name="/_default_">
 <attribute name="maxNodes">100000</attribute>
 <attribute name="timeToLiveSeconds">0</attribute>
 </region>
 <region name="/root/smu">
 <attribute name="maxNodes">100000</attribute>
 <attribute name="timeToLiveSeconds">0</attribute>
 </region>
 </config>
 </attribute>
 <attribute name="CacheLoaderConfiguration">
 <config>
 <passivation>true</passivation>
 <shared>false</shared>
 <preload></preload>
 <cacheloader>
 <class>org.jboss.cache.loader.JDBCCacheLoader</class>
 <properties>
 cache.jdbc.datasource=java:/my-ds
 cache.jdbc.table.drop=false
 </properties>
 <async>false</async>
 <fetchPersistentState>true</fetchPersistentState>
 <ignoreModifications>false</ignoreModifications>
 </cacheloader>
 </config>
 </attribute>
 </mbean>
</server>


So, to conclude, if anybody knows why this manual evicting is not working ??

Otherelse, If somebody knows also a simpliest way to evict automaticly all nodes from memory to cacheloader when Jboss shutdown ????
Thanks all!


ps : I use Jboss 4.05GA and JbossCache 1.4.1 SP3.

  • 1. Re: Manual eviction not working
    Damien Newbie

    I see this in JbossCache docs :

    When the eviction policy in effect calls evict() to evict a node from the cache, if passivation is enabled, a notification that the node is being passivated will be emitted to the tree cache listeners and the node and its children will be stored in the cache loader store


    It means that if passivation is true, a call to evict() will call another method in order to store node into cache loader store.
    What is the method to call, and How I do this ?

  • 2. Re: Manual eviction not working
    Mircea Markus Master

    I've run the following test on 1.4.1SP3, works fine:

    public void testIssues() throws Exception
     {
     TreeCache cache = new TreeCache();
     PropertyConfigurator conf = new PropertyConfigurator();
     conf.configure(cache, "..\\passivation-issues.xml");
     cache.startService();
     cache.put("/za_node", "key","value");
     cache.put("/za_node2", "key","value");
     cache.put("/za_node3", "key","value");
     cache.put("/za_node4", "key","value");
     cache.evict(Fqn.ROOT);
     assertEquals(0, cache.getNumberOfNodes());
     cache.stop();
    
     TreeCache cache2 = new TreeCache();
     PropertyConfigurator conf2 = new PropertyConfigurator();
     conf2.configure(cache2, "..\\passivation-issues.xml");
     cache2.startService();
     cache2.get("/za_node", "key");
     cache2.get("/za_node2", "key");
     cache2.get("/za_node3", "key");
     cache2.get("/za_node4", "key");
     assertEquals(4, cache2.getNumberOfNodes());
     cache2.stopService();
     }

    I've used same config as one you posted.

    Some comments on your code, though:
    Fqn fqn = Fqn.fromString("/root/");

    1. This will fetch you a node named 'root' (i.e. a child of root node), and not the root node which is '/'. Was this your intention?
    2. You can evict all existing nodes this way: cache.evict(Fqn.ROOT);

    If code was your issues hope this helps. Otherwise, Can you please create a UT (or change the one I've attached) to reproduce the issue, then a JIRA and attach code+config to it.

  • 3. Re: Manual eviction not working
    Damien Newbie

     

    "mircea.markus" wrote:
    I've run the following test on 1.4.1SP3, works fine:
    public void testIssues() throws Exception
     {
     TreeCache cache = new TreeCache();
     PropertyConfigurator conf = new PropertyConfigurator();
     conf.configure(cache, "..\\passivation-issues.xml");
     cache.startService();
     cache.put("/za_node", "key","value");
     cache.put("/za_node2", "key","value");
     cache.put("/za_node3", "key","value");
     cache.put("/za_node4", "key","value");
     cache.evict(Fqn.ROOT);
     assertEquals(0, cache.getNumberOfNodes());
     cache.stop();
    
     TreeCache cache2 = new TreeCache();
     PropertyConfigurator conf2 = new PropertyConfigurator();
     conf2.configure(cache2, "..\\passivation-issues.xml");
     cache2.startService();
     cache2.get("/za_node", "key");
     cache2.get("/za_node2", "key");
     cache2.get("/za_node3", "key");
     cache2.get("/za_node4", "key");
     assertEquals(4, cache2.getNumberOfNodes());
     cache2.stopService();
     }

    I've used same config as one you posted.

    Some comments on your code, though:
    Fqn fqn = Fqn.fromString("/root/");

    1. This will fetch you a node named 'root' (i.e. a child of root node), and not the root node which is '/'. Was this your intention?
    2. You can evict all existing nodes this way: cache.evict(Fqn.ROOT);

    If code was your issues hope this helps. Otherwise, Can you please create a UT (or change the one I've attached) to reproduce the issue, then a JIRA and attach code+config to it.


    Well , actually, I need to evict all nodes from memory and put them into datastore. Your example is interesting, but it is based on TreeCache, not PojoCache. Perhaps it have an issue with this version (1.4.1 SP3)

    Which datastore do u use ? a file with FileCacheLoader ?

  • 4. Re: Manual eviction not working
    Damien Newbie

    Well, I've try your code + two objects (Integer) :

    this.cache.put("/za_node", "key", "value");
     this.cache.put("/za_node2", "key", "value");
     this.cache.put("/za_node3", "key", "value");
     this.cache.put("/za_node4", "key", "value");
     this.cache.putObject("/za_node5", new Integer(56));
     this.cache.putObject("/za_node6", new Integer(60));


    If I call the evict method, all nodes have disappearead from memory to database , expect the last two objects (node5 and node6)
    It seems it only appeared with POJO (putObject).


    Can you try another time , but with a PojoCache, not a treeCache, as I use it ?

  • 5. Re: Manual eviction not working
    Damien Newbie

    up!

  • 6. Re: Manual eviction not working
    Damien Newbie

    nobody ??

  • 7. Re: Manual eviction not working
    Mircea Markus Master

    sorry for the late answer.
    this is a bug, and http://jira.jboss.com/jira/browse/JBCACHE-1293 was created for this. No workaround I am afraid.

  • 8. Re: Manual eviction not working
    Damien Newbie

    Well, does it work in version 2.xx and could I install 2.xx version with Jboss 4.0.5 GA ?

    Thanks for ur response.

  • 9. Re: Manual eviction not working
    Mircea Markus Master

    yes, it should work on pojo 2.x. (Pojo 2.x does not extend tree cache anymore, so you'll have to obtain the cache and evict manually: pojo.getCache().evict())
    Re: deploying Pojo 2x in AS4.x, it is still something we are looking to, check http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4131091#4131091