12

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.

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?

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.

Please provide me with sample code.

jsheeran
  • 2,912
  • 2
  • 17
  • 32
Hazel_arun
  • 1,721
  • 2
  • 13
  • 17
  • 1
    Hazelcast doesnt allow persistence to File. Quote from the documentation " NOTE: Data store needs to be a centralized system that is accessible from all Hazelcast members. Persistence to a local file system is not supported." – mprabhat Nov 21 '18 at 06:15
  • Sample from [hazelcast-code-samples](https://github.com/hazelcast/hazelcast-code-samples) can help you. – TongChen May 22 '20 at 06:27

2 Answers2

1

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

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

Samrat
  • 1,329
  • 12
  • 15
  • Map is partitioned Hazelcast data structure,Data store needs to be a centralized system that is accessible from all Hazelcast members. Persistence to a local file system is not supported. – TongChen May 22 '20 at 06:33
1

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

  • 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.

You can get code from hazelcast-code-samples.

TongChen
  • 1,414
  • 1
  • 11
  • 21