Apache Ignite缓存-从数据库获取所有数据- [英] Apache Ignite Cache - Gets all data from database -

查看:84
本文介绍了Apache Ignite缓存-从数据库获取所有数据-的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何确定这种情况始终为真:假设我有3个表,其中包含1000、2000、3000个记录.而且我必须将所有记录都加载到缓存中,但是我想确保在客户端使用此缓存之前所有数据都在缓存中.

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有这个未来吗?

Apache Ignite has this future?

这是我打算做的事情:

我将"atomicityMode"设置为"TRANSACTIONAL"

I will set the "atomicityMode" to the "TRANSACTIONAL"

我将为cacheStoreFactory创建类

I will create class for cacheStoreFactory

此类包含从CacheStoreAdapter扩展的loadCache方法.

This class contains loadCache method extends from CacheStoreAdapter.

这是pseducode:

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;
        }

     */
}

推荐答案

您可以使用分布式数据结构来表示某些操作已完成.例如:

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:

但是,在将数据加载到事务中之前,其他节点将无法读取它.

However, until you load the data in the transaction then other nodes will not be able to read it.

这篇关于Apache Ignite缓存-从数据库获取所有数据-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆