如何在cassandra集群中的不同节点之间分发数据

时间:2021-03-12 04:47:11

I have setup a multinode cassandra cluster with two different nodes with all required configurations i.e cluster_name , endpoint_snitch , seeds , auto_bootstrap etc. I am using datacenter as dc1 for both nodes. I created keyspace using -

我已经设置了一个多节点cassandra集群,其中包含两个不同的节点,其中包含所有必需的配置,即cluster_name,endpoint_snitch,seeds,auto_bootstrap等。我将两个节点的数据中心用作dc1。我用 - 创建了键空间

CREATE KEYSPACE dcTest WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'dc1' : 2 };

Now , when I start both nodes and try entering data in database , it creates replica on both nodes. i.e if I create 4 rows in table , it copies all 4 rows on another node also. I want this data to get distributed across nodes. i.e two on one node and two on another.

现在,当我启动两个节点并尝试在数据库中输入数据时,它会在两个节点上创建副本。即如果我在表中创建4行,它也会复制另一个节点上的所有4行。我希望这些数据能够跨节点分布。即两个在一个节点上,两个在另一个节点上。

Is it achieved by configuring keyspace? Am I missing anything?

是通过配置密钥空间来实现的吗?我错过了什么吗?

Nodetoll status -

节点状态 -

 nodetool -p 7199 status cassandrareplication1
    Datacenter: dc1
    ===============
    Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address         Load       Tokens       Owns (effective)  Host ID                               Rack
UN  10.45.123.123  35.01 MB   256          50.3%             8c529955-c42a-4629-dfgh-0666a444acbb  rack1
UN  10.45.123.124  225.4 KB   256          49.7%             eddf1039-d803-4d61-dfse-1ce0ec3782a9  rack1

2 个解决方案

#1


1  

You should replication factor 1, not 2. This will mean all your data in this keyspace will be replicated once within this datacenter. With 2 as replication factor it will be replicated twice, 3 thrice and so on.

您应该复制因子1,而不是2.这意味着此密钥空间中的所有数据将在此数据中心内复制一次。使用2作为复制因子,它将被复制两次,3次复制三次,依此类推。

#2


1  

Having 2 Replication means you want 2 copies of your data into datacenter henceforth Cassnadra will put 1 full copy of data on each node to satisfy 2 RF. to achieve your goal you may want to have 1 RF and 2 nodes so Cassandra can distribute data among nodes. you can alter keyspace using

拥有2个复制意味着您需要将2个数据副本放入数据中心,因此Cassnadra将在每个节点上放置1个完整的数据副本以满足2个RF。为了实现您的目标,您可能希望拥有1个RF和2个节点,以便Cassandra可以在节点之间分配数据。你可以使用改变键空间

Alter KEYSPACE dcTest WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'dc1' : 1 };

Don't forget to run nodetool repair with -full option after that.

在此之后不要忘记使用-full选项运行nodetool修复。

#1


1  

You should replication factor 1, not 2. This will mean all your data in this keyspace will be replicated once within this datacenter. With 2 as replication factor it will be replicated twice, 3 thrice and so on.

您应该复制因子1,而不是2.这意味着此密钥空间中的所有数据将在此数据中心内复制一次。使用2作为复制因子,它将被复制两次,3次复制三次,依此类推。

#2


1  

Having 2 Replication means you want 2 copies of your data into datacenter henceforth Cassnadra will put 1 full copy of data on each node to satisfy 2 RF. to achieve your goal you may want to have 1 RF and 2 nodes so Cassandra can distribute data among nodes. you can alter keyspace using

拥有2个复制意味着您需要将2个数据副本放入数据中心,因此Cassnadra将在每个节点上放置1个完整的数据副本以满足2个RF。为了实现您的目标,您可能希望拥有1个RF和2个节点,以便Cassandra可以在节点之间分配数据。你可以使用改变键空间

Alter KEYSPACE dcTest WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'dc1' : 1 };

Don't forget to run nodetool repair with -full option after that.

在此之后不要忘记使用-full选项运行nodetool修复。