【问题标题】:Apache Ignite Cache - Gets all data from database -Apache Ignite Cache - 从数据库中获取所有数据 -
【发布时间】:2018-07-02 19:25:40
【问题描述】:

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

注意缓存模式是复制的。

Apache Ignite 有这样的未来吗?

以下是我打算做的事情:

我会将“atomicityMode”设置为“TRANSACTIONAL”

我将为 cacheStoreFactory 创建类

该类包含从 CacheStoreAdapter 扩展而来的 loadCache 方法。

这是伪代码:

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

     */
}

【问题讨论】:

    标签: java apache-spark caching ignite


    【解决方案1】:

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

    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

    但是,除非您在事务中加载数据,否则其他节点将无法读取它。

    【讨论】:

    • "但是,除非您在事务中加载数据,否则其他节点将无法读取它。"因此,我将确保所有数据都在缓存中,并且客户端在 transaction.commit() 之前不会读取? .我对吗?即使我有多个缓存节点,因为缓存模式是REPLICATED?
    • 并且,你能在 apache ignite 或任何地方给出一个简单的节点定义吗?
    • 看起来您对 REPLICATED 缓存的含义有错误的理解。缓存模式 REPLICATED 只是意味着每个节点都将包含数据的副本(如备份)。 apacheignite.readme.io/docs/cache-modes#replicated-mode 这意味着如果某些节点离线,那么其他节点将包含数据的备份副本,您不会丢失它。即使缓存被复制,那么对于用户来说,它将是统一的缓存。
    • 您可以在此处阅读有关节点的信息 - apacheignite.readme.io/docs/clients-vs-servers
    • 好的,这是完整的场景,我有 1.000.000 个数据,我已经将这些数据加载到缓存中,然后有另一个节点想要复制此缓存中的所有数据,它将提供给客户消费。但是我们应该确定,所有数据在客户端使用之前都复制了,或者如果客户端想要使用,我们应该打印“节点未准备好”。我该如何实现?
    猜你喜欢
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    相关资源
    最近更新 更多