Saturday, 29 August 2015

Backups and Restore data In Cassandra

 Cassandra backs up data by taking a snapshot of all on-disk data files (SSTable files) stored in the data directory. You can take a snapshot of all keyspaces, a single keyspace, or a single table while the system is online.

Using a parallel ssh tool (such as pssh), you can snapshot an entire cluster. This provides an eventually consistent backup. Although no one node is guaranteed to be consistent with its replica nodes at the time a snapshot is taken, a restored snapshot resumes consistency using Cassandra's built-in consistency mechanisms.
After a system-wide snapshot is performed, you can enable incremental backups on each node to backup data that has changed since the last snapshot: each time an SSTable is flushed, a hard link is copied into a /backups subdirectory of the data directory (provided JNA is enabled)

1. Taking a snapshot

Run the nodetool snapshot command, specifying the hostname, JMX port, and keyspace.
$ nodetool -h hostname -p jmx port snapshot mykeyspace

 For example:

$ nodetool -h localhost -p 7999  snapshot test

The snapshot is created in data_directory_location/keyspace_name/table_name/snapshots/snapshot_name directory. Each snapshot directory contains numerous .db files that contain the data at the time of the snapshot.

For example:

Packaged installs:


Tarball installs:


Deleting snapshot files

To delete all snapshots for a node, run the nodetool clearsnapshot command. For example:
$ nodetool -h localhost -p 7199 clearsnapshot

Enabling incremental backups

Edit the cassandra.yaml configuration file on each node in the cluster and change the value of incremental_backups to true.

 Restoring from a Snapshot

1. Shut down the node.

2. Clear all files in the commitlog directory:
 Packaged installs: /var/lib/cassandra/commitlog
 Tarball installs: install_location/data/commitlog

3. Delete all *.db files in data_directory_location/keyspace_name/table_name directory, but DO NOT delete the /snapshots and /backups subdirectories. where data_directory_location is Packaged installs: /var/lib/cassandra/data and Tarball installs: install_location/data/data

4. Locate the most recent snapshot folder in this directory:

5. Copy its contents into this directory: data_directory_location/keyspace_name/table_name directory.

6. If using incremental backups, copy all contents of this directory:

7. Paste it into this directory: data_directory_location/keyspace_name/table_name
8. Restart the node.

Related Posts :

Insert Data Into Cassandra Example

Insert Data Into Cassandra Example Set 2 

 Select Data From Cassandra Using Java

Java Memory Leak Cause

 In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations[1] in such a way that memory which is no longer needed is not released. In object-oriented
programming, a memory leak may happen when an object is stored in memory but cannot be accessed by the running code.[2] A memory leak has symptoms similar to a number of other problems (see below) and generally can only be diagnosed by a programmer with access to the program's source code. Here are the typical cause of  Memory Leak In Java:

1. Do not close DB, file, socket, JMS resources and other external resources properly.

2. Do not close resources properly when an exception is thrown.

3.  Keep adding objects to a cache or a hash map without expiring the old one.

3. Do not implement the hash and equal function correctly for the key to a cache

4. Leak in third party library or the application server

5. Bugs in the JDK.

6. In an infinite application code loop.

7. Leaking memory in the native code

9. Session data is too large.


Friday, 28 August 2015 Failed to retrieve RMIServer stub: javax.naming.CommunicationException in cassandra

 I had got this exception many times when i had snapshot from cassandra. i try with different ways but there was no solutions. After many try i goto cassandra.yaml file and change rcp_ip address  after that i restart cassandra and it works properly . I  things this problem occur if some ip configure have issue or net connection down. Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host:; nested exception is: Connection refused: connect]
    at my.code.RemoteSimonManagerFactoryImpl.createSimonManager(
    at my.code.Demo.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at com.intellij.rt.execution.application.AppMain.main(
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host:; nested exception is: Connection refused: connect]
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(
    at com.sun.jndi.toolkit.url.GenericURLContext.lookup(
    at javax.naming.InitialContext.lookup(
    ... 9 more
Caused by: java.rmi.ConnectException: Connection refused to host:; nested exception is: Connection refused: connect
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(
    at sun.rmi.transport.tcp.TCPChannel.createConnection(
    at sun.rmi.transport.tcp.TCPChannel.newConnection(
    at sun.rmi.server.UnicastRef.newCall(
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(

Related Posts

How do I delete all data in a Cassandra column family ?

Wednesday, 26 August 2015

How to delete a non-empty directory in Terminal?

rm -rf myfolder

It deletes all files and folders contained in the myfolder directory.

Add sudo at the beginning of the command :

In case user doesn't have the permission to delete the folder:

sudo rm -rf myfolder

Otherwise, without sudo you will be returned permission denied. And it's a good practice to try not to use -f while deleting a directory:

sudo rm -r myfolder

Note: this is assuming you are already on the same level of the folder you want to delete in terminal, if not:

sudo rm -r /path/to/myfolder
FYI: you can use letters -f, -r, -v:

-f = to ignore non-existent files, never prompt
-r = to remove directories and their contents recursively
-v = to explain what is being done

How do I delete all data in a Cassandra column family ?

We can truncate  all rows from cassandra tables using truncate


cqlsh: test > TRUNCATE test.users ;


How to Convert Java Timestamp to MySQL timestamp vice versa

How to Insert java time in mysql timestamp

java.util.Date date = new Date();

Timestamp timestamp = new Timestamp(date.getTime());

preparedStatement.setTimestamp(1, timestamp);

Thursday, 6 August 2015

How To Install and Use Memcache on Ubuntu

Memcached  is a general-purpose distributed memory caching system. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source  must be read.

Install Memcached

1.     Firstly we install libevent

       sudo apt-get update

       sudo apt-get install libevent-core-2.0-5

2.  Install memcached 

 sudo apt-get install memcached


3.  configure iptables  with these entries

 sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT

 sudo iptables -A INPUT -m state --state NEW -m udp -p udp --dport 11211 -j ACCEPT

4.  Go to  /usr/share/memcached/memcached.conf.default
     and  change defulat connection port:

   -p 11211 [defualt]


 -m 20

and ip address also
-l [ip address ]

5.  Now also configure    /etc/memcached.conf

  change    port

    -p 11211 [defualt]

    and ip address

-l [ip address ]


-> telnet 11211

You can check memcached is runing or not.