集群扩展

Trove 目前的集群支持没有直接支持增长或缩小集群的功能。当前的 MongoDB 集群实现确实支持通过“add-shard”操作添加“分片”,但已决定应更改为使用本规范中概述的新 cluster-grow 功能。

cluster-grow 和 cluster-shrink 功能已经在之前的年中周期会议和峰会上讨论过,并被接受为优于当前 MongoDB 数据存储实现中的 add-shard 功能。本规范旨在为 Percona 和 Redis 集群中的 shrink/grow 功能开发基础,并与 MongoDB 集群实现保持向后兼容。

Launchpad Blueprint: https://blueprints.launchpad.net/trove/+spec/cluster-scaling

问题描述

Trove 集群支持需要扩展,以支持增加或减少集群的大小。将通过添加用于 cluster-grow 和 cluster-shrink 的新的 ReST API,以及相应的 CLI 和 python-troveclient 支持来提供此支持。

MongoDB 集群实现将得到增强,以支持 cluster-grow,除了目前支持的“add-shard”操作之外。

提议的变更

新的 ReST API

将为此功能添加两个新的 ReST API。

cluster-grow

向集群添加节点。

这个新的 API 在常规实例负载中添加了 3 个新的属性

name

要分配给实例的名称

instance_type

实例的特定于数据存储的类型(例如,Mongo 的 query/replica,Redis 的 master/slave)。

related_to

定义一个成员到另一个成员的关系。该值特定于数据存储,但很可能指的是同一 ReST 负载中先前定义的实例的名称。

请求

POST /v1.0/<tenant_id>/clusters/<cluster-id>/action
{
    "grow": [
      {
        "name": "redis-clstr-member-5",
        "instance_type": "master",
        "flavorRef": "2",
        "volume": {
          "size": 2
        },
      },
      {
        "name": "redis-clstr-member-6",
        "instance_type": "slave",
        "related_to": "redis-clstr-member-5",
        "flavorRef": "2",
        "volume": {
          "size": 2
        },
      }
    ]
}

响应

{
  "cluster": {
    "id": "edaac9ca-b5e1-4028-adb7-fa7653e11224",
    "task": {
      "id": 2,
      "name": "BUILDING",
      "description": "Building the initial cluster."
    },
    "name": "redis-clstr",
    "created": "2015-01-29T20:19:23",
    "updated": "2015-01-29T20:19:23",
    "links": [{...}],
    "datastore": {
      "type": "redis",
      "version": "3.0"
    },
    "ip": [],
    "instances": [
      {
        "id": "416b0b16-ba55-4302-bbd3-ff566032e1c1",
        "name": "redis-clstr-member-5",
        "instance_type": "master",
        "status": "BUILD",
        "ip": [],
        "links": [{...}],
        "flavor": {
          "id": "2",
          "links": [{...}]
        },
        "volume": {
          "size": 2
        }
      },
      {
        "id": "965ef811-7c1d-47fc-89f2-a89dfdd23ef2",
        "name": "redis-clstr-member-6",
        "instance_type": "slave",
        "related_to": "redis-clstr-member-5",
        "status": "BUILD",
        "ip": [],
        "links": [{...}],
        "flavor": {
          "id": "2",
          "links": [{...}]
        },
        "volume": {
          "size": 2
        }
      },
    ]
  }
}

HTTP 状态码

202 - Accepted.
400 - BadRequest. Server could not understand request.
403 - Forbidden. Local storage not specified in flavor ID: <ID>.
403 - Forbidden. A flavor is required for each instance in the cluster.
404 - Not Found. Flavor <id> not found.
404 - Not Found. Cluster <id> not found.

cluster-shrink

从集群中删除指定的实例。

请求

POST /v1.0/<tenant_id>/clusters/<cluster_id>/action
    "shrink": [
      {
        "id": "416b0b16-ba55-4302-bbd3-ff566032e1c1",
      },
      {
        "id": "965ef811-7c1d-47fc-89f2-a89dfdd23ef2",
      }
    ]
}

响应

N/A

HTTP 代码

202 - Accepted.
403 - Forbidden. Instance <instance_id> not in state to be removed.
404 - Instance <instance_id> not found in cluster <id>.

配置

n/a

数据库

n/a

公共 API

此更改添加了新的 CLI 命令 cluster-grow 和 cluster-shrink,详细信息如下。这些 CLI 命令及其相应的 API 应与现有的 CLI 和 API 用法保持一致。

公共 API 安全

预计不会产生安全影响。

Python API

以下方法将添加到 python-troveclient 中的 Clusters 类

class Clusters:

  def grow(self, cluster, instances)
      """Grow the specified cluster.

      :param cluster: The cluster to grow
      :param instances: JSON describing instances to add
      """

  def shrink(self, cluster, instances)
      """Shrink the specified cluster.

      :param cluster: The cluster to shrink
      :param instances: JSON describing instances to remove
      """

CLI (python-troveclient)

cluster-grow

基本扩展

基本扩展适用于 Galera 或 Cassandra 等所有节点实际上都是对等体的数据库 - 不需要特殊选项。

$ trove cluster-grow mycluster --instance flavor=7
<example output to follow>

--instance parameter may be specified multiple times.

生成的请求

POST /v1.0/<tenant_id>/clusters/<cluster-id>/action
{
    "grow": [
      {
        "flavorRef": "7",
      }
    ]
}
添加主节点和从节点

主节点和从节点扩展适用于 Redis 等支持集群内主/从复制的数据库。

$ trove cluster-grow mycluster \
  --instance name=newnode1,type=master,flavor=7 \
  --instance name=newnode2,type=slave,related_to=newnode1,flavor=7

生成的请求

POST /v1.0/<tenant_id>/clusters/<cluster-id>/action
{
    "grow": [
      {
        "name": "newnode1",
        "instance_type": "master",
        "flavorRef": "7"
      },
      {
        "name": "newnode2",
        "instance_type": "slave",
        "related_to": "newnode1",
        "flavorRef": "7 "
      }
    ]
}

要向 Vertica 或 Redis 等数据库中的名为“node1”的节点添加待机节点,可以使用上述更简单的形式。

$ trove cluster-grow mycluster \
  --instance type=standby,related_to=node1,flavor=7

生成的请求

POST /v1.0/<tenant_id>/clusters/<cluster-id>/action
{
    "grow": [
      {
        "instance_type": "standby",
        "related_to": "node1",
        "flavorRef": "7 "
      }
    ]
}
添加副本集

这种形式的 Grow Cluster 将用于 MongoDB 等通过分片(在本例中称为“副本集”)实现增长的数据库。下面的示例创建一个新的查询服务器,以及两个包含 3 个节点的副本集。

$ trove cluster-grow mycluster \
  --instance name=rs2q,type=query,flavor=7 \
  --instance name=rs2a,type=replica,flavor=7 \
  --instance name=rs2b,type=replica,related_to=rs2a,flavor=7 \
  --instance name=rs2c,type=replica,related_to=rs2b
  --instance name=rs3a,type=replica,flavor=7 \
  --instance name=rs3b,type=replica,related_to=rs3a,flavor=7 \
  --instance name=rs3c,type=replica,related_to=rs3b

生成的请求

POST /v1.0/<tenant_id>/clusters/<cluster-id>/action
{
    "grow": [
      {
        "name": "rs2q",
        "instance_type": "query",
        "flavorRef": "7"
      },
      {
        "name": "rs2a",
        "instance_type": "replica",
        "flavorRef": "7"
      },
      {
        "name": "rs2b",
        "instance_type": "replica",
        "related_to": "rs2a",
        "flavorRef": "7 "
      },
      {
        "name": "rs2c",
        "instance_type": "replica",
        "related_to": "rs2b",
        "flavorRef": "7 "
      },
      {
        "name": "rs3a",
        "instance_type": "replica",
        "flavorRef": "7"
      },
      {
        "name": "rs3b",
        "instance_type": "replica",
        "related_to": "rs3a",
        "flavorRef": "7 "
      },
      {
        "name": "rs3c",
        "instance_type": "replica",
        "related_to": "rs3b",
        "flavorRef": "7 "
      }
    ]
}

cluster-shrink

$ trove cluster-shrink mycluster nodename-1 nodename-2
<example output to follow>

内部 API

将向基础 Cluster Strategy 添加适当的方法。

Guest Agent

将向基础 Cluster Strategy 添加适当的方法。

MongoDB 实现将适应以支持现有的 add-shard 功能,以及新的 cluster-grow 功能。

备选方案

n/a

实现

负责人

主要负责人

Matthew Van Dijk Morgan Jones

里程碑

完成目标里程碑

Liberty-3

工作项

  • 实现基础 cluster-shrink/cluster-grow 功能

  • 更新 MongoDB 集群实现以使用新的 API

升级影响

MongoDB 集群实现将继续支持现有的“add-shard”功能。

依赖项

n/a

测试

集群功能的 int-tests 仍在考虑中。

文档影响

新的 cluster-grow 和 cluster-shrink 功能需要进行文档记录。

MongoDB 数据存储文档需要更新,以反映 Mongo 对旧功能和新功能的实现。

参考资料

n/a