赛尔校园公共服务平台 Logo
平台使用
阿里云
百度云
移动云
智算服务
教育生态
登录 →
赛尔校园公共服务平台 Logo
平台使用 阿里云 百度云 移动云 智算服务 教育生态
登录
  1. 首页
  2. 阿里云
  3. 日志服务
  4. 开发参考
  5. 日志服务SDK
  6. Python SDK
  7. 管理Shard
  8. 分裂Shard

分裂Shard

  • 管理Shard
  • 发布于 2025-04-22
  • 0 次阅读
文档编辑
文档编辑

调用SplitShard接口分裂Shard。

前提条件

  • 已开通日志服务。

  • 已初始化日志服务Python SDK。

参数说明

def split_shard(self, project_name, logstore_name, shardId, split_hash):

请求参数

名称

类型

是否必填

描述

示例值

project_name

String

是

Project名称。

ali-test-project

logstore_name

String

是

Logstore名称。

test-logstore

shardId

int

是

要分裂的ShardId,分裂后状态将变为readonly。

0

split_hash

String

是

分裂位置。必须位于该Shard的哈希区间内。建议填入空字符串,表示自动均匀分裂Shard。

""

返回参数

返回参数说明,请参见SplitShard - 分裂Shard。

示例代码

from aliyun.log import LogClient
import os


def main():
    # 本示例从环境变量中获取AccessKey ID和AccessKey Secret
    accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
    accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')

    # 日志服务的服务接入点
    endpoint = "cn-hangzhou.log.aliyuncs.com"
    project_name = "ali-test-project"
    logstore_name = "test-logstore"
    shardId = 0
    split_hash = ""

    client = LogClient(endpoint, accessKeyId, accessKey, "")
    res = client.split_shard(project_name, logstore_name, shardId, split_hash)
    res.log_print()


if __name__ == '__main__':
    main()

示例返回结果

示例代码将Shard0分裂为另外两个Shard,分别是Shard2和Shard3。

分裂Shard之前,Shard信息如下:

ListShardResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '335', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Wed, 30 Oct 2024 06:21:26 GMT', 'x-log-time': '1730269286', 'x-log-requestid': '6721D066A5CBF5E0D241541F'}
res: [{'shardID': 0, 'status': 'readwrite', 'inclusiveBeginKey': '00000000000000000000000000000000', 'exclusiveEndKey': '80000000000000000000000000000000', 'createTime': 1716966695}, {'shardID': 1, 'status': 'readwrite', 'inclusiveBeginKey': '80000000000000000000000000000000', 'exclusiveEndKey': 'ffffffffffffffffffffffffffffffff', 'createTime': 1716966695}]

Process finished with exit code 0

分裂Shard之后,示例代码返回结果如下:

ListShardResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '501', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Wed, 30 Oct 2024 07:03:33 GMT', 'x-log-time': '1730271813', 'x-log-requestid': '6721DA451538A95623658BBF'}
res: [{'shardID': 0, 'status': 'readonly', 'inclusiveBeginKey': '00000000000000000000000000000000', 'exclusiveEndKey': '80000000000000000000000000000000', 'createTime': 1716966695}, {'shardID': 2, 'status': 'readwrite', 'inclusiveBeginKey': '00000000000000000000000000000000', 'exclusiveEndKey': '40000000000000000000000000000000', 'createTime': 1730271813}, {'shardID': 3, 'status': 'readwrite', 'inclusiveBeginKey': '40000000000000000000000000000000', 'exclusiveEndKey': '80000000000000000000000000000000', 'createTime': 1730271813}]

Process finished with exit code 0

相关文档

  • 调用CLI命令管理Shard请参见:

    • list_shards

    • merge_shard

    • split_shard

  • 管理Shard的API请参见:

    • ListShards - 查询shard列表

    • MergeShard - 合并shard

    • SplitShard - 分裂Shard

  • 更多示例代码,请参见Aliyun Log Python SDK on GitHub。

  • 日志服务使用Shard控制Logstore读写数据的能力。详细信息,请参见分区(Shard)。

相关文章

查询Shard列表 2025-04-22 10:34

调用ListShards接口查询Logstore的Shard列表。 前提条件 已

分裂Shard 2025-04-22 10:34

调用SplitShard接口分裂Shard。 前提条件 已

合并Shard 2025-04-22 10:34

调用MergeShard接口合并Shard。 前提条件 已

目录
Copyright © 2025 your company All Rights Reserved. Powered by 赛尔网络.
京ICP备14022346号-15
gongan beian 京公网安备11010802041014号