HBASE-23678 : Builder API for version management - setVersionsWithTimeToLive

Signed-off-by: Xu Cang <xucang@apache.org>
This commit is contained in:
Viraj Jasani 2020-04-01 16:54:49 +05:30
parent f94c19494b
commit 96ae39b01b
No known key found for this signature in database
GPG Key ID: E906DFF511D3E5DB
2 changed files with 27 additions and 2 deletions

View File

@ -921,6 +921,23 @@ public class HColumnDescriptor implements WritableComparable<HColumnDescriptor>
return setValue(MIN_VERSIONS, Integer.toString(minVersions));
}
/**
* Retain all versions for a given TTL(retentionInterval), and then only a specific number
* of versions(versionAfterInterval) after that interval elapses.
*
* @param retentionInterval Retain all versions for this interval
* @param versionAfterInterval Retain no of versions to retain after retentionInterval
* @return this (for chained invocation)
*/
public HColumnDescriptor setVersionsWithTimeToLive(final int retentionInterval,
final int versionAfterInterval) {
HColumnDescriptor hColumnDescriptor =
setVersions(versionAfterInterval, Integer.MAX_VALUE);
hColumnDescriptor.setTimeToLive(retentionInterval);
hColumnDescriptor.setKeepDeletedCells(KeepDeletedCells.TTL);
return hColumnDescriptor;
}
/**
* @return True if hfile DATA type blocks should be cached (You cannot disable caching of INDEX
* and BLOOM type blocks).

View File

@ -19,6 +19,9 @@
package org.apache.hadoop.hbase.regionserver;
import static org.apache.hadoop.hbase.HBaseTestingUtility.COLUMNS;
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam1;
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam2;
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam3;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -28,8 +31,10 @@ import java.util.List;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeepDeletedCells;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
@ -470,8 +475,11 @@ public class TestMinVersions {
@Test
public void testMinVersionsWithKeepDeletedCellsTTL() throws Exception {
int ttl = 4;
HTableDescriptor htd = hbu.createTableDescriptor(name.getMethodName(),
2, Integer.MAX_VALUE, ttl, KeepDeletedCells.TTL);
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
for (byte[] cfName : new byte[][]{fam1, fam2, fam3}) {
htd.addFamily(new HColumnDescriptor(cfName)
.setVersionsWithTimeToLive(ttl, 2));
}
HRegion region = hbu.createLocalHRegion(htd, null, null);