2 Replies Latest reply on Nov 21, 2006 5:12 AM by sjeevan

    How to, Flush data stored in TreeCache to disk?

    sjeevan

      Hi,

      I am using JE BerkleyDB implementation of JBossTreeCache (org.jboss.cache.TreeCache) in my application for storing some information.

      A sniipet out of the constructor:

      public final Fqn CREATED_DATE_FQN;
      private static final String CREATED_DATE = "CreatedDate";
      ....
      
      this.cache = new TreeCache();
      cache.setClusterName(name);
      cache.setCacheMode("local");
      cache.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("",
       BdbjeCacheLoader.class.getName(), "location="
       + f.getAbsolutePath(), false, true, false));
      cache.startService();
      cache.put(CREATED_DATE_FQN, CREATED_DATE, new Timestamp(new Date().getTime()));
      cache.load(name);//Load existing data if any
      ...
      cache.startService(); /// required before the cache can be used!
      ...
      
      


      To store data I use:

      cache.put(MAX_ID_FQN, MAX_ID, eventId);
      


      But what I have observed is that the cache is not flushed to disk.
      I have discovered a workaround (but unacceptable for production) is, after every put;

      cache.put(MAX_ID_FQN, MAX_ID, eventId);
      // stopService & startSerivice of cache, to flush the data just added to disk
      cache.stopService();
      cache.startService();
      


      I tried commit() after the put
      cache.put(MAX_ID_FQN, MAX_ID, eventId);
      cache.commit(cache.getCurrentTransaction(true)); //commit to disk, but this throws an exception
      


      but that throws a
      java.lang.UnsupportedOperationException::commit() should not be called on TreeCache directly.

      Any clues will be appreciated.

      ~g1
      PS: To build I use maven with jboss-cache-1.4.0.SP1.jar, jboss-system-4.0.3.jar, jboss-jmx-4.0.3.jar & jboss-common-4.0.3.jar


        • 1. Re: How to, Flush data stored in TreeCache to disk?
          manik

          The code you have above, the getSingleCacheLoaderConfig() method generates a block of XML corresponding to a cache loader config (see the chapter on cache loaders in the docs).

          Make sure you generate XML that sets __async__ to false. If async is true, flushes will not happen in realtime and will be deferred to a queue and processed by a separate thread. Perhaps you could check the XML that getSingleCacheLoaderConfig() generates?

          • 2. Re: How to, Flush data stored in TreeCache to disk?
            sjeevan

            Manik,

            Thank you.
            My problem has been resolved but in a different way.

            I checked the code you pointed out and the xml used to configure the CacheLoader is as

            #DEBUG 15:35:02 [recovery.LedgerImpl] (main) Cache loader
             configuration XML=
             <config>
             <passivation>false</passivation>
             <preload></preload>
             <cacheloader>
             <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>
             <properties>location=C:\DOCUME~1\124872\LOCALS~1\Temp\dev\Ledgers\INTTEST2</properties>
             <async>false</async>
             <shared>false</shared>
             <fetchPersistentState>true</fetchPersistentState>
             <purgeOnStartup>false</purgeOnStartup>
             </cacheloader>
             </config>
            


            As pointed out the value of __async__ is false, but that did not help in acheiving flush to disk.

            Anyways I discovered that by setting the TransactionManager of the TreeCache I could achieve flushing to disk.

            this.cache = new TreeCache();
            cache.setClusterName(eventSourceName);
            cache.setCacheMode("local");
            
            //set the Transaction Manager to enable flushing of cache to disk
             cache.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
            
            cache.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("",
             BdbjeCacheLoader.class.getName(), "location="
             + f.getAbsolutePath(), false, true, false));
            
            


            thank u
            ~g1