Split a shard
You can call the SplitShard operation to split a shard by using the Simple Log Service SDK for Python.
Prerequisites
-
Simple Log Service is activated. For more information, see Activate Simple Log Service.
-
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
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 split. After the split, the shard status changes to readonly. |
0 |
|
split_hash |
String |
Yes |
The hash position at which to split the shard. The value must be within the hash range of the shard. An empty string splits the shard evenly. |
"" |
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 following example shows how Shard 0 is split into two new shards: Shard 2 and Shard 3.
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
-
For more information about using command-line interface (CLI) to manage shards, see the following topics:
-
For more information about shard management APIs, see the following topics:
-
The aliyun-log-python-sdk on GitHub repository provides additional samples.
-
Simple Log Service uses shards to manage the read and write capacities of logstores. For more information, see Shard.