java 使用 Hazelcast 在磁盘上持久化数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15132946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:35:49  来源:igfitidea点击:

Persisting data on disk using Hazelcast

javahazelcastin-memory

提问by Hazel_arun

I have installed HazelCast 2.5. I want to persist my records into disk. I learned that MapStore does this job. However i'm not sure how to implement MapStore.

我已经安装了 HazelCast 2.5。我想将我的记录保存到磁盘中。我了解到 MapStore 可以完成这项工作。但是我不确定如何实现 MapStore。

Code I've written so far:

到目前为止我写的代码:

public class MyMaps implements MapStore<String,String> {

    public static Map<Integer, String> mapCustomers = Hazelcast.getMap("customers");

    public static void main(String[] args) {
        {
            mapCustomers.put(1, "Ram");
            mapCustomers.put(2, "David");
            mapCustomers.put(3, "Arun");

        }
    }
}

How do i put all these entries into disk.

我如何将所有这些条目放入磁盘。

Is it necessary to have a back-end like MySQL or PostgreSQL to use this class?

使用这个类是否需要像 MySQL 或 PostgreSQL 这样的后端?

I believe the following function can be used:

我相信可以使用以下功能:

public void delete(String arg0);
public void deleteAll(String arg0);
public void store(String arg0);
public void storeAll(String arg0);

I need a sample snippet of how to implement MapStore.

我需要一个关于如何实现 MapStore 的示例片段。

Please provide me with sample code.

请给我提供示例代码。

回答by Samrat

Yes, you can use MapStore and MapLoader to persist file to local storage. Read official documentation here.

是的,您可以使用 MapStore 和 MapLoader 将文件持久化到本地存储。在此处阅读官方文档。

https://docs.hazelcast.org/docs/latest/manual/html-single/#loading-and-storing-persistent-data

https://docs.hazelcast.org/docs/latest/manual/html-single/#loading-and-storing-persistent-data

回答by TongChen

Hazelcast has two types of distributed objects in terms of their partitioning strategies:

Hazelcast 在分区策略方面有两种类型的分布式对象:

  • Data structures where each partition stores a part of the instance, namely partitioned data structures.

  • Data structures where a single partition stores the whole instance, namely non-partitioned data structures.

  • 每个分区存储一部分实例的数据结构,即分区数据结构。

  • 单个分区存储整个实例的数据结构,即非分区数据结构。

Partitioned Hazelcast data structures persistence data to local file system is not supported,need a centralized system that is accessible from all hazelcast members,like mysql or mongodb.

不支持分区的 Hazelcast 数据结构将数据持久化到本地文件系统,需要一个可以从所有 Hazelcast 成员(如 mysql 或 mongodb)访问的集中式系统。

You can get code from hazelcast-code-samples.

您可以从hazelcast-code-samples获取代码。