OSS Tables には、圧縮、スナップショット管理、未参照ファイルのクリーンアップという 3 つの最適化タスクを実行する自動メンテナンス機能が含まれています。この機能により、外部の計算リソースを必要とせずに、テーブルクエリのパフォーマンスを継続的に最適化し、ストレージコストを削減できます。
自動メンテナンス機能は、以下の 3 つの最適化タスクを異なるリソースレベルで実行します。
未参照ファイルのクリーンアップ:バケットレベルで設定されます。テーブルスナップショットから参照されていないオブジェクトを自動的に特定して削除します。
コンパクション:テーブルレベルで設定されます。小規模なファイルを大規模なファイルにマージして、クエリパフォーマンスを向上させます。
スナップショット管理:テーブルレベルで設定されます。期限切れのスナップショットを自動的にクリーンアップして、メタデータファイルおよびストレージのオーバーヘッドを削減します。
バケットおよびテーブル作成時に、システムは以下のデフォルトメンテナンス構成を自動的に適用します。
メンテナンス機能 | 構成レベル | パラメーター | デフォルト |
未参照ファイルのクリーンアップ | バケットレベル | status | enabled |
unreferencedDays | 3 | ||
nonCurrentDays | 10 | ||
コンパクション | テーブルレベル | status | enabled |
targetFileSizeMB | 512 | ||
strategy | auto | ||
スナップショット管理 | テーブルレベル | status | enabled |
maxSnapshotAgeHours | 120 | ||
minSnapshotsToKeep | 1 |
サービスリンクロール
OSS Tables のバックグラウンドサービスが、コンパクション、未参照ファイルのクリーンアップ、スナップショット管理を含む自動メンテナンスを実行します。このサービスは、Table Bucket へのアクセスに AliyunServiceRoleForOssTableMaintenance というサービスリンクロールを使用します。サービスリンクロールの詳細については、「サービスリンクロール」をご参照ください。
認可
OSS コンソールで初めて Table Bucket リスト ページにアクセスした際に、ご利用のアカウントにサービスリンクロールがまだ作成されていない場合は、ページ上部に通知が表示されます:Missing permissions: AliyunServiceRoleForOssTableMaintenance。通知内の [今すぐ作成] をクリックして、ロールを作成してください。ロールが作成されると、OSS Tables のバックグラウンドメンテナンスサービスが自動的に開始されます。
RAM ユーザーとしてこの操作を実行する場合は、RAM ユーザーにサービスリンクロールを作成するための必要な権限があることを確認してください。Alibaba Cloud アカウントは、以下の権限ポリシーを RAM ユーザーにアタッチできます。
{
"Version": "1",
"Statement": [
{
"Action": "ram:CreateServiceLinkedRole",
"Resource": "*",
"Effect": "Allow",
"Condition": {
"StringEquals": {
"ram:ServiceName": "tablemaintenance.oss.aliyuncs.com"
}
}
}
]
}権限
このサービスリンクロール (AliyunServiceRolePolicyForOssTableMaintenance) の権限ポリシーには、テーブル構成の読み取り、データメンテナンスの実行、メタデータの更新を行うための以下の権限が含まれます。
アクション | 説明 |
oss:GetTableBucketMaintenanceConfiguration | バケットレベルのメンテナンス構成を読み取る |
oss:GetTableMaintenanceConfiguration | テーブルレベルのメンテナンス構成を読み取る |
oss:ListTableBuckets | Table Bucket の一覧を取得する |
oss:GetTableBucket | Table Bucket 情報を取得する |
oss:ListTables | テーブルの一覧を取得する |
oss:GetTable | テーブル情報を取得する |
oss:GetTableData | テーブルデータファイルを読み取る (コンパクションおよびクリーンアップを実行するため) |
oss:PutTableData | テーブルデータファイルを書き込む (コンパクション後に新しいファイルを生成するため) |
oss:GetTableMetadataLocation | メタデータファイルの場所を取得する |
oss:UpdateTableMetadataLocation | メタデータファイルの場所を更新する (メンテナンス後の変更をコミットするため) |
未参照ファイルのクリーンアップ
未参照ファイルのクリーンアップ機能は、Table Bucket 内のすべてのテーブルに適用される バケットレベル の最適化です。この機能は、テーブルスナップショットから参照されていないすべてのオブジェクトを特定して削除します。データの書き込み、更新、または削除操作中に、書き込みジョブの失敗やスナップショットの期限切れなどのイベントにより、Parquet、Avro、ORC ファイルなどのデータファイルがメタデータから参照されなくなることがあります。これらの孤立したファイルは、ストレージスペースを継続的に消費します。
未参照ファイルのクリーンアップが有効になっている場合、テーブルの一部ではない Table Bucket に追加された Parquet、Avro、ORC ファイルも削除されます。
未参照ファイルのクリーンアップ機能は 2 段階のプロセスを使用します。まず、参照されなくなったファイルを non-current 状態にマークし (unreferencedDays で制御)、その後、指定された日数 non-current 状態が継続した後に削除します (nonCurrentDays で制御)。
以下の表は、未参照ファイルのクリーンアップの構成パラメーターについて説明しています。
パラメーター | 説明 | 値 | デフォルト |
status | 未参照ファイルのクリーンアップを有効にするかどうかを指定します。 | enabled または disabled。 | enabled |
unreferencedDays | メタデータから参照されなくなってからファイルを non-current としてマークするまでの待機日数。 | 1~2147483647。 | 3 |
nonCurrentDays | non-current としてマークされてからファイルを削除するまでの待機日数。 | 1~2147483647。 | 10 |
コンソール
OSS コンソールで Table Bucket の自動メンテナンス構成を表示および変更できます。
以下の手順に従ってください。
OSS コンソール にログインします。左側のナビゲーションウィンドウで、[Table Bucket リスト] を選択します。
対象の Table Bucket 名をクリックして、詳細ページを開きます。
[データメンテナンス] タブを選択します。
[未参照ファイルのクリーンアップ] セクションで、現在の構成を確認します。
ステータス:機能が有効かどうかを表示します。
未参照日数:メタデータから参照されなくなってからファイルを non-current としてマークするまでの待機日数。デフォルト値は 3 日です。
Non-current 日数:non-current としてマークされてからファイルを削除するまでの待機日数。デフォルト値は 10 日です。
[編集] をクリックして、未参照ファイルのクリーンアップのパラメーターを変更し、[保存] をクリックします。
ossutil
ossutil を使用して、未参照ファイルのクリーンアップ構成を変更します。
ossutil tables-api put-table-bucket-maintenance-configuration \
--table-bucket-arn {ARN} \
--type icebergUnreferencedFileRemoval \
--value '{"status":"enabled","settings":{"icebergUnreferencedFileRemoval":{"unreferencedDays":5,"nonCurrentDays":15}}}'SDK
以下のコードは、SDK を使用して Table Bucket の未参照ファイルのクリーンアップ構成を照会および変更する方法を示しています。
Python
未参照ファイルのクリーンアップ構成を照会します。
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.tables as oss_tables
parser = argparse.ArgumentParser(description="get table bucket maintenance configuration sample")
parser.add_argument('--region', help='The region in which the table bucket is located.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS Tables.')
parser.add_argument('--table-bucket-arn', help='The ARN of the table bucket.', required=True)
def main():
args = parser.parse_args()
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_tables.Client(cfg)
result = client.get_table_bucket_maintenance_configuration(
oss_tables.models.GetTableBucketMaintenanceConfigurationRequest(
table_bucket_arn=args.table_bucket_arn,
)
)
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
f' table bucket arn: {result.table_bucket_arn},'
f' configuration: {result.configuration}')
if __name__ == "__main__":
main()未参照ファイルのクリーンアップ構成を変更します。
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.tables as oss_tables
parser = argparse.ArgumentParser(description="put table bucket maintenance configuration sample")
parser.add_argument('--region', help='The region in which the table bucket is located.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS Tables.')
parser.add_argument('--table-bucket-arn', help='The ARN of the table bucket.', required=True)
parser.add_argument('--type', help='The maintenance type, e.g., icebergUnreferencedFileRemoval.', required=True)
def main():
args = parser.parse_args()
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_tables.Client(cfg)
value = {
'status': 'enabled',
'settings': {
'icebergUnreferencedFileRemoval': {
'unreferencedDays': 7,
'nonCurrentDays': 30
}
}
}
result = client.put_table_bucket_maintenance_configuration(
oss_tables.models.PutTableBucketMaintenanceConfigurationRequest(
table_bucket_arn=args.table_bucket_arn,
type=args.type,
value=value,
)
)
print(f'status code: {result.status_code},'
f' request id: {result.request_id}')
print(f'successfully updated maintenance configuration for: {args.table_bucket_arn}')
if __name__ == "__main__":
main()Go
未参照ファイルのクリーンアップ構成を照会します。
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/tables"
)
var (
region string
tableBucketArn string
)
func init() {
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
flag.StringVar(&tableBucketArn, "table-bucket-arn", "", "The arn of the table bucket.")
}
func main() {
flag.Parse()
if len(tableBucketArn) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table bucket arn required")
}
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := tables.NewTablesClient(cfg)
result, err := client.GetTableBucketMaintenanceConfiguration(context.TODO(), &tables.GetTableBucketMaintenanceConfigurationRequest{
TableBucketARN: oss.Ptr(tableBucketArn),
})
if err != nil {
log.Fatalf("failed to get table bucket maintenance configuration %v", err)
}
log.Printf("get table bucket maintenance configuration result:%#v\n", result)
}未参照ファイルのクリーンアップ構成を変更します。
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/tables"
)
var (
region string
tableBucketArn string
)
func init() {
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
flag.StringVar(&tableBucketArn, "table-bucket-arn", "", "The arn of the table bucket.")
}
func main() {
flag.Parse()
if len(tableBucketArn) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table bucket arn required")
}
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := tables.NewTablesClient(cfg)
result, err := client.PutTableBucketMaintenanceConfiguration(context.TODO(), &tables.PutTableBucketMaintenanceConfigurationRequest{
TableBucketARN: oss.Ptr(tableBucketArn),
Type: oss.Ptr("icebergUnreferencedFileRemoval"),
Value: &tables.MaintenanceValue{
Settings: &tables.MaintenanceSettings{
IcebergUnreferencedFileRemoval: &tables.SettingsDetail{
UnreferencedDays: oss.Ptr(4),
NonCurrentDays: oss.Ptr(10),
},
},
Status: oss.Ptr("enabled"),
},
})
if err != nil {
log.Fatalf("failed to put table bucket maintenance configuration %v", err)
}
log.Printf("put table bucket maintenance configuration result:%#v\n", result)
}Java
未参照ファイルのクリーンアップ構成を照会します。
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.tables.OSSTablesClient;
import com.aliyun.sdk.service.oss2.tables.models.*;
public class GetTableBucketMaintenanceConfigurationSample {
public static void main(String[] args) throws Exception {
String region = "cn-hangzhou";
String tableBucketARN = "acs:osstables:cn-hangzhou:1234567890:bucket/mytable-bucket";
try (OSSTablesClient client = OSSTablesClient.newBuilder()
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.region(region)
.build()) {
GetTableBucketMaintenanceConfigurationRequest request = GetTableBucketMaintenanceConfigurationRequest.newBuilder()
.tableBucketARN(tableBucketARN)
.build();
GetTableBucketMaintenanceConfigurationResult result = client.getTableBucketMaintenanceConfiguration(request);
System.out.printf("Status code:%d, request id:%s%n",
result.statusCode(), result.requestId());
System.out.printf("Successfully got maintenance configuration for table bucket: %s%n", tableBucketARN);
System.out.printf("Table Bucket ARN: %s%n", result.tableBucketARN());
result.configuration().forEach((key, value) -> {
System.out.printf("Configuration Type: %s, Status: %s%n", key, value.status());
});
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}未参照ファイルのクリーンアップ構成を変更します。
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.tables.OSSTablesClient;
import com.aliyun.sdk.service.oss2.tables.models.*;
public class PutTableBucketMaintenanceConfigurationSample {
public static void main(String[] args) throws Exception {
String region = "cn-hangzhou";
String tableBucketARN = "acs:osstables:cn-hangzhou:1234567890:bucket/mytable-bucket";
String type = "icebergUnreferencedFileRemoval";
String status = "enabled";
int unreferencedDays = 3;
int nonCurrentDays = 3;
IcebergUnreferencedFileRemovalSettings removalSettings = IcebergUnreferencedFileRemovalSettings.newBuilder()
.unreferencedDays(unreferencedDays)
.nonCurrentDays(nonCurrentDays)
.build();
TableBucketMaintenanceSettings settings = TableBucketMaintenanceSettings.newBuilder()
.icebergUnreferencedFileRemoval(removalSettings)
.build();
TableBucketMaintenanceConfigurationValue value = TableBucketMaintenanceConfigurationValue.newBuilder()
.status(status)
.settings(settings)
.build();
try (OSSTablesClient client = OSSTablesClient.newBuilder()
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.region(region)
.build()) {
PutTableBucketMaintenanceConfigurationRequest request = PutTableBucketMaintenanceConfigurationRequest.newBuilder()
.tableBucketARN(tableBucketARN)
.type(type)
.value(value)
.build();
PutTableBucketMaintenanceConfigurationResult result = client.putTableBucketMaintenanceConfiguration(request);
System.out.printf("Status code:%d, request id:%s%n",
result.statusCode(), result.requestId());
System.out.printf("Successfully configured maintenance for table bucket: %s%n", tableBucketARN);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}API
以下の API オペレーションを使用します。
コンパクション
コンパクションは テーブルレベル の最適化です。Apache Iceberg テーブルでは、頻繁なストリーミング書き込みや小規模バッチ書き込みにより、多数の小規模ファイルが生成されることがあります。多数の小規模ファイルを持つテーブルをクエリすると、クエリエンジンが多数のファイルを開いてスキャンする必要があるため、パフォーマンスが低下する可能性があります。コンパクションは、複数の小規模ファイルを、ターゲットサイズに近い大規模ファイルに統合します。このプロセスにより、ファイル数が削減され、クエリパフォーマンスが向上し、メタデータのオーバーヘッドが低減されます。
以下の表は、コンパクションの構成パラメーターについて説明しています。
パラメーター | 説明 | 値 | デフォルト |
status | 自動コンパクションを有効にするかどうかを指定します。 | enabled または disabled | enabled |
targetFileSizeMB | コンパクション後のファイルのターゲットサイズ (MB 単位)。この値より小さいファイルをマージして、このサイズに近い新しいファイルを生成します。 | 1~2147483647。 | 512 |
strategy | コンパクション戦略。異なる戦略により、ファイルのマージおよびソート方法が決定されます。 | auto、binpack、sort、または z-order。このパラメーターを sort または z-order に設定する場合は、テーブルのメタデータにソート順序を定義する必要があります。 | auto |
利用可能なコンパクション戦略は以下のとおりです。
auto:システムが最適なコンパクション戦略を自動的に選択します。ソート順序が定義されているテーブルには sort 戦略を、定義されていないテーブルには binpack 戦略を適用します。
binpack:データの順序を変更せずに、ファイルサイズに基づいてのみファイルをマージします。これは最も高速な戦略であり、データのソートが不要な場合に適しています。
sort:テーブルに定義されたソート順序に基づいてデータをソートおよびマージします。この戦略は範囲クエリシナリオに適しています。テーブルのメタデータにソート順序を定義する必要があります。
z-order:Z-Order 曲線を使用して、複数の列にわたって同時にデータをソートおよびマージします。この戦略は多次元クエリシナリオに適しています。テーブルのメタデータにソート順序を定義する必要があります。
以下のいずれかの方法で、コンパクションを表示および構成できます。
コンソール
テーブルの [データメンテナンス] タブで、コンパクション構成を表示および変更します。
OSS コンソール にログインします。左側のナビゲーションウィンドウで、[Table Bucket リスト] を選択します。
対象の Table Bucket 名をクリックします。[テーブルリスト] で、対象のテーブル名をクリックして、テーブル詳細ページを開きます。
[データメンテナンス] タブを選択します。
[コンパクション] セクションで、現在の構成を確認します。
ステータス:自動コンパクションが有効かどうかを示します。
ターゲットファイルサイズ:コンパクション後の各ファイルのターゲットサイズ。デフォルト値は 512 MB です。
コンパクション戦略:使用中のコンパクション戦略。デフォルト値は auto です。
ジョブステータス:前回のコンパクションジョブの実行ステータスおよび時刻。
[編集] をクリックして、コンパクションパラメーターを変更し、[保存] をクリックします。
ossutil
ossutil を使用して、コンパクション構成を変更します。
ossutil tables-api put-table-maintenance-configuration \
--table-bucket-arn {ARN} \
--namespace mynamespace \
--name mytable \
--type icebergCompaction \
--value '{"status":"enabled","settings":{"icebergCompaction":{"targetFileSizeMB":256,"strategy":"binpack"}}}'SDK
以下のコードサンプルは、SDK を使用してテーブルのコンパクション構成を照会および変更する方法を示しています。
Python
コンパクション構成を照会します。
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.tables as oss_tables
parser = argparse.ArgumentParser(description="get table maintenance configuration sample")
parser.add_argument('--region', help='The region in which the table bucket is located.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS Tables.')
parser.add_argument('--table-bucket-arn', help='The ARN of the table bucket.', required=True)
parser.add_argument('--namespace', help='The namespace of the table.', required=True)
parser.add_argument('--name', help='The name of the table.', required=True)
def main():
args = parser.parse_args()
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_tables.Client(cfg)
result = client.get_table_maintenance_configuration(
oss_tables.models.GetTableMaintenanceConfigurationRequest(
table_bucket_arn=args.table_bucket_arn,
namespace=args.namespace,
name=args.name,
)
)
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
f' table arn: {result.table_arn},'
f' configuration: {result.configuration}')
if __name__ == "__main__":
main()コンパクション構成を変更します。
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.tables as oss_tables
parser = argparse.ArgumentParser(description="put table maintenance configuration sample")
parser.add_argument('--region', help='The region in which the table bucket is located.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS Tables.')
parser.add_argument('--table-bucket-arn', help='The ARN of the table bucket.', required=True)
parser.add_argument('--namespace', help='The namespace of the table.', required=True)
parser.add_argument('--name', help='The name of the table.', required=True)
parser.add_argument('--type', help='The maintenance type, e.g., icebergCompaction.', required=True)
def main():
args = parser.parse_args()
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_tables.Client(cfg)
value = {
'status': 'enabled',
'settings': {
'icebergCompaction': {
'targetFileSizeMB': 512,
'strategy': 'auto'
}
}
}
result = client.put_table_maintenance_configuration(
oss_tables.models.PutTableMaintenanceConfigurationRequest(
table_bucket_arn=args.table_bucket_arn,
namespace=args.namespace,
name=args.name,
type=args.type,
value=value,
)
)
print(f'status code: {result.status_code},'
f' request id: {result.request_id}')
print(f'successfully updated maintenance configuration for: {args.namespace}/{args.name}')
if __name__ == "__main__":
main()Go
コンパクション構成を照会します。
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/tables"
)
var (
region string
tableBucketArn string
namespace string
name string
)
func init() {
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
flag.StringVar(&tableBucketArn, "table-bucket-arn", "", "The arn of the table bucket.")
flag.StringVar(&namespace, "namespace", "", "The name of the namespace.")
flag.StringVar(&name, "name", "", "The name of the table.")
}
func main() {
flag.Parse()
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
if len(tableBucketArn) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table bucket arn required")
}
if len(namespace) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, namespace name required")
}
if len(name) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table name required")
}
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := tables.NewTablesClient(cfg)
result, err := client.GetTableMaintenanceConfiguration(context.TODO(), &tables.GetTableMaintenanceConfigurationRequest{
TableBucketARN: oss.Ptr(tableBucketArn),
Namespace: oss.Ptr(namespace),
Name: oss.Ptr(name),
})
if err != nil {
log.Fatalf("failed to get table maintenance configuration %v", err)
}
log.Printf("get table maintenance configuration result:%#v\n", result)
}コンパクション構成を変更します。
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/tables"
)
var (
region string
tableBucketArn string
namespace string
name string
)
func init() {
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
flag.StringVar(&tableBucketArn, "table-bucket-arn", "", "The arn of the table bucket.")
flag.StringVar(&namespace, "namespace", "", "The name of the namespace.")
flag.StringVar(&name, "name", "", "The name of the table.")
}
func main() {
flag.Parse()
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
if len(tableBucketArn) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table bucket arn required")
}
if len(namespace) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, namespace name required")
}
if len(name) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table name required")
}
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := tables.NewTablesClient(cfg)
// icebergCompaction type
result, err := client.PutTableMaintenanceConfiguration(context.TODO(), &tables.PutTableMaintenanceConfigurationRequest{
TableBucketARN: oss.Ptr(tableBucketArn),
Namespace: oss.Ptr(namespace),
Name: oss.Ptr(name),
Type: oss.Ptr("icebergCompaction"),
Value: &tables.TableMaintenanceValue{
Status: oss.Ptr("enabled"),
Settings: &tables.TableMaintenanceSettings{
IcebergCompaction: &tables.IcebergCompactionSettingsDetail{
TargetFileSizeMB: oss.Ptr(400),
Strategy: oss.Ptr("auto"),
},
},
},
})
// icebergSnapshotManagement type
//result, err := client.PutTableMaintenanceConfiguration(context.TODO(), &tables.PutTableMaintenanceConfigurationRequest{
// TableBucketARN: oss.Ptr(tableBucketArn),
// Namespace: oss.Ptr(namespace),
// Name: oss.Ptr(name),
// Type: oss.Ptr("icebergSnapshotManagement"),
// Value: &tables.TableMaintenanceValue{
// Status: oss.Ptr("enabled"),
// Settings: &tables.TableMaintenanceSettings{
// IcebergSnapshotManagement: &tables.IcebergSnapshotManagementSettingsDetail{
// MaxSnapshotAgeHours: oss.Ptr(350),
// MinSnapshotsToKeep: oss.Ptr(1),
// },
// },
// },
//})
if err != nil {
log.Fatalf("failed to put table maintenance configuration %v", err)
}
log.Printf("put table maintenance configuration result:%#v\n", result)
}Java
コンパクション構成を照会します。
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.tables.OSSTablesClient;
import com.aliyun.sdk.service.oss2.tables.models.*;
public class GetTableMaintenanceConfigurationSample {
public static void main(String[] args) throws Exception {
String region = "cn-hangzhou";
String tableBucketARN = "acs:osstables:cn-hangzhou:1234567890:bucket/mytable-bucket";
String namespace = "mynamespace";
String name = "mytable";
try (OSSTablesClient client = OSSTablesClient.newBuilder()
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.region(region)
.build()) {
GetTableMaintenanceConfigurationRequest request = GetTableMaintenanceConfigurationRequest.newBuilder()
.tableBucketARN(tableBucketARN)
.namespace(namespace)
.name(name)
.build();
GetTableMaintenanceConfigurationResult result = client.getTableMaintenanceConfiguration(request);
System.out.printf("Status code:%d, request id:%s%n",
result.statusCode(), result.requestId());
System.out.printf("Table ARN: %s%n", result.tableARN());
if (result.configuration() != null && !result.configuration().isEmpty()) {
System.out.println("Maintenance configurations:");
result.configuration().forEach((type, config) -> {
System.out.printf(" Type: %s, Status: %s%n", type, config.status());
if (config.settings() != null) {
if (config.settings().icebergCompaction() != null) {
System.out.printf(" Compaction - TargetFileSizeMB: %d, Strategy: %s%n",
config.settings().icebergCompaction().targetFileSizeMB(),
config.settings().icebergCompaction().strategy());
}
if (config.settings().icebergSnapshotManagement() != null) {
System.out.printf(" SnapshotManagement - MinSnapshotsToKeep: %d, MaxSnapshotAgeHours: %d%n",
config.settings().icebergSnapshotManagement().minSnapshotsToKeep(),
config.settings().icebergSnapshotManagement().maxSnapshotAgeHours());
}
}
});
} else {
System.out.println("No maintenance configuration found.");
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}コンパクション構成を変更します。
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.tables.OSSTablesClient;
import com.aliyun.sdk.service.oss2.tables.models.*;
public class PutTableMaintenanceConfigurationSample {
public static void main(String[] args) throws Exception {
String region = "cn-hangzhou";
String tableBucketARN = "acs:osstables:cn-hangzhou:1234567890:bucket/mytable-bucket";
String namespace = "mynamespace";
String name = "mytable";
String type = "icebergCompaction";
String status = "enabled";
int targetFileSizeMB = 256;
String strategy = "auto";
try (OSSTablesClient client = OSSTablesClient.newBuilder()
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.region(region)
.build()) {
IcebergCompactionSettings compactionSettings = IcebergCompactionSettings.newBuilder()
.targetFileSizeMB(targetFileSizeMB)
.strategy(strategy)
.build();
TableMaintenanceSettings settings = TableMaintenanceSettings.newBuilder()
.icebergCompaction(compactionSettings)
.build();
TableMaintenanceConfigurationValue value = TableMaintenanceConfigurationValue.newBuilder()
.status(status)
.settings(settings)
.build();
PutTableMaintenanceConfigurationRequest request = PutTableMaintenanceConfigurationRequest.newBuilder()
.tableBucketARN(tableBucketARN)
.namespace(namespace)
.name(name)
.type(type)
.value(value)
.build();
PutTableMaintenanceConfigurationResult result = client.putTableMaintenanceConfiguration(request);
System.out.printf("Status code:%d, request id:%s%n",
result.statusCode(), result.requestId());
System.out.printf("Successfully put table maintenance configuration for table: %s/%s, type: %s%n", namespace, name, type);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}API
コンパクション構成を管理するには、以下の API オペレーションを使用します。
スナップショット管理
スナップショット管理は テーブルレベル の最適化です。Apache Iceberg では、各書き込み操作により、特定の時点でのデータ状態を記録する新しいスナップショットが作成されます。書き込み回数が増えるにつれて、過剰な数のスナップショットが大量のストレージスペースを消費し、メタデータ操作のオーバーヘッドを増加させる可能性があります。スナップショット管理は、データの安全性を確保しながら、期限切れのスナップショットを自動的にクリーンアップしてストレージコストを削減します。
スナップショット管理は、データの安全性を最優先する原則に従います。minSnapshotsToKeep および maxSnapshotAgeHours の条件が競合する場合、システムは最小スナップショット数の保持を優先します。これにより、スナップショットのクリーンアップが重要なデータ復旧機能を損なわないようにします。
以下の表は、スナップショット管理の構成パラメーターについて説明しています。
パラメーター | 説明 | 値 | デフォルト |
status | スナップショット管理を有効にするかどうかを指定します。 | enabled または disabled。 | enabled |
maxSnapshotAgeHours | スナップショットの最大保存期間 (時間単位)。この期間を超えたスナップショットはクリーンアップされます。 | 1~2147483647。 | 120 |
minSnapshotsToKeep | 保持するスナップショットの最小数。この数の最新スナップショットは、最大保存期間を超えていても保持されます。 | 1~2147483647。 | 1 |
スナップショット管理を表示および構成するには、以下のいずれかの方法を使用します。
コンソール
テーブルの [データメンテナンス] タブで、スナップショット管理構成を表示および変更します。
OSS 管理コンソール にログインします。左側のナビゲーションウィンドウで、[Table Bucket リスト] を選択します。
対象の Table Bucket 名をクリックします。[テーブルリスト] で、対象のテーブル名をクリックします。
[データメンテナンス] タブを選択します。
[スナップショット管理] セクションで、現在の構成を確認します。
ステータス:機能が有効かどうかを表示します。
スナップショットの最大保存期間:スナップショットの最大保存期間。デフォルトは 120 時間です。
保持するスナップショットの最小数:保持するスナップショットの最小数。デフォルトは 1 です。
ジョブステータス:最新のスナップショットクリーンアップジョブのステータスおよび時刻を表示します。
[編集] をクリックして、スナップショット管理パラメーターを変更し、[保存] をクリックします。
ossutil
ossutil を使用して、スナップショット管理構成を変更します。
ossutil tables-api put-table-maintenance-configuration \
--table-bucket-arn {ARN} \
--namespace mynamespace \
--name mytable \
--type icebergSnapshotManagement \
--value '{"status":"enabled","settings":{"icebergSnapshotManagement":{"maxSnapshotAgeHours":72,"minSnapshotsToKeep":3}}}'SDK
以下のコード例は、SDK を使用してテーブルのスナップショット管理構成を照会および変更する方法を示しています。スナップショット管理とコンパクションは、同じテーブルレベルのメンテナンス API オペレーション (GetTableMaintenanceConfiguration および PutTableMaintenanceConfiguration) を使用します。
Python
スナップショット管理構成を照会します。
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.tables as oss_tables
parser = argparse.ArgumentParser(description="get table maintenance configuration sample")
parser.add_argument('--region', help='The region in which the table bucket is located.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS Tables.')
parser.add_argument('--table-bucket-arn', help='The ARN of the table bucket.', required=True)
parser.add_argument('--namespace', help='The namespace of the table.', required=True)
parser.add_argument('--name', help='The name of the table.', required=True)
def main():
args = parser.parse_args()
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_tables.Client(cfg)
result = client.get_table_maintenance_configuration(
oss_tables.models.GetTableMaintenanceConfigurationRequest(
table_bucket_arn=args.table_bucket_arn,
namespace=args.namespace,
name=args.name,
)
)
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
f' table arn: {result.table_arn},'
f' configuration: {result.configuration}')
if __name__ == "__main__":
main()スナップショット管理構成を変更します。
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.tables as oss_tables
parser = argparse.ArgumentParser(description="put table maintenance configuration sample")
parser.add_argument('--region', help='The region in which the table bucket is located.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS Tables.')
parser.add_argument('--table-bucket-arn', help='The ARN of the table bucket.', required=True)
parser.add_argument('--namespace', help='The namespace of the table.', required=True)
parser.add_argument('--name', help='The name of the table.', required=True)
parser.add_argument('--type', help='The maintenance type, e.g., icebergSnapshotManagement.', required=True)
def main():
args = parser.parse_args()
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_tables.Client(cfg)
value = {
'status': 'enabled',
'settings': {
'icebergSnapshotManagement': {
'maxSnapshotAgeHours': 72,
'minSnapshotsToKeep': 3
}
}
}
result = client.put_table_maintenance_configuration(
oss_tables.models.PutTableMaintenanceConfigurationRequest(
table_bucket_arn=args.table_bucket_arn,
namespace=args.namespace,
name=args.name,
type=args.type,
value=value,
)
)
print(f'status code: {result.status_code},'
f' request id: {result.request_id}')
print(f'successfully updated maintenance configuration for: {args.namespace}/{args.name}')
if __name__ == "__main__":
main()Go
スナップショット管理構成を照会します。
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/tables"
)
var (
region string
tableBucketArn string
namespace string
name string
)
func init() {
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
flag.StringVar(&tableBucketArn, "table-bucket-arn", "", "The arn of the table bucket.")
flag.StringVar(&namespace, "namespace", "", "The name of the namespace.")
flag.StringVar(&name, "name", "", "The name of the table.")
}
func main() {
flag.Parse()
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
if len(tableBucketArn) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table bucket arn required")
}
if len(namespace) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, namespace name required")
}
if len(name) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table name required")
}
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := tables.NewTablesClient(cfg)
result, err := client.GetTableMaintenanceConfiguration(context.TODO(), &tables.GetTableMaintenanceConfigurationRequest{
TableBucketARN: oss.Ptr(tableBucketArn),
Namespace: oss.Ptr(namespace),
Name: oss.Ptr(name),
})
if err != nil {
log.Fatalf("failed to get table maintenance configuration %v", err)
}
log.Printf("get table maintenance configuration result:%#v\n", result)
}スナップショット管理構成を変更します。
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/tables"
)
var (
region string
tableBucketArn string
namespace string
name string
)
func init() {
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
flag.StringVar(&tableBucketArn, "table-bucket-arn", "", "The arn of the table bucket.")
flag.StringVar(&namespace, "namespace", "", "The name of the namespace.")
flag.StringVar(&name, "name", "", "The name of the table.")
}
func main() {
flag.Parse()
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
if len(tableBucketArn) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table bucket arn required")
}
if len(namespace) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, namespace name required")
}
if len(name) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table name required")
}
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := tables.NewTablesClient(cfg)
// icebergSnapshotManagement type
result, err := client.PutTableMaintenanceConfiguration(context.TODO(), &tables.PutTableMaintenanceConfigurationRequest{
TableBucketARN: oss.Ptr(tableBucketArn),
Namespace: oss.Ptr(namespace),
Name: oss.Ptr(name),
Type: oss.Ptr("icebergSnapshotManagement"),
Value: &tables.TableMaintenanceValue{
Status: oss.Ptr("enabled"),
Settings: &tables.TableMaintenanceSettings{
IcebergSnapshotManagement: &tables.IcebergSnapshotManagementSettingsDetail{
MaxSnapshotAgeHours: oss.Ptr(350),
MinSnapshotsToKeep: oss.Ptr(1),
},
},
},
})
if err != nil {
log.Fatalf("failed to put table maintenance configuration %v", err)
}
log.Printf("put table maintenance configuration result:%#v\n", result)
}Java
スナップショット管理構成を照会します。
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.tables.OSSTablesClient;
import com.aliyun.sdk.service.oss2.tables.models.*;
public class GetTableMaintenanceConfigurationSample {
public static void main(String[] args) throws Exception {
String region = "cn-hangzhou";
String tableBucketARN = "acs:osstables:cn-hangzhou:1234567890:bucket/mytable-bucket";
String namespace = "mynamespace";
String name = "mytable";
try (OSSTablesClient client = OSSTablesClient.newBuilder()
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.region(region)
.build()) {
GetTableMaintenanceConfigurationRequest request = GetTableMaintenanceConfigurationRequest.newBuilder()
.tableBucketARN(tableBucketARN)
.namespace(namespace)
.name(name)
.build();
GetTableMaintenanceConfigurationResult result = client.getTableMaintenanceConfiguration(request);
System.out.printf("Status code:%d, request id:%s%n",
result.statusCode(), result.requestId());
System.out.printf("Table ARN: %s%n", result.tableARN());
if (result.configuration() != null && !result.configuration().isEmpty()) {
System.out.println("Maintenance configurations:");
result.configuration().forEach((type, config) -> {
System.out.printf(" Type: %s, Status: %s%n", type, config.status());
if (config.settings() != null) {
if (config.settings().icebergCompaction() != null) {
System.out.printf(" Compaction - TargetFileSizeMB: %d, Strategy: %s%n",
config.settings().icebergCompaction().targetFileSizeMB(),
config.settings().icebergCompaction().strategy());
}
if (config.settings().icebergSnapshotManagement() != null) {
System.out.printf(" SnapshotManagement - MinSnapshotsToKeep: %d, MaxSnapshotAgeHours: %d%n",
config.settings().icebergSnapshotManagement().minSnapshotsToKeep(),
config.settings().icebergSnapshotManagement().maxSnapshotAgeHours());
}
}
});
} else {
System.out.println("No maintenance configuration found.");
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}スナップショット管理構成を変更します。
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.tables.OSSTablesClient;
import com.aliyun.sdk.service.oss2.tables.models.*;
public class PutTableMaintenanceConfigurationSample {
public static void main(String[] args) throws Exception {
String region = "cn-hangzhou";
String tableBucketARN = "acs:osstables:cn-hangzhou:1234567890:bucket/mytable-bucket";
String namespace = "mynamespace";
String name = "mytable";
String type = "icebergSnapshotManagement";
String status = "enabled";
int maxSnapshotAgeHours = 72;
int minSnapshotsToKeep = 3;
try (OSSTablesClient client = OSSTablesClient.newBuilder()
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.region(region)
.build()) {
IcebergSnapshotManagementSettings snapshotManagementSettings = IcebergSnapshotManagementSettings.newBuilder()
.maxSnapshotAgeHours(maxSnapshotAgeHours)
.minSnapshotsToKeep(minSnapshotsToKeep)
.build();
TableMaintenanceSettings settings = TableMaintenanceSettings.newBuilder()
.icebergSnapshotManagement(snapshotManagementSettings)
.build();
TableMaintenanceConfigurationValue value = TableMaintenanceConfigurationValue.newBuilder()
.status(status)
.settings(settings)
.build();
PutTableMaintenanceConfigurationRequest request = PutTableMaintenanceConfigurationRequest.newBuilder()
.tableBucketARN(tableBucketARN)
.namespace(namespace)
.name(name)
.type(type)
.value(value)
.build();
PutTableMaintenanceConfigurationResult result = client.putTableMaintenanceConfiguration(request);
System.out.printf("Status code:%d, request id:%s%n",
result.statusCode(), result.requestId());
System.out.printf("Successfully put table maintenance configuration for table: %s/%s, type: %s%n", namespace, name, type);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}API
スナップショット管理を構成するには、以下の API オペレーションを使用します。
実行メカニズム
スケジューリング:システムバックエンドがメンテナンスタスクを自動的にスケジュールおよび実行します。これらのタスクは固定時刻に実行されません。通常、特定のテーブルに対するメンテナンスタスクは約 24 時間に 1 回実行されます。システム負荷が高い場合、メンテナンスタスクが遅延する可能性があります。
リソース使用量:自動メンテナンスタスクは、ご利用のスループットまたは QPS クォータを消費せず、本番ワークロードに影響を与えません。
トランザクション隔離:メンテナンスタスクは Iceberg スナップショット隔離を使用します。タスクがファイルをマージしている間も、並行する書き込み操作を継続できます。クエリエンジンが自動的に最新の有効なスナップショットを選択するため、読み取り操作にも影響はありません。
メンテナンスジョブステータスの照会
テーブルの 3 種類のメンテナンスジョブ (コンパクション、スナップショット管理、未参照ファイルのクリーンアップ) のステータスを確認します。各ジョブタイプは、それぞれ独立してステータスを返します。
コンソール
テーブルの [データメンテナンス] タブで、各メンテナンスジョブの [ジョブステータス] を表示します。
OSS 管理コンソール にログインします。左側のナビゲーションバーで、[Table Bucket リスト] を選択します。
対象の Table Bucket 名をクリックします。[テーブルリスト] で、テーブル名をクリックして詳細ページを開きます。
[データメンテナンス] タブをクリックします。
各メンテナンスセクションで、[ジョブステータス] を確認します。
コンパクション:コンパクションジョブの実行ステータス (「失敗」または「成功」など) および前回の実行タイムスタンプを表示します。
スナップショット管理:スナップショットクリーンアップジョブの実行ステータスおよび前回の実行タイムスタンプを表示します。
未参照ファイルのクリーンアップ:このジョブは Table Bucket レベルで構成されています。[Table Bucket で構成を編集] リンクをクリックして、Table Bucket の [データメンテナンス] ページを開き、ステータスを確認します。
ossutil
ossutil tables-api get-table-maintenance-job-status \
--table-bucket-arn acs:osstables:cn-hangzhou:1234567890:bucket/mytable-bucket \
--namespace mynamespace \
--name mytableSDK
Python
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.tables as oss_tables
parser = argparse.ArgumentParser(description="get table maintenance job status sample")
parser.add_argument('--region', help='The region where the table bucket is located.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS Tables.')
parser.add_argument('--table-bucket-arn', help='The ARN of the table bucket.', required=True)
parser.add_argument('--namespace', help='The namespace of the table.', required=True)
parser.add_argument('--name', help='The name of the table.', required=True)
def main():
args = parser.parse_args()
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_tables.Client(cfg)
result = client.get_table_maintenance_job_status(
oss_tables.models.GetTableMaintenanceJobStatusRequest(
table_bucket_arn=args.table_bucket_arn,
namespace=args.namespace,
name=args.name,
)
)
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
f' table arn: {result.table_arn},'
f' status: {result.status}')
if __name__ == "__main__":
main()Go
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/tables"
)
var (
region string
tableBucketArn string
namespace string
name string
)
func init() {
flag.StringVar(®ion, "region", "", "The region where the table bucket is located.")
flag.StringVar(&tableBucketArn, "table-bucket-arn", "", "The ARN of the table bucket.")
flag.StringVar(&namespace, "namespace", "", "The namespace of the table.")
flag.StringVar(&name, "name", "", "The name of the table.")
}
func main() {
flag.Parse()
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
if len(tableBucketArn) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table bucket arn required")
}
if len(namespace) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, namespace name required")
}
if len(name) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, table name required")
}
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := tables.NewTablesClient(cfg)
result, err := client.GetTableMaintenanceJobStatus(context.TODO(), &tables.GetTableMaintenanceJobStatusRequest{
TableBucketARN: oss.Ptr(tableBucketArn),
Namespace: oss.Ptr(namespace),
Name: oss.Ptr(name),
})
if err != nil {
log.Fatalf("failed to get table maintenance job status %v", err)
}
log.Printf("get table maintenance job status result:%#v\n", result)
}Java
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.tables.OSSTablesClient;
import com.aliyun.sdk.service.oss2.tables.models.*;
public class GetTableMaintenanceJobStatusSample {
public static void main(String[] args) throws Exception {
String region = "cn-hangzhou";
String tableBucketARN = "acs:osstables:cn-hangzhou:1234567890:bucket/mytable-bucket";
String namespace = "mynamespace";
String name = "mytable";
try (OSSTablesClient client = OSSTablesClient.newBuilder()
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.region(region)
.build()) {
GetTableMaintenanceJobStatusRequest request = GetTableMaintenanceJobStatusRequest.newBuilder()
.tableBucketARN(tableBucketARN)
.namespace(namespace)
.name(name)
.build();
GetTableMaintenanceJobStatusResult result = client.getTableMaintenanceJobStatus(request);
System.out.printf("Status code:%d, request id:%s%n",
result.statusCode(), result.requestId());
System.out.printf("Table ARN: %s%n", result.tableARN());
if (result.jobStatus() != null && !result.jobStatus().isEmpty()) {
System.out.println("Maintenance job status:");
result.jobStatus().forEach((type, status) -> {
System.out.printf(" Type: %s, Status: %s%n", type, status.status());
if (status.lastRunTimestamp() != null) {
System.out.printf(" LastRunTimestamp: %s%n", status.lastRunTimestamp());
}
if (status.failureMessage() != null && !status.failureMessage().isEmpty()) {
System.out.printf(" FailureMessage: %s%n", status.failureMessage());
}
});
} else {
System.out.println("No maintenance job status found.");
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}API
GetTableMaintenanceJobStatus API を呼び出して、メンテナンスジョブのステータスを取得します。