Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persisting data on disk using Hazelcast

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.

like image 964
Hazel_arun Avatar asked Feb 28 '13 10:02

Hazel_arun


People also ask

How does Hazelcast store data?

Hazelcast is horizontally scalable, so you can join hundreds of nodes in a cluster to aggregate terabytes of RAM to keep all your data in memory. Hazelcast replicates data across the cluster, so it has no single point of failure. In the case of a node failure, your application will continue operating with no downtime.

How much data can Hazelcast store?

Hazelcast will create 40 DirectBuffers, each with 1GB capacity. If you have, say 50 nodes, then you have total of 2TB off-heap storage capacity.

What is MapStore in Hazelcast?

public interface MapStore<K,V> extends MapLoader<K,V> Hazelcast distributed map implementation is an in-memory data store, but it can be backed by any type of data store such as RDBMS, OODBMS, NOSQL, or simply a file-based data store. IMap. put(key, value) normally stores the entry into JVM's memory.

How does Hazelcast cluster work?

Hazelcast is designed to scale up to hundreds and thousands of members. Simply add new members; they automatically discover the cluster and linearly increase both the memory and processing capacity. The members maintain a TCP connection between each other and all communication is performed through this layer.


2 Answers

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

like image 74
Samrat Avatar answered Oct 07 '22 04:10

Samrat


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.

like image 43
TongChen Avatar answered Oct 07 '22 04:10

TongChen