Metadata management
Metadata management is designed for metadata management scenarios that involve massive amounts of data. After you enable this feature, OSS automatically collects change events such as the creation, update, and deletion of objects in an object bucket, along with related metadata, and writes them to tables managed in OSS Tables periodically. You can query these tables by using a SQL query engine in a compute cluster, which is suitable for scenarios such as data auditing, statistical analysis, and data governance.
Overview
In scenarios that involve massive amounts of data, managing and collecting statistics on metadata by directly traversing objects with List operations is inefficient. The metadata management feature organizes and stores the metadata of an object bucket as Apache Iceberg tables in an OSS-managed table bucket periodically, which improves the efficiency of managing and analyzing massive amounts of data.
After you enable metadata management, OSS maintains the following two types of metadata tables for the object bucket:
-
Journal Table: Required. Continuously records change events such as the creation, update, and deletion of objects in the object bucket, along with related metadata updates. It is a periodically updated, append-only event stream table.
-
Live Inventory Table: Optional. A metadata snapshot table that is continuously generated and updated based on the records of the Journal Table. It reflects the current state of objects in the object bucket.
The metadata tables are stored in the Iceberg format in an OSS-managed table bucket. You can query and analyze them by using SQL query engines that support the Iceberg REST Catalog protocol, such as Spark and Flink.
Typical scenarios include:
-
Data auditing: Trace the changes that occurred to an object within a specified time range.
-
Statistical analysis: Collect statistics on the number of objects, storage capacity, and the distribution of storage classes.
-
Data governance: Retrieve, analyze, and govern the metadata of massive amounts of objects.
The metadata management feature is currently in invitational preview and is available only in the Germany (Frankfurt) region. You can enable, modify, or disable the metadata management feature by using the OSS console, ossutil, SDKs, or API operations. For more information, see Operations.
Core concepts
|
Concept |
Term |
Description |
|
Metadata management |
OSS Metadata |
The periodic metadata collection and management capability provided by OSS. It organizes and stores object metadata as Iceberg tables to facilitate querying and analysis. |
|
OSS-managed table bucket |
OSS Managed Table Bucket |
A table bucket that is automatically created and managed by OSS to store metadata tables. Users have only read permissions on it. |
|
Journal Table |
Journal Table |
An append-only event stream table that continuously records object change events (upload, update, and deletion, along with their metadata updates). It is required when you enable the metadata management feature. |
|
Live Inventory Table |
Live Inventory Table |
A snapshot table that reflects the current metadata state of the object bucket. It is dynamically maintained by OSS in the background and is optional. |
|
Backfill |
Backfill |
The process of scanning existing objects in the object bucket to generate a full set of metadata when the Live Inventory Table is enabled for the first time. |
|
Record expiration |
Record Expiration |
The capability of the Journal Table to automatically clean up historical record entries that are no longer needed, based on the configured expiration period in days. |
Metadata storage structure
Metadata tables are stored uniformly in an OSS-managed table bucket. A single managed table bucket named oss-managed-table-bucket is shared within the same region and under the same Alibaba Cloud account (UID). The metadata tables of different object buckets are isolated by different namespaces. A namespace is named b_{object-bucket-name} and contains the Journal Table (journal) and the Live Inventory Table (inventory) of the corresponding object bucket.
oss-managed-table-bucket (Managed Table Bucket)
├─ b_object_bucket_1/ (Namespace)
│ ├── journal (Journal Table)
│ └── inventory (Live Inventory Table)
├─ b_object_bucket_2/
│ ├── journal
│ └── inventory
└─ b_object_bucket_3/
└── journal
If the Live Inventory Table is not enabled, the namespace contains only the Journal Table.
The Journal Table and Live Inventory Table are metadata tables that are automatically generated by scanning by the OSS system. To ensure consistency between the metadata and the actual objects, the tables in the managed table bucket are designed to be read-only: you can query (SELECT) the table data, but you cannot write to or modify it (INSERT/UPDATE/DELETE). This ensures the following:
-
The content of the metadata tables is always trustworthy.
-
There is no risk of inconsistency between the metadata and the actual objects caused by user errors.
-
The data is reliable in auditing scenarios.
Although the tables in the managed table bucket are read-only by default, you can still configure authorization policies that grant write or delete permissions on the table bucket and assign them to relevant users. Do not configure such modification or deletion permissions for the managed metadata tables. Otherwise, the metadata may become inconsistent with the actual objects, which affects the accuracy and trustworthiness of the data.
Journal Table
The Journal Table records the changes that occur to objects in the object bucket. It is a continuously recorded event stream. The change types include CREATE, UPDATE_METADATA, and DELETE. It does not include access log information such as access time.
Enabling, disabling, and update frequency
-
Start time: Recording starts when you enable the metadata management feature. There is a certain delay before it takes effect.
-
Update frequency: Typically updated approximately every 10 minutes.
-
End time: Recording stops when you disable the metadata management feature. There is a certain delay before disabling takes effect.
Record expiration
Over time, record entries in the Journal Table continue to accumulate. When you enable the metadata management feature (CreateBucketMetadataConfiguration), you can enable record expiration and set the number of expiration days. OSS then automatically cleans up historical record entries that exceed the retention period. After enabling the feature, you can also adjust the expiration configuration separately by using UpdateBucketMetadataJournalTableConfiguration, or modify the auto-expire configuration in the Modify OSS Metadata Configuration panel in the OSS console.
Schema
The fields of the Journal Table are described in the following table.
In the current invitational preview, the metadata includes only system metadata, along with the tag count (tagging_count) and the user-defined metadata count (user_meta_count) fields. It does not yet include the specific content of object tags or user-defined metadata.
|
Column name |
Required |
Description |
Example |
|
bucket |
Yes |
The name of the object bucket for which the metadata management feature is enabled. |
examplebucket |
|
key |
Yes |
The object name. |
exampledir/example.jpg |
|
sequence_number |
Yes |
A sequence number that is unique within a single object and can be ordered by time. |
1024 |
|
record_type |
Yes |
The record type. Valid values: CREATE, UPDATE_METADATA, DELETE. |
CREATE |
|
record_timestamp |
Yes |
The timestamp when the record was generated. |
2024-01-15T10:30:00.000Z |
|
version_id |
No |
The version ID of the object. |
CAEQEhiBgIDb1example |
|
is_delete_marker |
Yes |
Whether the object is a delete marker. |
false |
|
size |
Yes |
The size of the object, in bytes. |
1048576 |
|
last_modified_date |
No |
The last modified time of the object. |
2024-01-15T10:30:00.000Z |
|
e_tag |
Yes |
The ETag of the object. |
5D41402ABC4B2A76B9719D911017C592 |
|
storage_class |
Yes |
The storage class of the object. |
Standard |
|
is_multipart_upload |
Yes |
Whether the object is a multipart upload object. |
false |
|
encryption_status |
No |
The server-side encryption status of the object, which depends on the type of encryption key used. |
SSE-OSS |
|
is_sse_kms_enabled |
Yes |
The bucket key enabling status of the object. The value is true if the object is encrypted with SSE-KMS by using a bucket key. Otherwise, the value is false. |
false |
|
kms_key_arn |
No |
The KMS primary key. This field is included only when the object is encrypted with SSE-KMS. |
acs:kms:cn-hangzhou:123456789012****:key/1234abcd-12ab-34cd-56ef-1234567890ab |
|
crc64 |
No |
The CRC-64 value of the object. |
3821901021982791585 |
|
tagging_count |
Yes |
The number of tags of the object. |
2 |
|
user_meta_count |
Yes |
The number of user-defined metadata items of the object. |
3 |
|
requester |
Yes |
The Alibaba Cloud ID or principal ID of the requester. |
203456789012**** |
|
source_ip |
No |
The source IP address of the requester. |
192.0.2.1 |
|
request_id |
Yes |
The unique identifier of the request. |
5F3E9A1B2C3D4E5F60718293 |
|
object_type |
Yes |
The object type. Valid values: Normal, Multipart, Appendable, Symlink. |
Normal |
|
object_acl |
Yes |
The read and write permissions on the object. For more information, see Object ACL. |
default |
Live Inventory Table
The Live Inventory Table is a snapshot of the latest metadata of the object bucket. OSS dynamically maintains this table in the background, so you do not need to export and update CSV or Parquet files by using the traditional inventory feature. This table is an optional item in the metadata management feature, and you can decide whether to enable it as needed.
Enabling, disabling, and update frequency
-
Start time: Generation starts when you enable the Live Inventory Table. Unlike the Journal Table, which records only new changes, the Live Inventory Table requires a full backfill of the metadata of existing objects in the object bucket when it is enabled for the first time.
-
Initial backfill time: On the order of hours. The exact duration depends on the volume of existing data in the object bucket. The larger the volume, the longer the backfill takes.
-
Update frequency after backfill: Typically updated approximately once an hour.
-
End time: Updates stop when you disable the Live Inventory Table or the metadata management feature. There is a certain delay before it takes effect.
Table states
The common states of the Live Inventory Table are as follows:
-
Creating: The table is being created. The console displays this state as Creating.
-
Backfilling: Existing data is being backfilled. After the backfill is complete (the full set is complete and has caught up with incremental changes), the state changes to Active. The console displays this state as Backfilling.
-
Active: The table is ready and can be queried. The console displays this state as Active.
-
Failed: Creation failed. The console displays this state as Failed.
Schema
The fields of the Live Inventory Table are described in the following table.
|
Column name |
Required |
Description |
Example |
|
bucket |
Yes |
The name of the object bucket for which the metadata management feature is enabled. |
examplebucket |
|
key |
Yes |
The object name. |
exampledir/example.jpg |
|
sequence_number |
Yes |
A sequence number that is unique within a single object and can be ordered by time. |
1024 |
|
version_id |
No |
The version ID of the object. |
CAEQEhiBgIDb1example |
|
is_delete_marker |
Yes |
Whether the object is a delete marker. |
false |
|
size |
Yes |
The size of the object, in bytes. |
1048576 |
|
last_modified_date |
Yes |
The last modified date of the object. |
2024-01-15T10:30:00.000Z |
|
e_tag |
Yes |
The ETag of the object. |
5D41402ABC4B2A76B9719D911017C592 |
|
storage_class |
Yes |
The storage class of the object. |
Standard |
|
is_multipart_upload |
Yes |
Whether the object is a multipart upload object. |
false |
|
encryption_status |
Yes |
The encryption status of the object. |
SSE-OSS |
|
is_sse_kms_enabled |
Yes |
The bucket key enabling status of the object. The value is true if the object is encrypted with SSE-KMS by using a bucket key. Otherwise, the value is false. |
false |
|
kms_key_arn |
Yes |
The KMS primary key. This field is included only when the object is encrypted with SSE-KMS. |
acs:kms:cn-hangzhou:123456789012****:key/1234abcd-12ab-34cd-56ef-1234567890ab |
|
tagging_count |
Yes |
The number of tags of the object. |
2 |
|
user_meta_count |
Yes |
The number of user-defined metadata items of the object. |
3 |
|
crc64 |
Yes |
The CRC-64 value of the object. |
3821901021982791585 |
Query metadata tables
Metadata tables are stored in OSS Tables as Apache Iceberg tables. OSS Tables is compatible with the Apache Iceberg REST Catalog standard protocol, so you do not need to set up an external catalog service. Compute engines such as Spark can connect directly to OSS Tables through the Iceberg REST Catalog and use standard SQL for queries. For example, see Access OSS Tables with Spark, Access OSS Tables from EMR Serverless Spark, and Access OSS Tables by using EMR Serverless StarRocks.
Operations
You can manage metadata management configuration by using the OSS console, ossutil, SDKs, and API operations. The following sections describe how to configure metadata management by using each method.
Enable metadata management
When you enable metadata management, OSS creates a Journal Table for the object bucket. You can also enable record expiration, specify an encryption method, and enable the Live Inventory Table.
When you enable the metadata management feature for the first time, you must explicitly complete AssumeRole authorization, which involves the following two service-linked roles. In the OSS console, after the authorization is complete, the Metadata Management page displays RAM Authorization Complete and lists the created roles.
-
AliyunServiceRoleForOSSMetadata: Uses the service principalmetadata.oss.aliyuncs.comto collect object change events and write them to metadata tables. -
AliyunServiceRoleForOSSSystemTables: Uses the service principalsystemtables.oss.aliyuncs.comto create and manage system-managed tables in the managed Table Bucket.
Console
-
Log on to the OSS console.
-
Click the name of the target bucket. In the left-side navigation pane, choose Data Management > OSS Metadata.
-
On the Metadata Management page, click Enable Now. If the page prompts that RAM authorization is not complete, follow the on-screen instructions to complete the authorization. After the authorization is complete, the page displays RAM Authorization Complete and the service-linked roles that were created.
-
In the Enable OSS Metadata panel, configure the following parameters:
-
Change Log: Enabled by default and cannot be disabled.
-
Auto-Cleanup on Expiration: Optional. If you enable this option, set Days to Expire to a value from 7 to 365 and select I confirm that expired records will be automatically deleted and cannot be recovered. Expiration cleanup runs periodically in the background and does not take effect immediately after you change the configuration.
-
Encryption Configuration: You can select Default Encryption Method, AES256, or KMS Encryption. The encryption method of the Journal Table cannot be changed after creation.
-
Dynamic Inventory: Optional. When you first enable this, historical data is backfilled. The process can take hours, depending on the data volume.
-
-
Click Enable. After the feature is enabled, the page displays the managed table bucket information and the states of the Journal Table and the Live Inventory Table. Tables are created asynchronously. When you enable the feature for the first time, the page displays a loading state of Enabling, and the Journal Table may remain in the Creating state for more than ten minutes. This is normal. Wait for the status to update.
ossutil
The following command enables metadata management for the bucket examplebucket and also enables record expiration (7 days) and the Live Inventory Table.
ossutil api create-bucket-metadata-configuration --bucket examplebucket --metadata-configuration file://metadata-configuration.json
The content of metadata-configuration.json is as follows:
{
"JournalTableConfiguration": {
"RecordExpiration": {
"Expiration": "ENABLED",
"Days": 7
}
},
"InventoryTableConfiguration": {
"ConfigurationState": "ENABLED"
}
}
This command requires ossutil 2.4.1 or later. For more information about this command, see create-bucket-metadata-configuration.
SDK
The following examples show how to enable metadata management by using common SDKs. For complete examples, see Metadata management (Java SDK V2), Metadata management (Python SDK V2), and Metadata management (Go SDK V2).
Java
To enable metadata management, configure the MetadataConfiguration object as follows.
MetadataConfiguration configuration = MetadataConfiguration.newBuilder()
.journalTableConfiguration(JournalTableConfiguration.newBuilder()
.recordExpiration(MetadataTableRecordExpiration.newBuilder()
.expiration("ENABLED")
.days(7)
.build())
.build())
.inventoryTableConfiguration(InventoryTableConfiguration.newBuilder()
.configurationState("ENABLED")
.build())
.build();
CreateBucketMetadataConfigurationResult result = client.createBucketMetadataConfiguration(
CreateBucketMetadataConfigurationRequest.newBuilder()
.bucket("examplebucket")
.metadataConfiguration(configuration)
.build());
Python
When you call the create_bucket_metadata_configuration method, configure the Journal Table and the Live Inventory Table by using the metadata_configuration parameter.
result = client.create_bucket_metadata_configuration(oss.CreateBucketMetadataConfigurationRequest(
bucket="examplebucket",
metadata_configuration=oss.MetadataConfiguration(
journal_table_configuration=oss.JournalTableConfiguration(
record_expiration=oss.MetadataTableRecordExpiration(
expiration="ENABLED",
days=7,
),
),
inventory_table_configuration=oss.InventoryTableConfiguration(
configuration_state="ENABLED",
),
),
))
Go
When you create a CreateBucketMetadataConfigurationRequest request, configure the MetadataConfiguration field as follows.
request := &oss.CreateBucketMetadataConfigurationRequest{
Bucket: oss.Ptr("examplebucket"),
MetadataConfiguration: &oss.MetadataConfiguration{
JournalTableConfiguration: &oss.JournalTableConfiguration{
RecordExpiration: &oss.MetadataTableRecordExpiration{
Expiration: oss.Ptr("ENABLED"),
Days: oss.Ptr(7),
},
},
InventoryTableConfiguration: &oss.InventoryTableConfiguration{
ConfigurationState: oss.Ptr("ENABLED"),
},
},
}
After metadata management is enabled, to query the status of each table, see GetBucketMetadataConfiguration below, or view the status on the Metadata Management page in the console.
API
Call CreateBucketMetadataConfiguration to enable metadata management. Use the MetadataConfiguration request parameter to configure record expiration and encryption for the Journal Table, and to specify whether to enable the Live Inventory Table.
After metadata management is enabled, you can call GetBucketMetadataConfiguration to query the configuration details and the status of each table.
By default, only the Journal Table is enabled. Auto-Cleanup on Expiration and the Live Inventory Table are disabled by default.
View and delete metadata tables in a Table Bucket
Metadata tables are stored in the managed Table Bucket in the current region under the current Alibaba Cloud account that is named oss-managed-table-bucket. Metadata tables of different object buckets are isolated by namespace b_{object-bucket-name}. You can view and delete metadata tables by using the OSS console, ossutil, OSS SDKs, or API operations.
Console
-
Log on to the OSS console. In the left-side navigation pane, click Table Buckets.
-
Click the managed Table Bucket
oss-managed-table-bucket. Its Type issystem, which indicates that the Table Bucket is automatically created and managed by OSS. -
Click the Tables tab to view all metadata tables in the Table Bucket. The Name column shows the table name (
journalorinventory), and the Namespace column shows the object bucket to which the table belongs (b_{object-bucket-name}). -
Find the target table, click Delete, enter the name of the table in the dialog box, and click Delete again.
ossutil
The following command lists the metadata tables of the object bucket examplebucket. Replace the region and Alibaba Cloud account ID in --table-bucket-arn with actual values. The ARN of a Table Bucket uses the format acs:osstables:{region}:{uid}:bucket/{bucket-name}. You can view the ARN in Table Buckets: click oss-managed-table-bucket and view the value in the Basic Information section.
ossutil tables-api list-tables --table-bucket-arn acs:osstables:cn-hangzhou:1234567890:bucket/oss-managed-table-bucket --namespace b_examplebucket
In the returned result, the table named journal is the Journal Table, and the table named inventory is the Live Inventory Table. The following command deletes the specified metadata table. Deleted tables cannot be recovered.
ossutil tables-api delete-table --table-bucket-arn acs:osstables:cn-hangzhou:1234567890:bucket/oss-managed-table-bucket --namespace b_examplebucket --name journal
For more information about this command, see list-tables and delete-table.
SDK
The following code examples use ListTables to list metadata tables and DeleteTable to delete metadata tables.
Java
List metadata tables:
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 ListTablesSample {
public static void main(String[] args) throws Exception {
String region = "cn-hangzhou";
String tableBucketARN = "acs:osstables:cn-hangzhou:1234567890:bucket/my-table-bucket";
String namespace = "my-namespace";
int maxTables = 10;
try (OSSTablesClient client = OSSTablesClient.newBuilder()
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.region(region)
.build()) {
ListTablesRequest request = ListTablesRequest.newBuilder()
.tableBucketARN(tableBucketARN)
.namespace(namespace)
.maxTables(maxTables)
.build();
ListTablesResult result = client.listTables(request);
System.out.printf("Status code:%d, request id:%s%n",
result.statusCode(), result.requestId());
System.out.printf("Continuation token: %s%n", result.continuationToken());
if (result.tables() != null) {
System.out.printf("Number of tables: %d%n", result.tables().size());
for (int i = 0; i < result.tables().size(); i++) {
TableSummary table = result.tables().get(i);
System.out.printf("Table %d:%n", i + 1);
System.out.printf(" Name: %s%n", table.name());
System.out.printf(" Namespace: %s%n", table.namespace());
System.out.printf(" ARN: %s%n", table.tableARN());
System.out.printf(" Type: %s%n", table.type());
System.out.printf(" Created at: %s%n", table.createdAt());
System.out.printf(" Modified at: %s%n", table.modifiedAt());
}
} else {
System.out.println("No tables found.");
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}
Delete a metadata table:
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 DeleteTableSample {
public static void main(String[] args) throws Exception {
String region = "cn-hangzhou";
String tableBucketARN = "acs:osstables:cn-hangzhou:1234567890:bucket/my-table-bucket";
String namespace = "my-namespace";
String tableName = "my-table";
try (OSSTablesClient client = OSSTablesClient.newBuilder()
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.region(region)
.build()) {
DeleteTableRequest request = DeleteTableRequest.newBuilder()
.tableBucketARN(tableBucketARN)
.namespace(namespace)
.name(tableName)
.build();
DeleteTableResult result = client.deleteTable(request);
System.out.printf("Status code:%d, request id:%s%n",
result.statusCode(), result.requestId());
System.out.printf("Successfully deleted table: %s/%s from bucket: %s%n",
namespace, tableName, tableBucketARN);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}
Python
List metadata tables:
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.tables as oss_tables
parser = argparse.ArgumentParser(description="list tables 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 tables.', required=True)
parser.add_argument('--prefix', help='The prefix to filter tables.')
parser.add_argument('--max-tables', type=int, help='The maximum number of tables to return.')
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.list_tables(oss_tables.models.ListTablesRequest(
table_bucket_arn=args.table_bucket_arn,
namespace=args.namespace,
prefix=args.prefix,
max_tables=args.max_tables,
))
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
f' continuation token: {result.continuation_token}')
if result.table_summaries:
for i, table in enumerate(result.table_summaries):
print(f'table {i + 1}:'
f' name: {table.name},'
f' namespace: {table.namespace},'
f' type: {table.type},'
f' table arn: {table.table_arn},'
f' created at: {table.created_at},'
f' modified at: {table.modified_at}')
if __name__ == "__main__":
main()
Delete a metadata table:
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.tables as oss_tables
parser = argparse.ArgumentParser(description="delete table 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('--version-token', help='The version token for optimistic locking.')
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.delete_table(oss_tables.models.DeleteTableRequest(
table_bucket_arn=args.table_bucket_arn,
namespace=args.namespace,
name=args.name,
version_token=args.version_token,
))
print(f'status code: {result.status_code},'
f' request id: {result.request_id}')
print(f'successfully deleted table: {args.namespace}/{args.name}')
if __name__ == "__main__":
main()
Go
List metadata tables:
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
)
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.")
}
func main() {
flag.Parse()
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(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := tables.NewTablesClient(cfg)
p := client.NewListTablesPaginator(&tables.ListTablesRequest{
TableBucketARN: oss.Ptr(tableBucketArn),
Namespace: oss.Ptr(namespace),
})
var i int
log.Println("Tables:")
for p.HasNext() {
i++
page, err := p.NextPage(context.TODO())
if err != nil {
log.Fatalf("failed to get page %v, %v", i, err)
}
for _, b := range page.Tables {
log.Printf("Table %v,%v,%v,%v,%v,%v\n", oss.ToString(b.CreatedAt), oss.ToString(b.TableARN), oss.ToString(b.ModifiedAt), oss.ToString(b.Type), oss.ToString(b.Name), b.Namespace)
}
}
}
Delete a metadata table:
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(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")
}
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.DeleteTable(context.TODO(), &tables.DeleteTableRequest{
TableBucketARN: oss.Ptr(tableBucketArn),
Namespace: oss.Ptr(namespace),
Name: oss.Ptr(name),
})
if err != nil {
log.Fatalf("failed to delete table %v", err)
}
log.Printf("delete table result:%#v\n", result)
}
For complete examples, see Manage table buckets (Java SDK V2), Manage table buckets (Python SDK V2), and Table buckets (Go SDK V2).
API
Call ListTables to list metadata tables, call GetTable to view the details of a specified table, and call DeleteTable to delete a specified table. The tableBucketARN parameter in the request must be URL-encoded.
GET /tables/{tableBucketARN}?namespace=b_examplebucket HTTP/1.1
Host: cn-hangzhou.oss-tables.aliyuncs.com
DELETE /tables/{tableBucketARN}/b_examplebucket/journal HTTP/1.1
Host: cn-hangzhou.oss-tables.aliyuncs.com
A namespace does not have a separate delete entry. After you delete the last table in a namespace, the namespace is automatically removed. Do not delete oss-managed-table-bucket itself. Otherwise, the metadata tables of all object buckets in the region are lost. If the Table Buckets page prompts you to apply for beta testing, apply for the Table Bucket feature first.
Modify metadata management settings
You can adjust the record expiration configuration of the Journal Table and enable or disable the Live Inventory Table.
Console
-
On the Metadata Management page, click Modify.
-
In the Modify OSS Metadata Configuration panel, modify the Auto-Cleanup on Expiration configuration or enable the Live Inventory Table.
-
Click OK.
You can also click Enable or Disable in the Live Inventory Table section to enable or disable the Live Inventory Table separately. The change takes effect in about 15 to 30 minutes.
ossutil
Adjust the record expiration configuration of the Journal Table. The following command sets the expiration period to 7 days:
ossutil api update-bucket-metadata-journal-table-configuration --bucket examplebucket --journal-table-configuration file://journal-table-configuration.json
The content of journal-table-configuration.json is as follows:
{
"RecordExpiration": {
"Expiration": "ENABLED",
"Days": 7
}
}
Enable or disable the Live Inventory Table:
ossutil api update-bucket-metadata-inventory-table-configuration --bucket examplebucket --inventory-table-configuration file://inventory-table-configuration.json
The content of inventory-table-configuration.json is as follows (ConfigurationState can be set to ENABLED or DISABLED):
{
"ConfigurationState": "ENABLED"
}
For command details, see update-bucket-metadata-journal-table-configuration and update-bucket-metadata-inventory-table-configuration.
SDK
The following examples show how to modify the configuration by using common SDKs. For complete examples, see Metadata management (Java SDK V2), Metadata management (Python SDK V2), and Metadata management (Go SDK V2).
Java
Adjust the record expiration configuration of the Journal Table:
JournalTableConfiguration configuration = JournalTableConfiguration.newBuilder()
.recordExpiration(MetadataTableRecordExpiration.newBuilder()
.expiration("ENABLED")
.days(7)
.build())
.build();
client.updateBucketMetadataJournalTableConfiguration(
UpdateBucketMetadataJournalTableConfigurationRequest.newBuilder()
.bucket("examplebucket")
.journalTableConfiguration(configuration)
.build());
Enable or disable the Live Inventory Table:
InventoryTableConfiguration configuration = InventoryTableConfiguration.newBuilder()
.configurationState("ENABLED") // Set to DISABLED to disable the Live Inventory Table
.build();
client.updateBucketMetadataInventoryTableConfiguration(
UpdateBucketMetadataInventoryTableConfigurationRequest.newBuilder()
.bucket("examplebucket")
.inventoryTableConfiguration(configuration)
.build());
Python
Adjust the record expiration configuration of the Journal Table:
result = client.update_bucket_metadata_journal_table_configuration(
oss.UpdateBucketMetadataJournalTableConfigurationRequest(
bucket="examplebucket",
journal_table_configuration=oss.JournalTableConfiguration(
record_expiration=oss.MetadataTableRecordExpiration(
expiration="ENABLED",
days=7,
),
),
))
Enable or disable the Live Inventory Table:
result = client.update_bucket_metadata_inventory_table_configuration(
oss.UpdateBucketMetadataInventoryTableConfigurationRequest(
bucket="examplebucket",
inventory_table_configuration=oss.InventoryTableConfiguration(
configuration_state="ENABLED", # Set to DISABLED to disable the Live Inventory Table
),
))
Go
Adjust the record expiration configuration of the Journal Table:
request := &oss.UpdateBucketMetadataJournalTableConfigurationRequest{
Bucket: oss.Ptr("examplebucket"),
JournalTableConfiguration: &oss.JournalTableConfiguration{
RecordExpiration: &oss.MetadataTableRecordExpiration{
Expiration: oss.Ptr("ENABLED"),
Days: oss.Ptr(7),
},
},
}
Enable or disable the Live Inventory Table:
request := &oss.UpdateBucketMetadataInventoryTableConfigurationRequest{
Bucket: oss.Ptr("examplebucket"),
InventoryTableConfiguration: &oss.InventoryTableConfiguration{
ConfigurationState: oss.Ptr("ENABLED"), // Set to DISABLED to disable the Live Inventory Table
},
}
API
Call UpdateBucketMetadataJournalTableConfiguration to adjust the record expiration configuration of the Journal Table. Call UpdateBucketMetadataInventoryTableConfiguration to enable or disable the Live Inventory Table.
The encryption method of the Journal Table cannot be modified after creation.
Disable metadata management
Disabling metadata management deletes only the configuration and does not delete the generated metadata tables.
Console
-
On the Metadata Management page, click Close.
-
In the confirmation dialog box, click Confirm. After the feature is disabled, OSS stops collecting new object events. The generated Journal Table and Live Inventory Table are retained in the managed Table Bucket, and you can still query historical data. Storage fees for the historical data continue to be incurred.
ossutil
The following command deletes the metadata management configuration of the bucket examplebucket:
ossutil api delete-bucket-metadata-configuration --bucket examplebucket
For command details, see delete-bucket-metadata-configuration.
SDK
The following examples show how to delete the metadata management configuration by using common SDKs. For complete examples, see Metadata management (Java SDK V2), Metadata management (Python SDK V2), and Metadata management (Go SDK V2).
Java
client.deleteBucketMetadataConfiguration(
DeleteBucketMetadataConfigurationRequest.newBuilder()
.bucket("examplebucket")
.build());
Python
result = client.delete_bucket_metadata_configuration(
oss.DeleteBucketMetadataConfigurationRequest(bucket="examplebucket"))
Go
request := &oss.DeleteBucketMetadataConfigurationRequest{
Bucket: oss.Ptr("examplebucket"),
}
API
Call DeleteBucketMetadataConfiguration to delete the metadata management configuration. You can specify the object bucket by using the Bucket parameter.
To re-enable metadata management, first delete the generated metadata tables in the Table Bucket (after you delete the last table in a namespace, the namespace is automatically removed), and then click Enable Now on the Metadata Management page. If the existing metadata tables are not deleted, the Journal Table creation fails asynchronously after you re-enable the feature, and the Journal Table status is displayed as Failed. After you re-enable the feature, the Journal Table starts recording from the time of re-enabling, and the Live Inventory Table must backfill historical data again.
Limits
The OSS-managed table bucket, namespace, and tables that store the metadata tables are automatically created and managed by OSS. Users have only read permissions. The specific limits are as follows.
|
Operation |
Allowed for users |
Description |
|
Query table data (SELECT) |
Yes |
You can query the metadata tables by using query engines such as Spark and Flink. |
|
Create a table, namespace, or table bucket |
No |
These are automatically created by OSS when you enable the metadata management feature. |
|
Write table data (INSERT/UPDATE/DELETE) |
No |
To ensure that the metadata tables correctly reflect the content of the object bucket, users are not allowed to write to them. |
|
Rename a table, modify a table schema, or modify table maintenance configuration |
No |
Users are not allowed to make any modifications to the metadata tables. |
|
Delete a table or namespace |
Yes |
You can delete your own metadata tables. After you delete the last table in a namespace, the namespace is automatically removed. |
|
Set table encryption |
Only at creation |
The encryption method can be set only at creation and cannot be changed afterward. |
The OSS-managed table bucket does not count toward your table bucket quota.
Disabling metadata management deletes only the configuration and does not delete the generated metadata tables. Storage fees for the historical tables continue to be incurred. To re-enable the metadata management feature, you must first delete the generated metadata tables in the Table Bucket. Otherwise, the Journal Table fails to be created after you re-enable the feature, the Journal Table status is displayed as Failed, and the error code is JournalTableAlreadyExists.
Billing
The Journal Table and the Live Inventory Table stored in the OSS Table Bucket are billed for storage and related fees in the same way as OSS Tables. The metadata management feature does not incur additional fees during the invitational preview. Stay tuned to the commercialization announcements released on the OSS official website.