Hazelcast mongodb 集成; loadAll 方法

Hazelcast mongodb integration; loadAll method

我在他们的 github 页面上查看了 MongoDB 与 hazelcast 集成的代码。

https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/mongodb/src/main/java/com/hazelcast/loader

MongoMapStore 实现了一个以 Java 集合作为参数的 loadAll 方法。稍后在 ReadWriteThroughCache.java 代码中调用 supplements.loadAll,其中 supplements 是我目前所了解的 imap,这会在 MongoMapStore.java 中执行 loadAll 方法,但我们在哪里传递 Collection keys 参数。 mongoCollection 已实例化,但我们如何确定该示例中的键

MapStore#loadAll(keys) 在初始化 Hazelcast 地图时在内部调用。你不需要提供任何参数,它是一组批量分发给所有成员的密钥。请在此处查看启用持久性的地图初始化的详细信息和步骤:http://docs.hazelcast.org/docs/latest/manual/html-single/index.html#initializing-map-on-startup

以下是上面提供的文档 link 的摘录:

Here is the MapLoader initialization flow:

When getMap() is first called from any member, initialization will start depending on the value of InitialLoadMode. If it is set to EAGER, initialization starts on all partitions as soon as the map is touched, i.e., all partitions will be loaded when getMap is called. If it is set to LAZY, data will be loaded partition by partition, i.e., each partition will be loaded with its first touch.

Hazelcast will call MapLoader.loadAllKeys() to get all your keys on one of the members.

That member will distribute keys to all other members in batches.

Each member will load values of all its owned keys by calling MapLoader.loadAll(keys).

Each member puts its owned entries into the map by calling IMap.putTransient(key,value).