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

Simple Log Service:シャードの結合

最終更新日:Dec 05, 2024

MergeShard APIを呼び出して、シャードを結合します。

前提条件

パラメータ説明

def merge_shard(self, project_name, logstore_name, shardId):

リクエストパラメーター

パラメーター

必須 / 任意

説明

project_name

String

プロジェクトの名前。

ali-test-project

logstore_name

String

ログストアの名前。

test-logstore

shardId

int

シャードの ID です。

重要

シャードをマージする場合、ステータスがreadwriteの2つの隣接するシャードが必要です。 shardIdパラメーターは、これら2つの隣接するシャードの最初のIDである必要があります。 マージ後、両方の隣接するシャードは読み取り専用になり、新しいマージされたシャードのハッシュ範囲は元の隣接するシャードの和集合になります。

2

サンプルコード

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 = "xmltest"
    shardId = 2

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


if __name__ == '__main__':
    main()

レスポンスの例

サンプルコードは、Shard 2と隣接するShard 3とのマージを示しています。Shard 3は、Simple Log Serviceによって自動的に識別されます。 マージ後、元のシャードのステータスがreadwriteからreadonlyに変わります。

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

ListShardResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '668', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Wed, 30 Oct 2024 07:06:50 GMT', 'x-log-time': '1730272010', 'x-log-requestid': '6721DB0AE05BB30ACE5654AE'}
res:
 [{'shardID': 2, 'status': 'readwrite', 'inclusiveBeginKey': '00000000000000000000000000000000', 'exclusiveEndKey': '40000000000000000000000000000000', 'createTime': 1730271813},
 {'shardID': 3, 'status': 'readwrite', 'inclusiveBeginKey': '40000000000000000000000000000000', 'exclusiveEndKey': '80000000000000000000000000000000', 'createTime': 1730271813},
 {'shardID': 1, 'status': 'readwrite', 'inclusiveBeginKey': '80000000000000000000000000000000', 'exclusiveEndKey': 'ffffffffffffffffffffffffffffffff', 'createTime': 1716966695},
 {'shardID': 0, 'status': 'readonly', 'inclusiveBeginKey': '00000000000000000000000000000000', 'exclusiveEndKey': '80000000000000000000000000000000', 'createTime': 1716966695}]
 
 Process finished with exit code 0
 

マージ後のサンプル応答は次のとおりです。

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

Process finished with exit code 0

関連ドキュメント

  • コマンドラインインターフェイス (CLI) を使用してシャードを管理する方法の詳細については、以下のトピックを参照してください。

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

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

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