Data reload from persistent disk store is not working after restart - ehcache 3 -spring boot 1.5.6

1,696 views
Skip to first unread message

mahmoud romeh

unread,
Aug 11, 2017, 10:49:16 AM8/11/17
to ehcache-users
Dears ,
I am facing an issue with ehcache 3 disk persistance reload after restart when i am using it with spring boot app :

the xml configuration :
  • attachement : ehcache.xml
the spring boot configuration :
  • attachmnet : CachingConfiguration.java
sprint boot app main enable caching annotation
  • attachmnet : AlertManagerApplication

after I add in the runtime some data objects then restart the app from IDEA , when i query for those data , it is empty all the time i try that , why the cache is cleared upoan restart ? what i am doing wrong ?

ehCache version : 
3.3.1 
Spring boot version : spring boot 1.5.6
ehcache.xml
AlertManagerApplication.java
CachingConfiguration.java

Anthony Dahanne

unread,
Aug 11, 2017, 11:37:06 AM8/11/17
to ehcache-users
Hello,
it looks like you have never configured the disk tier, I can only see onheap and offheap tiers configuration in your xml.
You need to configure a diskTier to have persistent caches (that said, they'll only be persistent as long as your JVM does not crash)
Like this for example :


<resources>
<heap unit="entries">1000</heap>
<disk unit="MB" persistent="true">10</disk>
</resources> 

HTH,
Anthony

Anthony Dahanne

unread,
Aug 11, 2017, 12:29:11 PM8/11/17
to ehcache-users
ah, you'll also need to configure the persistence :

<persistence directory="cachingPersistence"/>

mahmoud romeh

unread,
Aug 14, 2017, 11:44:31 AM8/14/17
to ehcache-users
Dear Anthony,

Thanks for your response ,actually it was wrong file i have uploaded for the ehcache xml , here is the correct one which already contain all the remarks you have mentioned but still same issue no data load after restart .

I do not know what else i could have done wrong.

Thx a lot
ehcache.xml

Anthony Dahanne

unread,
Aug 14, 2017, 11:56:50 AM8/14/17
to ehcache-users
Hello Mahmoud,
Have you located the cache folder ? Does it remain empty ? When you restart your JVM, is it still taking some disk space ?
As it is the authoritative tier, it should start growing as soon as you put elements into the caches that are using it.
Anthony

mahmoud romeh

unread,
Aug 16, 2017, 5:44:41 AM8/16/17
to ehcache-users
Hi Anthony ,

yes i see the cache folder is created and the file size is increasing when I add the data but when I restart the app i see the file size is decreased again which tell me the file data is wiped out when the restart happen , i have attached the file size during running and then after the restart , what leads the file data to be cleared upon restart.

Thanks a lot,
Romeh
before.png
after.png

mahmoud romeh

unread,
Aug 16, 2017, 7:23:48 AM8/16/17
to ehcache-users
also in the startup logs i see the following :[2017-08-16 13:18:25]
[main] INFO  org.ehcache.core.EhcacheManager - Cache 'AlertsConfig' created in Eh107InternalCacheManager.
[2017-08-16 13:18:25] [main] DEBUG org.ehcache.core.EhcacheManager - Creating Cache 'Alerts' in Eh107InternalCacheManager.
[2017-08-16 13:18:25] [main] DEBUG o.ehcache.impl.persistence.FileUtils - Reusing C:\Dev\projects\alert-manager\.\cache\file
[2017-08-16 13:18:25] [main] DEBUG o.ehcache.impl.persistence.FileUtils - Reusing C:\Dev\projects\alert-manager\.\cache\file\Alerts_d0efe0b2c75c1c670b3146f5f276e23a667f15ec
[2017-08-16 13:18:25] [main] DEBUG o.e.i.i.s.s.DefaultSerializationProvider - Serializer for <java.lang.Object> : org.ehcache.impl.serialization.PlainJavaSerializer@682af059
[2017-08-16 13:18:25] [main] DEBUG o.e.i.i.s.s.DefaultSerializationProvider - Serializer for <java.lang.Object> : org.ehcache.impl.serialization.PlainJavaSerializer@5f36c8e3
[2017-08-16 13:18:25] [main] DEBUG o.e.i.i.spi.copy.DefaultCopyProvider - Copier for <java.lang.Object> : org.ehcache.impl.copy.IdentityCopier@4da39ca9
[2017-08-16 13:18:25] [main] DEBUG o.e.i.i.spi.copy.DefaultCopyProvider - Copier for <java.lang.Object> : org.ehcache.impl.copy.IdentityCopier@6a9344f5
[2017-08-16 13:18:25] [main] DEBUG o.ehcache.impl.persistence.FileUtils - Reusing C:\Dev\projects\alert-manager\.\cache\file\Alerts_d0efe0b2c75c1c670b3146f5f276e23a667f15ec\offheap-disk-store
[2017-08-16 13:18:25] [main] INFO  o.t.o.p.UpfrontAllocatingPageSource - Allocating 1MB in chunks
[2017-08-16 13:18:25] [pool-2-thread-1] DEBUG o.t.o.p.UpfrontAllocatingPageSource - 1MB chunk allocated
[2017-08-16 13:18:25] [main] DEBUG o.t.o.p.UpfrontAllocatingPageSource - Took 1 ms to create off-heap sto

So he see the cache file , but it is clearing its content out upon start , is it maybe due to an error in cache manager close with spring boot ?

Henri Tremblay

unread,
Aug 16, 2017, 9:25:04 AM8/16/17
to ehcach...@googlegroups.com
Are you doing a clean shutdown? Closing the cache manager before shutdown.

Because, without a clean shutdown the disk is systematically wiped.

Only the enterprise disk persistence provides resiliency over crash.

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-users+unsubscribe@googlegroups.com.
To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/accb85a3-d58d-4298-b65a-d2a072191c43%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

mahmoud romeh

unread,
Aug 16, 2017, 10:28:26 AM8/16/17
to ehcache-users
yes , i am following all exmaples about spring boot like : https://github.com/ehcache/ehcache3-samples/blob/master/fullstack/src/main/java/org/terracotta/demo/config/CacheConfiguration.java

the issue i see the index file created at starting time sometimes , and when i stop the application , delete the cache folder , start again  i do not see the index file being created

What can make the index file not be created during startup ?
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.

Anthony Dahanne

unread,
Aug 16, 2017, 11:14:00 AM8/16/17
to ehcache-users
Mahmoud,
Please have a look and start / restart it ; you'll see previous cache mapping being restored on restart.
HTH
Anthony

mahmoud romeh

unread,
Aug 17, 2017, 4:47:36 AM8/17/17
to ehcache-users
Hi Anthony ,

Thanks a lot for your demo project , I have used the same setup locally and still can not have the index file being created , please be informed i am using spring boot web module as well so maybe for properly closing the cache manager we need to do something uplon web app closing on embeded tomcat , i do not know.

I have created a github project from my local try you to make your life much easier : https://github.com/Romeh/springboot-web-echache3Persistance

thx a lot

Henri Tremblay

unread,
Aug 17, 2017, 8:04:39 AM8/17/17
to ehcach...@googlegroups.com
I just tried your app and it works perfectly.

I have added this in CacheDataLoader:

System.out.println("Already loaded");
for(Cache.Entry<String, AlertConfigEntry> entry : alertsConfig) {
System.
out.println(entry.getKey() + ":" + entry.getValue());
}
If I start the app, the first time, this cache is empty.

If I stop the app (and see the log "org.ehcache.core.EhcacheManager - Close successful"), and relaunch it, the content is still there as expected.


To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-users+unsubscribe@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.

mahmoud romeh

unread,
Aug 21, 2017, 5:30:12 AM8/21/17
to ehcache-users
Thanks Henry for your reply , i will double check my file system permissions then and i will let you know.

thanks a lot,
Romeh
Reply all
Reply to author
Forward
0 new messages