文档

指定大小计算分片

更新时间:

使用ComputeSplitsBySize接口可以将全表数据逻辑上划分成若干接近指定大小的分片,并返回这些分片之间的分割点以及分片所在机器的提示。一般用于计算引擎规划并发度等执行计划。

说明

API说明请参见ComputeSplitPointsBySize

前提条件

接口

    /**
     * 将全表的数据在逻辑上划分成接近指定大小的若干分片,返回这些分片之间的分割点以及分片所在机器的提示。
     * 一般用于计算引擎规划并发度等执行计划。
     * @api
     * @param [] $request 请求参数。
     * @return [] 请求返回。
     * @throws OTSClientException 当参数检查出错或服务端返回校验出错时抛出异常。
     * @throws OTSServerException 当OTS服务端返回错误时抛出异常。
     */
    public function computeSplitPointsBySize(array $request)
            

参数

请求信息

请求参数

参数

说明

table_name

数据表名称。

split_size

每个分片的近似大小。

单位为百兆(即100 MB)。

请求格式

$result = $client->ComputeSplitsBySize([
    'table_name' => '<string>', //设置数据表名称,必须设置。
    'split_size' => <integer>   //设置分片大小,必须设置。
]);     

响应信息

响应参数

参数

说明

consumed

本次操作消耗服务能力单元的值。

capacity_unit表示使用的读写单元。

  • read:读吞吐量

  • write:写吞吐量

primary_key_schema

数据表的主键定义,与创建数据表时的主键定义相同。

splits

分片之间的分割点,包括如下内容:

  • lower_bound:主键的区间最小值。

    此值可以传递给GetRange用于范围读数据。

    • 每一项的顺序是主键名、主键值PrimaryKeyValue、主键类型PrimaryKeyType。

    • PrimaryKeyType可以是INTEGER、STRING(UTF-8编码字符串)、BINARY、INF_MIN(-inf)、 INF_MAX(inf)五种,分别用PrimaryKeyTypeConst::CONST_INTEGER、PrimaryKeyTypeConst::CONST_STRING、PrimaryKeyTypeConst::CONST_BINARY、PrimaryKeyTypeConst::CONST_INF_MIN、PrimaryKeyTypeConst::CONST_INF_MAX表示。

  • upper_bound:主键的区间最大值。格式与lower_bound相同。

    此值可以传递给GetRange用于范围读数据。

  • location:分割点所在机器的提示,可以为空。

结果格式

[
    'consumed' => [
        'capacity_unit' => [
            'read' => <integer>,
            'write' => <integer>
        ]
    ],
    'primary_key_schema' => [
        ['<string>', <PrimaryKeyType>],
        ['<string>', <PrimaryKeyType>, <PrimaryKeyOption>]
    ]
    'splits' => [
        [ 
            'lower_bound' => [
                ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>],
                ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
            ],
            'upper_bound' => [
                ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>],
                ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
            ],
            'location' => '<string>'
        ],
        // ...
    ]
]           

示例

以下示例用于将全表数据在逻辑上划分成接近100 MB的若干分片。

    $result = $client->ComputeSplitsBySize([
        'table_name' => 'MyTable', 
        'split_size' => 1
    ]);
    foreach($result['splits'] as $split) {
        print_r($split['location']);    
        print_r($split['lower_bound']);    
        print_r($split['upper_bound']);    
    }