【Cassandra】使用nodetool status / ring / describering命令查询集群状态、分区环和描述分区环信息

首先

本页面上显示的命令结果是DSE分发的结果(版本各有不同)。

1. 节点工具状态查询。

集群状态显示

如果指定了键空间并进行了执行,则在”Owns”列中显示可用令牌范围的比例。
令牌范围的比例是每个节点拥有的令牌比例与复制因子相乘的结果。
如果键空间的复制因子为2,则集群中的百分比总和约为200%,如果复制因子为3,则约为300%。

执行示例:DSE 5.1.17

# nodetool status test01
Datacenter: DC1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address     Load       Tokens       Owns (effective)  Host ID                               Rack
UN  10.0.2.131  722.14 KiB  256          70.8%             3f1d4bd5-e99f-4251-8a8a-d5c23a2d2fa9  RAC1
UN  10.0.2.121  659.79 KiB  256          76.7%             a2541bd4-8d08-41ae-abf0-b22d4cae5716  RAC1
UN  10.0.2.122  662.59 KiB  256          75.8%             244dc6ed-45a1-47df-a89c-0ee2dc3f4a38  RAC1
UN  10.0.2.123  714.68 KiB  256          76.6%             9490e3e8-16af-4d5a-9e31-0e480c613ad8  RAC1

# 

如果在不指定keyspace的情况下执行的话,在之前的版本(例如,DSE4.8.x)中,Own列会显示为问号,但是在最新的版本(至少从5.1.17开始),会显示百分比。不管怎样,根据DATASTAX文档的说明,如果要对该字段的数字进行解释,需要在执行nodetool status时指定相应的keyspace。

“重要提示:如果集群中存在具有不同复制策略或复制因子的keyspace,请在执行nodetool status时指定keyspace以获取有意义的所有权信息。”

(运行示例:DSE 4.8.16)

# nodetool status 
Datacenter: DC1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address     Load       Tokens  Owns    Host ID                               Rack
UN  10.0.2.121  479.96 KB  256     ?       e52df442-eebb-490a-8787-372d4e2705c2  RAC1
UN  10.0.2.122  433.09 KB  256     ?       b1ccdf1e-a6ee-4f71-95c3-b3b5bd0f3e81  RAC1
UN  10.0.2.123  488.47 KB  256     ?       a4cfeb3a-1fa2-4f99-ac8b-e14e2aa44ec4  RAC1

Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless
# 

2. 节点工具环路查询

类似于 nodetool status,但按照令牌范围显示节点的状态

实例执行: DSE 5.1.17

# nodetool ring test01 

Datacenter: DC1
==========
Address     Rack        Status State   Load            Owns                Token                                       
                                                                           9218035512596006795                         
10.0.2.121  RAC1        Up     Normal  659.79 KiB      76.72%              -9222728930267421097                        
10.0.2.131  RAC1        Up     Normal  722.14 KiB      70.85%              -9180151874169604866                        
10.0.2.131  RAC1        Up     Normal  722.14 KiB      70.85%              -9162853831163961080                        
10.0.2.122  RAC1        Up     Normal  662.59 KiB      75.79%              -9129890199084435875                        
10.0.2.131  RAC1        Up     Normal  722.14 KiB      70.85%              -9125736719015339102                        
10.0.2.131  RAC1        Up     Normal  722.14 KiB      70.85%              -9113235406061065294                        
10.0.2.122  RAC1        Up     Normal  662.59 KiB      75.79%              -9113100503939633554                        

    :
   (略)
    :

10.0.2.121  RAC1        Up     Normal  659.79 KiB      76.72%              9218035512596006795         


  Warning: "nodetool ring" is used to output all the tokens of a node.
  To view status related info of a node use "nodetool status" instead.

只是一个与nodetool命令无关的插曲,通过结合cqlsh的token函数和nodetool ring(或后续的nodetool describering)的结果,可以手动执行在令牌范围内进行分页查询的查询。

cqlsh> select * from test01.customer where token(id) <= -9222728930267421097; 

 id   | age | firstname | lastname
------+-----+-----------+----------
 4317 |  17 |     aaaaa |    bbbbb 
 3356 |  26 |     aaaaa |    bbbbb
    :
   (略)
    :

cqlsh> select * from test01.customer where token(id) > -9222728930267421097 and token(id) <= -9129890199084435875;

 id   | age | firstname | lastname
------+-----+-----------+----------
 3372 |  27 |     aaaaa |    bbbbb
 1584 |  26 |     aaaaa |    bbbbb

    :
   (略)
    :

cqlsh> select * from test01.customer where token(id) >  9218035512596006795;

 id   | age | firstname | lastname
------+-----+-----------+----------
 5504 |  17 |     aaaaa |    bbbbb
 3476 |  42 |     aaaaa |    bbbbb
    :
   (略)
    :

3. nodetool describering 转述为中文:查看环的描述。

显示 Keyspace 的分区范围(以令牌值表示,未进行排序)。

实例执行:DSE 5.1.17

# nodetool describering test01
Schema Version:3e44afb3-428b-3c44-a053-6363a2a78403
Keyspace: test01
TokenRange: 
        TokenRange(start_token:-7067710157254911858, end_token:-7027724543442860409, endpoints:[10.0.2.122, 10.0.2.121, 10.0.2.123], rpc_endpoints:[10.0.2.122, 10.0.2.121, 10.0.2.123], endpoint_details:[EndpointDetails(host:10.0.2.122, datacenter:DC1, rack:RAC1), EndpointDetails(host:10.0.2.121, datacenter:DC1, rack:RAC1), EndpointDetails(host:10.0.2.123, datacenter:DC1, rack:RAC1)])
        TokenRange(start_token:-4032970123352172154, end_token:-3949095354840399141, endpoints:[10.0.2.123, 10.0.2.121, 10.0.2.122], rpc_endpoints:[10.0.2.123, 10.0.2.121, 10.0.2.122], endpoint_details:[EndpointDetails(host:10.0.2.123, datacenter:DC1, rack:RAC1), EndpointDetails(host:10.0.2.121, datacenter:DC1, rack:RAC1), EndpointDetails(host:10.0.2.122, datacenter:DC1, rack:RAC1)])
        TokenRange(start_token:1245622280671050746, end_token:1265745285746323744, endpoints:[10.0.2.121, 10.0.2.122, 10.0.2.123], rpc_endpoints:[10.0.2.121, 10.0.2.122, 10.0.2.123], endpoint_details:[EndpointDetails(host:10.0.2.121, datacenter:DC1, rack:RAC1), EndpointDetails(host:10.0.2.122, datacenter:DC1, rack:RAC1), EndpointDetails(host:10.0.2.123, datacenter:DC1, rack:RAC1)])

    :
   (略)
    :

2020-05-05_182221.png
广告
将在 10 秒后关闭
bannerAds