How to detach a table or a keyspace to a new cluster in cassandra

There are many ways to migrate cassandra data, as long as your sstable files are not lost, here are only two common and easy-to-use methods:

The first way: copy command

How to use: Applicable when the amount of data is small.

How to use:

copy mykeyspace.mytable to ‘/home/db.csv’

In this way, the table mytable is successfully exported to the db.csv file in csv format.

Then in another cluster, create an identical table, and then use

copy app12345.mytable from ‘/home/db.csv’

Import the data into the new library.

However, the above methods are limited to a small amount of data. When the amount of data is large, the process will last for a long time, and the file will be very large.

The second way: sstableloader tool.

A sstableloader tool is provided in the bin directory of cassandra, which is specially used to import the sstable file of a table into a new cluster.

Suppose your table is mykeyspace.mytable. Your data is stored in a cluster of 10 nodes, and the data of each point is stored in the /disk/data1 and /disk/data2 directories.

Assuming that an access address of your new cluster is 192.168.2.1, first create a keyspace and table structure with the same name in the new cluster.

Next you just execute the following command on each node of the old cluster:

bin/sstableloader -d 192.168.2.1 -u cassandra -pw cassandra -t 100 /disk/data1/mykeyspace/mytable

bin/sstableloader -d 192.168.2.1 -u cassandra -pw cassandra -t 100 /disk/data2/mykeyspace/mytable

Where -u is the username -pw is the password -t is the limit traffic 100M/bps

After all nodes are executed, your table data will be successfully imported into the new cluster. Of course, as long as your machine io and network conditions allow, you can execute concurrently on multiple nodes.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326944831&siteId=291194637