LoginSignup
1
1

More than 5 years have passed since last update.

initial_tokenの設定

Posted at

強いハッシュ関数を使うとキーは均一に分散されるはずだけど、MD5は強くないらしい。

# nodetool ring
Note: Ownership information does not include topology, please specify a keyspace.
Address         DC          Rack        Status State   Load            Owns                Token
                                                                                           161038431783640996747061834539477326541
10.10.10.1        datacenter1 rack1       Up     Normal  56.08 KB        59.76%              92566278802770359146832254620092330417
10.10.10.2        datacenter1 rack1       Up     Normal  60.69 KB        5.16%               101344869056471442016922121422834278883
10.10.10.3        datacenter1 rack1       Up     Normal  56.18 KB        18.41%              132670840620665264014573975366691587616
10.10.10.4        datacenter1 rack1       Up     Normal  60.49 KB        5.90%               142707366785106214210137953545520747214
10.10.10.5        datacenter1 rack1       Up     Normal  56.18 KB        10.77%              161038431783640996747061834539477326541

バッラバラ。
データが入っていないのでinitial_tokenを設定する。

プロセス止めてもOKな場合

1.まずプロセスを落とす

# /etc/init.d/cassandra stop

2.データ削除

# rm -rf /var/lib/cassandra/data/*
# rm -rf /var/lib/cassandra/commitlog/*
# rm -rf /var/lib/cassandra/aved_caches/*

3.initial_tokenを計算する

# token-generator 5
DC #1:
  Node #1:                                        0
  Node #2:   34028236692093846346337460743176821145
  Node #3:   68056473384187692692674921486353642290
  Node #4:  102084710076281539039012382229530463435
  Node #5:  136112946768375385385349842972707284580

4.各Nodeごとにinitial_tokenを設定

/etc/cassandra/cassandra.yaml
# Node1
initial_token: 0
# Node2
initial_token: 34028236692093846346337460743176821145
# Node3
initial_token: 68056473384187692692674921486353642290
# Node4
initial_token: 102084710076281539039012382229530463435
# Node5
initial_token: 136112946768375385385349842972707284580

5.起動

# /etc/init.d/cassandra start
Starting Cassandra:                                        [  OK  ]

6.リング確認

# nodetool ring
Note: Ownership information does not include topology, please specify a keyspace.
Address         DC          Rack        Status State   Load            Owns                Token
10.34.68.186    datacenter1 rack1       Up     Normal  9.08 KB         100.00%             0

からの

# nodetool ring
Note: Ownership information does not include topology, please specify a keyspace.
Address         DC          Rack        Status State   Load            Owns                Token
                                                                                           34028236692093846346337460743176821145
10.10.10.1        datacenter1 rack1       Up     Normal  13.51 KB        80.00%              0
10.10.10.2        datacenter1 rack1       Up     Normal  ?               20.00%              34028236692093846346337460743176821145

いい感じ

# nodetool ring
Note: Ownership information does not include topology, please specify a keyspace.
Address         DC          Rack        Status State   Load            Owns                Token
                                                                                           136112946768375385385349842972707284580
10.10.10.1        datacenter1 rack1       Up     Normal  6.72 KB         60.00%              0
10.10.10.2        datacenter1 rack1       Up     Normal  13.51 KB        20.00%              34028236692093846346337460743176821145
10.10.10.3        datacenter1 rack1       Up     Normal  6.72 KB         20.00%              68056473384187692692674921486353642290
10.10.10.4        datacenter1 rack1       Up     Joining 6.72 KB         0.00%               102084710076281539039012382229530463435
10.10.10.5        datacenter1 rack1       Up     Joining 4.58 KB         0.00%               136112946768375385385349842972707284580

Joining!!

# nodetool ring
Note: Ownership information does not include topology, please specify a keyspace.
Address         DC          Rack        Status State   Load            Owns                Token
                                                                                           136112946768375385385349842972707284580
10.10.10.1        datacenter1 rack1       Up     Normal  15.57 KB        20.00%              0
10.10.10.2        datacenter1 rack1       Up     Normal  6.72 KB         20.00%              34028236692093846346337460743176821145
10.10.10.3        datacenter1 rack1       Up     Normal  6.72 KB         20.00%              68056473384187692692674921486353642290
10.10.10.4        datacenter1 rack1       Up     Normal  6.72 KB         20.00%              102084710076281539039012382229530463435
10.10.10.5        datacenter1 rack1       Up     Normal  4.58 KB         20.00%              136112946768375385385349842972707284580

ぴったんこカンカン

オンラインで変更する場合

nodetool moveを各ノードで実行

# nodetool -h ${NODE_IP} move ${割り当てるTOKEN}

時間がかかるらしいので、止めれるなら止めよう。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1