Hello all,

I have test program to help me better understand the design behavior of
expired entry in cache with persistent store. I have write behind/read
through enabled and created listener for expire event. The log below shows
that if I use a get operation after an entry is expired,  the entry will be
loaded from database, and return the cache value. 

[16:20:36] Topology snapshot [ver=1, servers=1, clients=0, CPUs=4,
heap=0.5GB]
Try get entry before sleep
[Sample Mode]col1:10; col2: 10String value of     ; col3: 10String value of    
String value of     ; 
[1495754442269]-----------Datebase BATCH upsert:1 entries successful
----------------
Received event [evt=CACHE_OBJECT_EXPIRED, key=10|10String value of     |,
oldVal=com.sample.model.SampleModel [idHash=2074419914, hash=1504083002,
col2=10String value of     , col3=10String value of     String value of    
, col1=10], newVal=null
Try get entry after 2 minute sleep
*entry with key =10|10String value of     | loaded from database*
[Sample Mode]col1:10; col2: 10String value of     ; col3: 10String value of    
String value of     ; 
[16:22:41] Ignite node stopped OK [uptime=00:02:04:396]

when I disable write through/behind and leave read through true, ignite
still tries to load data from database.

Try get entry before sleep
[Sample Mode]col1:10; col2: 10String value of     ; col3: 10String value of    
String value of     ; 
[18:08:29] New version is available at ignite.apache.org: 2.0.0
Received event [evt=CACHE_OBJECT_EXPIRED, key=10|10String value of     |,
oldVal=com.sample.model.SampleModel [idHash=532656278, hash=449338124,
col2=10String value of     , col3=10String value of     String value of    
, col1=10], newVal=null
Try get entry after 2 minute sleep
*entry with key =10|10String value of     | loaded from database
null*
[18:10:24] Ignite node stopped OK [uptime=00:02:04:613]

When I disable write through/behind and read through, no cache.load is
executed.

Try get entry before sleep
[Sample Mode]col1:10; col2: 10String value of     ; col3: 10String value of    
String value of     ; 
[18:13:04] New version is available at ignite.apache.org: 2.0.0
Received event [evt=CACHE_OBJECT_EXPIRED, key=10|10String value of     |,
oldVal=com.sample.model.SampleModel [idHash=1018189201, hash=449338124,
col2=10String value of     , col3=10String value of     String value of    
, col1=10], newVal=null
Try get entry after 2 minute sleep
null

Is it a designed behavior? Appreciate clarification. The example below is
great, but doesn't show how it behave when a persistent store is in picture.

https://github.com/gridgain/gridgain-advanced-examples/blob/master/src/main/java/org/gridgain/examples/datagrid/eviction/CacheTtlExample.java


The program looks like below:

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

        System.out.println(new Date()+ "IGNITE START
----------------------------");
        Ignite ignite = null;
        try {

            Ignition.setClientMode(false);
            ignite = Ignition.start("config/ignite-writebehind.xml");

            try (IgniteCache<String, SampleModel> cache =
ignite.getOrCreateCache("sampleCache")) {

                //test expiry
                // Local listener that listenes to local events.
                IgnitePredicate<CacheEvent> rmtLsnr = evt -> {
                    System.out.println("Received event [evt=" + evt.name() +
", key=" + evt.key() +
                            ", oldVal=" + evt.oldValue() + ", newVal=" +
evt.newValue());

                    return true; // Continue listening.
                };

                // Subscribe to specified cache events occuring on local
node.
               
ignite.events(ignite.cluster().forCacheNodes("sampleCache")).remoteListen(null,
rmtLsnr,
//                        EventType.EVT_CACHE_OBJECT_PUT,
//                        EventType.EVT_CACHE_OBJECT_READ,
//                        EventType.EVT_CACHE_OBJECT_REMOVED,
                        EventType.EVT_CACHE_OBJECT_EXPIRED);

                testTouchdExpiry(cache);
            }
        } finally {
            if (ignite != null) {
                ignite.close();
            }
        }

    }

    private static void testTouchdExpiry(IgniteCache<String, SampleModel>
cache) {
        //create
        SampleModel entry = new SampleModel( Long.valueOf(10),
                String.valueOf(10) + "String value of     ",
                String.valueOf(10) + "String value of     String value of    
" );
        cache.put(entry.getKeyString(), entry);
        System.out.println("Try get entry before sleep");
        System.out.println(cache.get(entry.getKeyString()));


        //exire?
        try {
            TimeUnit.MINUTES.sleep(2);
        }catch (InterruptedException e) {

        }
        System.out.println("Try get entry after 2 minute sleep");
        System.out.println(cache.get(entry.getKeyString()));

    }
  
configuration file

         <property name="cacheConfiguration">

            <list>
            <bean
class="org.apache.ignite.configuration.CacheConfiguration">
                <property name="name" value="sampleCache"/>
                
                <property name="readThrough" value="false"/>
                <property name="writeThrough" value="false"/>
                <property name="writeBehindEnabled" value="false"/>
                <property name="writeBehindFlushFrequency" value="5000" />
                <property name="writeBehindFlushSize" value="1000"/>
                <property name="writeBehindFlushThreadCount" value="10"/>
                <property name="writeBehindBatchSize" value="100"/>
                <property name="expiryPolicyFactory" >
                    <bean id ="expiryPolicy" class
="javax.cache.expiry.CreatedExpiryPolicy"
                          factory-method="factoryOf">
                        <constructor-arg>
                            <bean class="javax.cache.expiry.Duration">
                                <constructor-arg value="MINUTES" />
                                <constructor-arg value="1"/>
                            </bean>
                        </constructor-arg>
                    </bean>
                </property>

                
                <property name="cacheStoreFactory">
                    <bean class="javax.cache.configuration.FactoryBuilder"
factory-method="factoryOf">
                        <constructor-arg
value="com.sample.store.SampleStore" />
                    </bean>
                </property>
               

            </bean>
        </list>
        </property>

        <property name="peerClassLoadingEnabled" value="true"/>

        
        <property name="includeEventTypes">
            <list>
                <util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_EXPIRED"/>
                <util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT" />
            </list>
        </property>

 



--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/Expired-entry-in-cache-with-persistent-store-tp13156.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to