问题
How I sure such a this condition always true: Let's say I have 3 tables which are contains 1000, 2000, 3000 records. And I have to load that all records to the cache, but I want to be sure all the data is in cache before Client using this cache.
Note that cache mode is replicated.
Apache Ignite has this future?
Here is the things that I will plan to do:
I will set the "atomicityMode" to the "TRANSACTIONAL"
I will create class for cacheStoreFactory
This class contains loadCache method extends from CacheStoreAdapter.
here is the pseducode:
public void loadCache(IgniteBiInClosure<K, V> clo, Object... args) {
// Connect the all databases
/*while true:
try(Transaction transaction = Ignition.ignite().transactions().txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.SERIALIZABLE)){
PreparedStatement for all databases such as "select * from persons"
then take the all ResultSet from all databases
then create the corresponding object from the results and put the "clo.apply(objectID, object);"
before transaction.commit()
if there is way, find the total records number from all databases (maybe find before starting try block)
then, again if there is way, compare the cache size and total records
If 2 numbers are equals -> transaction.commmit() & break
else -> continue;
}
*/
}
回答1:
You can use distributed data structures to signal that some action was completed. For example:
https://apacheignite.readme.io/docs/countdownlatch
https://apacheignite.readme.io/docs/distributed-semaphore
https://apacheignite.readme.io/docs/atomic-types
Also, you can check the size of the cache or send the message from one node to another like here:
https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/messaging/MessagingExample.java
However, until you load the data in the transaction then other nodes will not be able to read it.
来源:https://stackoverflow.com/questions/51142575/apache-ignite-cache-gets-all-data-from-database