0

In my project i use infinispan to manage my data and improve the performance, so i have a problem is when we stop de server and restart it all my data are deleted ans it's normal beacause its a cache.

so i demand you if you have a sugggestion for me for saving my data of my application even if the server is stopped ?

I searched in the internet , i found a lot of solution like using database with infinispan or store the data into a file like using (filecacheStore, jdbccachestore, casassandraCachedatastore) and i dont know which one is the best solution!

thank you very much in advance for your reply.

user3822342
  • 357
  • 1
  • 2
  • 8

1 Answers1

0

There's a multitude of options and none is best for all use-cases; that's why there are the options. You haven't said much about your app needs.

1) Use persistent cache store (single file store is the simplest option probably). This is and OOTB solution.

2) Before shutdown fetch and persist all data from your app (use streams API to iterate through), and upload them after boot. This does not add any overhead during runtime but requires you to handle the process yourselves.

3) Use cluster of nodes and always keep some nodes with the data up. However, backups (either via 1) or 2)) might be advisable anyway.

Radim Vansa
  • 5,686
  • 2
  • 25
  • 40
  • thank you very much for your reply. but i still have other questions :) If I use the first solution which the storage into a file for saving my data : • When have I to save the data of my cache ? just before the shutdown of the server ? or with a frequency for example I persist into the file each 1mn ? because im a fraid to lost my data when the sever is crashed instead of stopped properly. – user3822342 Dec 05 '18 at 14:18
  • For Second proposition: Ok , I think its easy to do , but when I save my data into a variable , this variable won’t be initialized when the server is stopped ? because the content of my variable will be persisting in the memory. and How can I upload the content ? – user3822342 Dec 05 '18 at 14:18
  • For the third solution : I think it’s a good solution but the incovenient is we should buy a server just for this purpose ! what do you think about Redis for this case ? Thanks again – user3822342 Dec 05 '18 at 14:18
  • When using persistent cache store, it is update on each write (write-through policy) or asynchronously very soon after (write-behind). You don't need to address that yourselves. – Radim Vansa Dec 05 '18 at 16:20
  • 'variables' are in-memory only in most programming languages. The second proposition says that you should load them into your app and store them somewhere (persistently), writing the data to a file or your favourite database. – Radim Vansa Dec 05 '18 at 16:23
  • Hello Vansa, finally i choose your first proposition , but now the file is generated but its binary , its content is not understandable. here is the generated file. FCS1 … ? &ÿÿÿÿÿÿÿÿkey1 Person/AI'ZBM{ name surname >cle1>test1=ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ9ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ – user3822342 Dec 07 '18 at 14:24
  • hello Radim, have you any idea please ? thanks in advance – user3822342 Dec 10 '18 at 09:29
  • It was your code that stored the object retrieved from Infinispan to the binary form - I don't know what exactly you've done. It is the same as if you were storing Java objects to file in any other application. – Radim Vansa Dec 10 '18 at 15:20
  • i just added this configuration i think if i want to have a particular format , i have to write my own store – user3822342 Dec 12 '18 at 09:09
  • My bad; I thought you're persisting yourselves (option 2). Okay, you should set 'purgeOnStartup="false"', and when Infinispan boots you'll see the data back in. Your setting to 'true' means that the cachestore is wiped out at startup. – Radim Vansa Dec 12 '18 at 10:05
  • The format of this store really is binary (using JBoss Marshaller to serialize your objects); do you have any need to access it externally? – Radim Vansa Dec 12 '18 at 10:06
  • okey , thank you .. can you confirme me please that infinispan will be able to load the data of my file automatically in the startup of my application ? because in my project , we are using file JMS and web services and im afraid that the call of this web services or consumption message will passe before the load of data with infinispan.. – user3822342 Dec 12 '18 at 10:41
  • The format of this store really is binary (using JBoss Marshaller to serialize your objects); do you have any need to access it externally? --> Yes we want to access it externally ! – user3822342 Dec 12 '18 at 15:22
  • hello vansa , you told me that i have just to add 'purgeOnstartup=false" for to see the data back in . but in this issue , you said that There is no automated system for data recovery, the link is : https://developer.jboss.org/thread/251420 ! you said that we shoud write my own store if we want to make a recovery. which this the difference between his problem and the mine please ? im confused :( – user3822342 Dec 12 '18 at 18:03
  • hello Vansa , please i have a question , I want to know the way how I can detect the cache rebalance is finished in infinispan ? when we have a cluster composed of nodes in a replication mode. – user3822342 Dec 17 '18 at 15:33
  • [Context=org.infinispan.CONFIG] ISPN100010: Finished rebalance with members [CSPYCHAKIR-29032, CSPYCHAKIR-60692], topology id 7 [Context=local] ISPN100002: Starting rebalance with members [CSPYCHAKIR-29032, CSPYCHAKIR-60692], phase READ_OLD_WRITE_ALL, topology id 3 [Context=local] ISPN100009: Advancing to rebalance phase READ_ALL_WRITE_ALL, topology id 4 [Context=local] ISPN100009: Advancing to rebalance phase READ_NEW_WRITE_ALL, topology id 5 [Context=local] ISPN100010: Finished rebalance with members [CSPYCHAKIR-29032, CSPYCHAKIR-60692], topology id 6 – – user3822342 Dec 17 '18 at 16:00
  • how can i detect that rebalance is finished please ? – user3822342 Dec 17 '18 at 16:00
  • there is listener which can notify me ? – user3822342 Dec 17 '18 at 16:34
  • As for the thread in jboss forums: The use says that the node was shutdown cleanly, but the file is for some reason corrupt. There's no tool (I would be aware of) to try to recover corrupt file, it shouldn't be corrupt in the first place when the node is shutdown cleanly. – Radim Vansa Dec 18 '18 at 15:29
  • I have not suggested (neither here or in the forum thread) to write your own store. On the forums, I've suggested to write tool that will recover the data from corrupt file, adding some heuristic dealing with corrupt entries. In this question I've suggested that you can let your application persist the data independently. – Radim Vansa Dec 18 '18 at 15:33
  • About rebalance notifications, yes, there's http://docs.jboss.org/infinispan/9.4/apidocs/org/infinispan/notifications/cachelistener/annotation/TopologyChanged.html Rebalancing is complete when read and write hashes in the TopologyChangedEvent are identical. – Radim Vansa Dec 18 '18 at 15:35