すべてのプロダクト
Search
ドキュメントセンター

Simple Log Service:シャードを分割します。

最終更新日:Dec 05, 2024

SplitShard APIを呼び出して、シャードを分割します。

前提条件

パラメータ説明

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

リクエストパラメーター

パラメーター

必須 / 任意

説明

値の例

project_name

String

プロジェクトの名前。

ali-test-project

logstore_name

String

ログストアの名前。

test-logstore

shardId

int

分割するシャードのID。 分割後、ステータスはreadonlyになります。

0

split_hash

String

シャードが分割される位置。 シャードのハッシュ範囲内にある必要があります。 空の文字列は、シャードの自動均等分割を示します。

""

応答パラメーター

詳細については、「SplitShard」をご参照ください。

サンプルコード

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()

レスポンスの例

サンプルコードは、Shard0を2つの新しいシャードShard2とShard3に分割する方法を示しています。

分割前のシャード情報は次のとおりです。

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

分割後のサンプル応答は次のとおりです。

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) を使用してシャードを管理する方法の詳細については、以下のトピックを参照してください。

  • シャード管理APIの詳細については、以下のトピックを参照してください。

  • その他のコードサンプルについては、『aliyun-log-python-sdk on GitHub』をご参照ください。

  • Simple Log Serviceは、シャードを使用してログストアの読み取りおよび書き込み容量を管理します。 詳細は、「シャード」をご参照ください。