tencent cloud

TDSQL Boundless

Deletion of Expired Data

PDF
Modo Foco
Tamanho da Fonte
Última atualização: 2026-02-10 10:54:57
The system provides powerful data version control and lifecycle management features, mainly including:
Maximum versions: Controls the number of historical versions retained per cell.
Minimum versions: Used in conjunction with TTL to ensure a specified number of versions are retained when data expires.
Time To Live (TTL): Sets the data time-to-live for column families and automatically deletes expired data.
Note:
The current version only supports TTL/maximum versions/minimum versions at the ColumnFamily level, and does not support TTL/maximum versions/minimum versions at the Cell level.

Maximum Versions

Purpose: Sets the maximum versions retained per cell in each column family by using HColumnDescriptor .
Default Value: 1
Mechanism: The system does not overwrite data but appends new versions with timestamps. Old versions are deleted during Major Compaction.
Recommendation: Adjust the maximum versions based on application requirements. Avoid setting maximum versions too high (such as hundreds), as this may result in excessively large storage files.

Minimum Versions

Purpose: Sets the minimum versions retained per cell in each column family through HColumnDescriptor .
Default Value: 0 (indicating disabled).
Use Case: Used in conjunction with TTL to configure settings such as "retain data from the last T minutes, with a maximum of N versions, but keep at least M versions" (M < N).
Limitation: Applicable only when TTL is enabled for column families; must be less than the maximum versions.

TTL

Feature Description
Purpose: Sets the TTL (Time To Live) in seconds for column families. HBase automatically deletes all rows in the column family after data expiration, including both current and historical versions.
Time Basis: TTL time is based on UTC time.
Cleanup mechanism: During Minor Compaction, HBase will delete store files that contain only expired data.
Configuration Parameter
MIN_VERSIONS: If the minimum number of versions (MIN_VERSIONS) is set to a non-zero value, the TTL feature will be disabled.

Configuration Example

Set the TTL/min/maxVersions attributes for the ColumnFamily when creating a table.
TableName tableName = createTDSQLTableName("ht1");
byte[] CF1 = Bytes.toBytes("cf1");
byte[] CF2 = Bytes.toBytes("cf2");

// Create table descriptor
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(tableName);

// Configure the first column family: TTL=2 seconds, minVersions=2, maxVersions=5
tdb.setColumnFamily(
ColumnFamilyDescriptorBuilder.newBuilder(CF1)
.setTimeToLive(2)
.setMinVersions(2)
.setMaxVersions(5)
.build()
);

// Configure the second column family: TTL=3 seconds, minVersions=4, maxVersions=10
tdb.setColumnFamily(
ColumnFamilyDescriptorBuilder.newBuilder(CF2)
.setTimeToLive(3)
.setMinVersions(4)
.setMaxVersions(10)
.build()
);

// Build table and create
try (Admin admin = connection.getAdmin()) {
admin.createTable(tdb.build());
}
Modify the TTL/min/maxVersions attributes of the ColumnFamily.
TableName tableName = TableName.valueOf("ht1");
byte[] CF2 = Bytes.toBytes("cf2");

try (Admin admin = connection.getAdmin()) {
// Obtain the current column family configuration
ColumnFamilyDescriptor currentDesc = admin.getDescriptor(tableName)
.getColumnFamily(CF2);
// Create a new configuration based on the existing one (retaining other settings)
ColumnFamilyDescriptor newDesc = ColumnFamilyDescriptorBuilder.newBuilder(currentDesc)
.setTimeToLive(10) // Modifying TTL=10 seconds
.setMinVersions(2) // Modify minVersions=2
.setMaxVersions(5) // Modify maxVersions=5
.build();
// Apply the modifications
admin.modifyColumnFamily(tableName, newDesc);
System.out.println("Column family configuration updated successfully");
}

Ajuda e Suporte

Esta página foi útil?

comentários