Apache Ignite Cache - 从数据库中获取所有数据 -



我如何确定这样的条件总是正确的: 假设我有 3 个表,包含 1000、2000、3000 条记录。 我必须将所有记录加载到缓存中,但我想确保在客户端使用此缓存之前所有数据都在缓存中。

请注意,将复制缓存模式。

Apache Ignite 有这个未来吗?

以下是我将计划做的事情:

我将"原子性模式"设置为"事务">

我将为 cacheStoreFactory 创建类

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

这是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;
}
*/
}

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

https://apacheignite.readme.io/docs/countdownlatch

https://apacheignite.readme.io/docs/distributed-semaphore

https://apacheignite.readme.io/docs/atomic-types

此外,您可以检查缓存的大小或将消息从一个节点发送到另一个节点,如下所示:

https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/messaging/MessagingExample.java

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

最新更新