了解 CockroachDB 副本

Understanding CockroachDB Replicas

我很难理解为什么我的单节点设置中的 CockroachDB 管理控制台有 37 个副本。根据我读到的内容

CockroachDB replicates each range (3 times by default) and stores each replica on a different node.

这直接来自文档 https://www.cockroachlabs.com/docs/v20.2/architecture/overview#glossary

运行命令\l我明白了

  database_name
-----------------
  defaultdb
  postgres
  system
  test2
(4 rows)

运行命令SHOW ALL ZONE CONFIGURATIONS;我得到

target                      |                               raw_config_sql
---------------------------------------------------+------------------------------------------------------------------------------
  RANGE default                                    | ALTER RANGE default CONFIGURE ZONE USING
                                                   |     range_min_bytes = 134217728,
                                                   |     range_max_bytes = 536870912,
                                                   |     gc.ttlseconds = 90000,
                                                   |     num_replicas = 3,
                                                   |     constraints = '[]',
                                                   |     lease_preferences = '[]'
  DATABASE system                                  | ALTER DATABASE system CONFIGURE ZONE USING
                                                   |     range_min_bytes = 134217728,
                                                   |     range_max_bytes = 536870912,
                                                   |     gc.ttlseconds = 90000,
                                                   |     num_replicas = 5,
                                                   |     constraints = '[]',
                                                   |     lease_preferences = '[]'
  RANGE meta                                       | ALTER RANGE meta CONFIGURE ZONE USING
                                                   |     range_min_bytes = 134217728,
                                                   |     range_max_bytes = 536870912,
                                                   |     gc.ttlseconds = 3600,
                                                   |     num_replicas = 5,
                                                   |     constraints = '[]',
                                                   |     lease_preferences = '[]'
  RANGE system                                     | ALTER RANGE system CONFIGURE ZONE USING
                                                   |     range_min_bytes = 134217728,
                                                   |     range_max_bytes = 536870912,
                                                   |     gc.ttlseconds = 90000,
                                                   |     num_replicas = 5,
                                                   |     constraints = '[]',
                                                   |     lease_preferences = '[]'
  RANGE liveness                                   | ALTER RANGE liveness CONFIGURE ZONE USING
                                                   |     range_min_bytes = 134217728,
                                                   |     range_max_bytes = 536870912,
                                                   |     gc.ttlseconds = 600,
                                                   |     num_replicas = 5,
                                                   |     constraints = '[]',
                                                   |     lease_preferences = '[]'
  TABLE system.public.replication_constraint_stats | ALTER TABLE system.public.replication_constraint_stats CONFIGURE ZONE USING
                                                   |     gc.ttlseconds = 600,
                                                   |     constraints = '[]',
                                                   |     lease_preferences = '[]'
  TABLE system.public.replication_stats            | ALTER TABLE system.public.replication_stats CONFIGURE ZONE USING
                                                   |     gc.ttlseconds = 600,
                                                   |     constraints = '[]',
                                                   |     lease_preferences = '[]'
(7 rows)

我不确定37是从哪里来的,因为我只创建了数据库test2,它不应该只是3吗?或者如果它甚至复制默认数据库,它仍然只有 3*4 = 12? None 我的数据库超过 512M,因此每个数据库最多只需要 1 个范围。我一定是误会了什么,有人可以帮我吗?谢谢。

Cockroach 内部系统范围比较多。它维护内部系统 tables 以及其他引导元数据。 Cockroach 在 table 边界以及其他一些硬编码分割点上分割范围。您可以通过 运行 查询来发现范围集,例如:

> SELECT start_pretty, end_pretty, database_name, table_name, replicas FROM crdb_internal.ranges_no_leases;

          start_pretty          |          end_pretty           | database_name |           table_name            | replicas
--------------------------------+-------------------------------+---------------+---------------------------------+-----------
  /Min                          | /System/NodeLiveness          |               |                                 | {1,2,3}
  /System/NodeLiveness          | /System/NodeLivenessMax       |               |                                 | {1,2,3}
  /System/NodeLivenessMax       | /System/tsd                   |               |                                 | {1,2,3}
  /System/tsd                   | /System/"tse"                 |               |                                 | {1,2,3}
  /System/"tse"                 | /Table/SystemConfigSpan/Start |               |                                 | {1,2,3}
  /Table/SystemConfigSpan/Start | /Table/11                     |               |                                 | {1,2,3}
  /Table/11                     | /Table/12                     | system        | lease                           | {1,2,3}
  /Table/12                     | /Table/13                     | system        | eventlog                        | {1,2,3}
  /Table/13                     | /Table/14                     | system        | rangelog                        | {1,2,3}
  /Table/14                     | /Table/15                     | system        | ui                              | {1,2,3}
  /Table/15                     | /Table/16                     | system        | jobs                            | {1,2,3}
  /Table/16                     | /Table/17                     |               |                                 | {1,2,3}
  /Table/17                     | /Table/18                     |               |                                 | {1,2,3}
  /Table/18                     | /Table/19                     |               |                                 | {1}
  /Table/19                     | /Table/20                     | system        | web_sessions                    | {1,2,3}
  /Table/20                     | /Table/21                     | system        | table_statistics                | {1,2,3}
  /Table/21                     | /Table/22                     | system        | locations                       | {1,2,3}
  /Table/22                     | /Table/23                     |               |                                 | {1,2,3}
  /Table/23                     | /Table/24                     | system        | role_members                    | {1,2,3}
  /Table/24                     | /Table/25                     | system        | comments                        | {1,2,3}
  /Table/25                     | /Table/26                     | system        | replication_constraint_stats    | {1,2,3}
  /Table/26                     | /Table/27                     | system        | replication_critical_localities | {1,2,3}
  /Table/27                     | /Table/28                     | system        | replication_stats               | {1,2,3}
  /Table/28                     | /Table/29                     | system        | reports_meta                    | {1}
  /Table/29                     | /NamespaceTable/30            |               |                                 | {1,2,3}
  /NamespaceTable/30            | /NamespaceTable/Max           | system        | namespace2                      | {1,2,3}
  /NamespaceTable/Max           | /Table/32                     | system        | protected_ts_meta               | {1,2,3}
  /Table/32                     | /Table/33                     | system        | protected_ts_records            | {1,2,3}
  /Table/33                     | /Table/34                     | system        | role_options                    | {1,2,3}
  /Table/34                     | /Table/35                     | system        | statement_bundle_chunks         | {1,2,3}
  /Table/35                     | /Table/36                     | system        | statement_diagnostics_requests  | {1,2,3}
  /Table/36                     | /Table/37                     | system        | statement_diagnostics           | {1}
  /Table/37                     | /Table/38                     | system        | scheduled_jobs                  | {1,2,3}
  /Table/38                     | /Table/39                     |               |                                 | {1,2,3}
  /Table/39                     | /Max                          | system        | sqlliveness                     | {1,2,3}
(35 rows)

replicas 字段中的每个条目代表一个副本。希望这能让您深入了解存在的范围。