全部產品
Search
文件中心

Simple Log Service:分裂Shard

更新時間:Dec 02, 2024

調用SplitShard介面分裂Shard。

前提條件

您已完成以下操作:

參數說明

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的雜湊區間內。建議填入Null 字元串,表示自動均勻分裂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', '')

    # Log Service的服務存取點
    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

相關文檔