本节讨论 NDB 集群如何划分和复制数据以进行存储。This section discusses the manner in which NDB Cluster divides and duplicates data for storage.
接下来的几段将讨论理解该主题所需的若干核心概念。A number of concepts central to an understanding of this topic are discussed in the next few paragraphs.
数据节点。 一个 ndbd 或 ndbmtd 进程,它存储一个或多个 分片副本——也就是分配给该节点所属节点组的 分区 的副本(本节稍后将讨论)。Data node. An ndbd or ndbmtd process, which stores one or more fragment replicas—that is, copies of the partitions (discussed later in this section) assigned to the node group of which the node is a member.
每个数据节点应位于不同的计算机上。虽然也可以在一台计算机上托管多个数据节点进程,但通常不建议采用这种配置。Each data node should be located on a separate computer. While it is also possible to host multiple data node processes on a single computer, such a configuration is not usually recommended.
当指代 ndbd 或 ndbmtd 进程时,术语 “节点” 和 “数据节点” 常常可以互换使用;在此讨论中,管理节点 (ndb_mgmd 进程) 和 SQL 节点 (mysqld 进程) 会在讨论中明确标出。It is common for the terms “node” and “data node” to be used interchangeably when referring to an ndbd or ndbmtd process; where mentioned, management nodes (ndb_mgmd processes) and SQL nodes (mysqld processes) are specified as such in this discussion.
节点组。 节点组由一个或多个节点组成,并存储分区,或者说碎片副本集合(见下一项)。Node group. A node group consists of one or more nodes, and stores partitions, or sets of fragment replicas (see next item).
NDB Cluster 中的节点组数量不能直接配置;它取决于数据节点的数量和碎片副本数量(NoOfReplicas 配置参数),如下所示:The number of node groups in an NDB Cluster is not directly
configurable; it is a function of the number of data nodes and of
the number of fragment replicas
(NoOfReplicas
configuration parameter), as shown here:
[# of node groups] = [# of data nodes] / NoOfReplicas
因此,如果在 config.ini 文件中将 NoOfReplicas 设置为 1,则具有 4 个数据节点的 NDB 集群将有 4 个节点组;如果将 NoOfReplicas 设置为 2,则有 2 个节点组;如果将 NoOfReplicas 设置为 4,则有 1 个节点组。本节稍后将讨论分段副本;有关 NoOfReplicas 的更多信息,请参见 第 25.4.3.6 节,“定义 NDB 集群数据节点”。Thus, an NDB Cluster with 4 data nodes has 4 node groups if
NoOfReplicas is set to 1
in the config.ini file, 2 node groups if
NoOfReplicas is set to 2,
and 1 node group if
NoOfReplicas is set to 4.
Fragment replicas are discussed later in this section; for more
information about
NoOfReplicas, see
Section 25.4.3.6, “Defining NDB Cluster Data Nodes”.
NDB 集群中的所有节点组必须具有相同数量的数据节点。All node groups in an NDB Cluster must have the same number of data nodes.
您可以在运行中的 NDB 集群中在线添加新的节点组(从而添加新的数据节点);有关更多信息,请参见 第 25.6.7 节,“在线添加 NDB 集群数据节点”。You can add new node groups (and thus new data nodes) online, to a running NDB Cluster; see Section 25.6.7, “Adding NDB Cluster Data Nodes Online”, for more information.
分区。 这是集群存储的数据的一部分。每个节点负责保持分配给它的至少一个分区副本(即至少一个碎片副本)对集群可用。Partition. This is a portion of the data stored by the cluster. Each node is responsible for keeping at least one copy of any partitions assigned to it (that is, at least one fragment replica) available to the cluster.
NDB 集群默认使用的分区数量取决于数据节点的数量以及数据节点使用的 LDM 线程数量,如下所示:The number of partitions used by default by NDB Cluster depends on the number of data nodes and the number of LDM threads in use by the data nodes, as shown here:
[# of partitions] = [# of data nodes] * [# of LDM threads]
在使用运行 ndbmtd 的数据节点时,LDM 线程的数量由 MaxNoOfExecutionThreads 的设置控制。使用 ndbd 时,只有一个 LDM 线程,这意味着集群中参与的节点数量等于集群分区的数量。当使用 ndbmtd 并将 MaxNoOfExecutionThreads 设置为 3 或更少时,也同样如此。(您应该注意,LDM 线程的数量会随着此参数的值增加,但并不是严格线性的,而且在设置时还有额外的限制;有关详细信息,请参见 MaxNoOfExecutionThreads 的描述。)When using data nodes running ndbmtd, the
number of LDM threads is controlled by the setting for
MaxNoOfExecutionThreads.
When using ndbd there is a single LDM thread,
which means that there are as many cluster partitions as nodes
participating in the cluster. This is also the case when using
ndbmtd with
MaxNoOfExecutionThreads set to 3 or less. (You
should be aware that the number of LDM threads increases with the
value of this parameter, but not in a strictly linear fashion, and
that there are additional constraints on setting it; see the
description of
MaxNoOfExecutionThreads
for more information.)
NDB 和用户定义的分区。 NDB 集群通常会自动对 NDBCLUSTER 表进行分区。不过,也可以在 NDBCLUSTER 表中使用用户定义的分区。此功能受以下限制:NDB and user-defined partitioning.
NDB Cluster normally partitions
NDBCLUSTER tables automatically.
However, it is also possible to employ user-defined partitioning
with NDBCLUSTER tables. This is
subject to the following limitations:
在生产环境中,
NDB表仅支持KEY和LINEAR KEY分区方案。Only theKEYandLINEAR KEYpartitioning schemes are supported in production withNDBtables.对于任何
NDB表,可以显式定义的最大分区数是8 * [number of LDM threads] * [number of node groups],NDB 集群中的节点组数量如本节前面所述确定。当运行用于数据节点进程的 ndbd 时,设置 LDM 线程的数量不会产生影响(因为ThreadConfig仅适用于 ndbmtd);在这种情况下,为了进行此计算,可以将该值视为等于 1。The maximum number of partitions that may be defined explicitly for anyNDBtable is8 * [, the number of node groups in an NDB Cluster being determined as discussed previously in this section. When running ndbd for data node processes, setting the number of LDM threads has no effect (sincenumber of LDM threads] * [number of node groups]ThreadConfigapplies only to ndbmtd); in such cases, this value can be treated as though it were equal to 1 for purposes of performing this calculation.有关更多信息,请参见第 25.5.3 节,“ndbmtd — NDB Cluster 数据节点守护进程(多线程)”。See Section 25.5.3, “ndbmtd — The NDB Cluster Data Node Daemon (Multi-Threaded)”, for more information.
有关 NDB Cluster 和用户定义分区的更多信息,请参见第 25.2.7 节,“NDB Cluster 已知限制”,以及第 26.6.2 节,“与存储引擎相关的分区限制”。For more information relating to NDB Cluster and user-defined partitioning, see Section 25.2.7, “Known Limitations of NDB Cluster”, and Section 26.6.2, “Partitioning Limitations Relating to Storage Engines”.
片段副本。 这是集群分区的副本。节点组中的每个节点都存储一个片段副本。有时也称为 分区副本。片段副本的数量等于每个节点组中的节点数量。Fragment replica. This is a copy of a cluster partition. Each node in a node group stores a fragment replica. Also sometimes known as a partition replica. The number of fragment replicas is equal to the number of nodes per node group.
一个片段副本完全属于单个节点;一个节点可以(通常也会)存储多个片段副本。A fragment replica belongs entirely to a single node; a node can (and usually does) store several fragment replicas.
下图说明了一个 NDB 集群,其中有四个数据节点运行 ndbd,分布在两个每个包含两个节点的节点组中;节点 1 和 2 属于节点组 0,节点 3 和 4 属于节点组 1。The following diagram illustrates an NDB Cluster with four data nodes running ndbd, arranged in two node groups of two nodes each; nodes 1 and 2 belong to node group 0, and nodes 3 and 4 belong to node group 1.
这里只显示数据节点;虽然一个可运行的 NDB 集群需要一个 ndb_mgmd 进程来进行集群管理,并且至少需要一个 SQL 节点来访问集群存储的数据,但为了清晰起见,这些在图中被省略了。Only data nodes are shown here; although a working NDB Cluster requires an ndb_mgmd process for cluster management and at least one SQL node to access the data stored by the cluster, these have been omitted from the figure for clarity.
集群存储的数据被划分为四个分区,编号为 0、1、2 和 3。每个分区以多个副本的形式存储在同一个节点组中。分区按如下方式存储在交替的节点组上:The data stored by the cluster is divided into four partitions, numbered 0, 1, 2, and 3. Each partition is stored—in multiple copies—on the same node group. Partitions are stored on alternate node groups as follows:
分区 0 存储在节点组 0 上;一个 主分片副本(主副本)存储在节点 1,备份分片副本(分区的备份副本)存储在节点 2。Partition 0 is stored on node group 0; a primary fragment replica (primary copy) is stored on node 1, and a backup fragment replica (backup copy of the partition) is stored on node 2.
分区 1 存储在另一个节点组(节点组 1)上;该分区的主碎片副本在节点 3 上,备份碎片副本在节点 4 上。Partition 1 is stored on the other node group (node group 1); this partition's primary fragment replica is on node 3, and its backup fragment replica is on node 4.
分区 2 存储在节点组 0 上。然而,它的两个碎片副本的放置与分区 0 相反;对于分区 2,主碎片副本存储在节点 2 上,备份存储在节点 1 上。Partition 2 is stored on node group 0. However, the placing of its two fragment replicas is reversed from that of Partition 0; for Partition 2, the primary fragment replica is stored on node 2, and the backup on node 1.
分区 3 存储在节点组 1 上,其两个碎片副本的放置与分区 1 相反。也就是说,它的主碎片副本位于节点 4,备份位于节点 3。Partition 3 is stored on node group 1, and the placement of its two fragment replicas are reversed from those of partition 1. That is, its primary fragment replica is located on node 4, with the backup on node 3.
这对 NDB 集群的持续运行意味着:只要集群中每个参与的节点组至少有一个节点在运行,集群就拥有所有数据的完整副本,并保持可用。下一张图说明了这一点。What this means regarding the continued operation of an NDB Cluster is this: so long as each node group participating in the cluster has at least one node operating, the cluster has a complete copy of all data and remains viable. This is illustrated in the next diagram.
在此示例中,集群由两个节点组组成,每个节点组包含两个数据节点。每个数据节点都运行一个 ndbd 实例。来自节点组 0 的至少一个节点与来自节点组 1 的至少一个节点的任意组合都足以保持集群“存活”。然而,如果单个节点组的两个节点都发生故障,剩余在另一个节点组中的两个节点的组合将不足以维持集群。在这种情况下,集群已经丢失了整个分区,因此无法再提供对全部 NDB 集群数据的完整访问。In this example, the cluster consists of two node groups each consisting of two data nodes. Each data node is running an instance of ndbd. Any combination of at least one node from node group 0 and at least one node from node group 1 is sufficient to keep the cluster “alive”. However, if both nodes from a single node group fail, the combination consisting of the remaining two nodes in the other node group is not sufficient. In this situation, the cluster has lost an entire partition and so can no longer provide access to a complete set of all NDB Cluster data.
单个 NDB 集群实例支持的最大节点组数量为 48。The maximum number of node groups supported for a single NDB Cluster instance is 48.

