1 Reply Latest reply: Mar 6, 2011 2:18 PM by Paul Jackson RSS

Unable to load data from JDBM after restarting cache.

Paul Jackson Newbie

I am new, so I suspect I am doing something stupid, but I can not figure out why I am unable to get data from my JDBM-backed cache after I restart it.  Any suggestions would be greatly appreciated.  Here's the code in its entirety:

 

  public static void main(String[] args)

  {

    CacheFactory<String, Integer> factory = new DefaultCacheFactory<String, Integer>();

    Configuration config = new Configuration();

    config.setClusterName("test");

    Configuration.CacheMode cacheMode = config.getCacheMode();

    config.setCacheMode(Configuration.CacheMode.LOCAL);

    config.setTransactionManagerLookupClass("org.jboss.cache.transaction.GenericTransactionManagerLookup");

    CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();

    config.setCacheLoaderConfig(cacheLoaderConfig);

    JdbmCacheLoaderConfig jdbmCacheLoaderConfig = new JdbmCacheLoaderConfig();

    jdbmCacheLoaderConfig.setLocation(".\\test");

    cacheLoaderConfig.addIndividualCacheLoaderConfig(jdbmCacheLoaderConfig);

    Cache<String, Integer> cache = factory.createCache(config, false);

    cache.create();

    cache.start();

    Node<String, Integer> rootNode;

    rootNode = cache.getRoot();

    rootNode.put("a", 1);

    assert rootNode.get("a").equals(1);

    assert rootNode.getKeys().size() == 1;

    cache.stop();

    cache.start();

    rootNode = cache.getRoot();

    assert rootNode.get("a") != null;  // Assert fails here!

    assert rootNode.get("a").equals(1);

    assert rootNode.getKeys().size() == 1;

    cache.stop();

    cache.destroy();

  }

 

Thanks,

-Paul

  • 1. Unable to load data from JDBM after restarting cache.
    Paul Jackson Newbie

    It seems I am expecting the wrong thing from JBoss cache. It seems like the purpose of a cache loader is to provide additional storage for the in-memory cache, not to persist everything in the cache in real time. As a result, the only data that is written to the cache is that data that could not fit in memory and was evicted. I was able to get my above test to pass by adding a line: cache.evict(Fqn.ROOT, true); before cache.stop() but this does not mean that I can achieve the behavior I am looking for. I would like transactions to be "acid", meaning that they are persisted to disk when a transaction completes. If the only way I can force a write to disk is to evict my node from the cache, then this defeats the purpose of the cache. Am I missing something or do I understand this correctly?

     

    Thanks,

    -Paul