All Products
Search
Document Center

Simple Log Service:Split a shard

Last Updated:Dec 02, 2024

Call the SplitShard API to split a shard.

Prerequisites

Prerequisites

Parameter description

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

Request parameters

Parameter

Type

Required

Description

Example value

project_name

String

Yes

The name of the project.

ali-test-project

logstore_name

String

Yes

The name of the logstore.

test-logstore

shardId

int

Yes

The ID of the shard to be split. After the split, the status becomes readonly.

0

split_hash

String

Yes

The position from which the shard is split. It must be within the hash range of the shard. The empty string indicates automatic even splitting of the shard.

""

Response parameters

For more information, see SplitShard.

Sample code

from aliyun.log import LogClient
import os


def main():
    # In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
    accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
    accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')

    # Specify a Simple Log Service endpoint.
    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()

Sample response

The sample code demonstrates how Shard0 is split into two new shards, Shard2 and Shard3.

Before the split, the shard information is as follows:

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

After the split, the sample response is as follows:

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

References