Apache Ignite Cache - Gets all data from database -

时间秒杀一切 提交于 2019-12-11 16:44:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!