6 Replies Latest reply on Apr 19, 2017 5:39 AM by Surendra Dangol

    Stop querying persistence once the datagrid has been preloaded

    Surendra Dangol Newbie

      My project requires me to preload data from a database on startup and I am able to do so by using "preload=true" attribute on persistence. The database I am querying contains half million entries and so I am not supposed to query more than once per node. After several nodes have been started, I noticed that some nodes query the database for all data. Is there any way I can configure Infinispan to stop querying for all data once it has preloaded the entries?

       

       

      Test config I am using to debug the problem, using a dummy persistence implementation,

       

      <?xml version="1.0" encoding="UTF-8"?>

      <infinispan>

       

        <cache-container default-cache="default" name="cacheContainer" statistics="true">

        <transport cluster="cluster" />

        <distributed-cache-configuration

        name="default-config"

        mode="SYNC"

        statistics="true"

        >

       

        <persistence>

        <store

        fetch-state="false"

        preload="true"

        purge="false"

        read-only="false"

        class="infinispan.persistence.DummyMapPersistence">

        </store>

        </persistence>

       

        </distributed-cache-configuration>

       

        <distributed-cache

        name="default"

        configuration="default-config">

        </distributed-cache>

        </cache-container>

      </infinispan>

       

       

       

      public class DummyMapPersistence<K, V> implements AdvancedLoadWriteStore<K, V> {

       

       

        @Override

        public void init(InitializationContext ctx) {

        log("init");

        }

       

       

        private static void log(String msg) {

        System.out.println("[DumbMapPersistence] " + msg);

        }

       

        @Override

        public MarshalledEntry<K, V> load(Object key) {

        log("load()");

        }

       

        @Override

        public boolean contains(Object key) {

       

        }

       

        @Override

        public void start() {

        }

       

        @Override

        public void stop() {

        }

       

        @Override

        public void write(MarshalledEntry<? extends K, ? extends V> entry) {

        log("write()");

       

        }

       

        @Override

        public boolean delete(Object key) {

       

        }

       

       

        @Override

        public void process(KeyFilter<? super K> filter,

        org.infinispan.persistence.spi.AdvancedCacheLoader.CacheLoaderTask<K, V> task, Executor executor,

        boolean fetchValue, boolean fetchMetadata) {

        log("process()");

      }

       

       

        @Override

        public int size() {

        log("size()");

        return plainDatastore.size();

        }

       

        @Override

        public void clear() {

        log("clear()");

        plainDatastore.clear();

        }

       

       

        @Override

        public void purge(Executor threadPool,

        org.infinispan.persistence.spi.AdvancedCacheWriter.PurgeListener<? super K> listener) {

        log("purge()");

      }

      }

       

      The main:

       

      public class PersistencePreloadTest {

       

        public static void main(String[] args) throws Exception {

       

        DefaultCacheManager cacheManager = new DefaultCacheManager("infinispan.xml");

       

        Cache<String, Object> cache = cacheManager.getCache("default");

       

        System.out.println("-- Datagrid started --");

        System.out.println("-- process() should not appear after this --");

       

        }

      }

       

      After launching serveral nodes with this same configuration, I find that AdvancedLoadWriteStore::process() is called on some of the nodes. Is there any way to get around this ?

       

      Thanks in advance