S3 protocol data compression

更新时间:
复制 MD 格式

The Lindorm S3-compatible protocol supports bucket-level data compression. You can use this feature to compress objects in a bucket during file upload. This topic describes how to use this data compression feature.

Prerequisites

The LindormTable database engine version must be 2.4.3.2 or later. For more information about how to view or upgrade the database engine version, see LindormTable version guide and Minor version update.

Usage notes

  • Setting a compression algorithm does not compress existing objects in the bucket.

  • Only the zlib algorithm is supported.

Enable data compression for a bucket

To enable data compression for a bucket, set the compression parameter in the bucket tag to zlib. This setting specifies the compression algorithm for objects that are uploaded to the bucket.

Important
  • By default, data compression is disabled for a bucket if the compression parameter is not set.

  • The data compression setting takes effect in 5 to 10 minutes. Wait 5 to 10 minutes after you set the compression algorithm before you upload files.

The following examples show how to enable data compression for the testbucket bucket in different environments.

Java

String bucketName = "testbucket";
TagSet tagSet = new TagSet();
tagSet.setTag("compression", "zlib");
client.setBucketTaggingConfiguration(bucketName, new BucketTaggingConfiguration().withTagSets(tagSet));

Go

tagInput := &s3.PutBucketTaggingInput{
        Bucket: aws.String("testbucket"),
        Tagging: &s3.Tagging{
            TagSet: []*s3.Tag{
            {
                Key:   aws.String("compression"),
                Value: aws.String("zlib"),
            },
        },
    },
  }
  _, err := client.PutBucketTagging(tagInput)

Python

client.put_bucket_tagging(
        Bucket="testbucket",
        Tagging={
            "TagSet":[{"Key":"compression","Value":"zlib"},]
        }
)

View the compression algorithm of a bucket

You can view the compression algorithm for a bucket by checking its tags.

Java

BucketTaggingConfiguration tagConfig = client.getBucketTaggingConfiguration(bucketName);

Go

result, _ := client.GetBucketTagging(&s3.GetBucketTaggingInput{
        Bucket: aws.String("testbucket"),
})

Python

result = client.get_bucket_tagging(
Bucket='testbucket'
)

Disable data compression for a bucket

You can disable data compression by removing the compression tag from the bucket.

Important
  • If a bucket has multiple tags and you want to remove only the compression tag, you must overwrite the existing set of tags. For more information, see Enable data compression for a bucket.

  • After you delete the compression tag, the change takes effect in 5 to 10 minutes.

Java

client.deleteBucketTaggingConfiguration("testbucket");

Go

_, err := client.DeleteBucketTagging(&s3.DeleteBucketTaggingInput{
    Bucket: aws.String("testbucket"),
})

Python

client.delete_bucket_tagging(Bucket="testbucket")

View the compression effect

Java

S3Object object = client.getObject(containerName, blobName);
object.getObjectMetadata().getUserMetadata().get("x-lindorm-blob-compressed-length")
Note
  • x-lindorm-blob-compressed-length is a specific field. You must add this field to your request to view the compressed size of an object.

  • The value returned for this field is the size of the compressed object.

Go

input := &s3.HeadObjectInput{
Bucket: aws.String("testbucket"),
Key: aws.String("testblob"),
}
result, _ := client.HeadObject(input)
fmt.Println(*result)

Python

response = s3_client.head_object(
    Bucket="testbucket",
    Key="testblob"
)
print(response['Metadata']['x-lindorm-blob-compressed-length'])
Note
  • x-lindorm-blob-compressed-length is a specific field. You must add this field to your request to view the compressed size of an object.

  • The value returned for this field is the size of the compressed object.