HBASE-621 Make MAX_VERSIONS work like TTL: In scans and gets, check MAX_VERSIONs setting and return that many only rather than wait on compaction

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@658419 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2008-05-20 20:40:47 +00:00
parent 7bbe456b0f
commit bf4536f713
5 changed files with 22 additions and 9 deletions

View File

@ -40,6 +40,9 @@ Hbase Change Log
and HConnectionManager (Jean-Daniel Cryans via Stack)
HBASE-23 UI listing regions should be sorted by address and show additional
region state (Jean-Daniel Cryans via Stack)
HBASE-621 Make MAX_VERSIONS work like TTL: In scans and gets, check
MAX_VERSIONs setting and return that many only rather than wait on
compaction (Jean-Daniel Cryans via Stack)
Release 0.1.2 - 05/13/2008

View File

@ -196,7 +196,7 @@ public interface HConstants {
/**
* Define for 'return-all-versions'.
*/
static final int ALL_VERSIONS = -1;
static final int ALL_VERSIONS = Integer.MAX_VALUE;
/**
* Unlimited time-to-live.

View File

@ -1230,7 +1230,7 @@ public class HStore implements HConstants {
* Get the value for the indicated HStoreKey. Grab the target value and the
* previous 'numVersions-1' values, as well.
*
* If 'numVersions' is negative, the method returns all available versions.
* Use {@link HConstants.ALL_VERSIONS} to retrieve all versions.
* @param key
* @param numVersions Number of versions to fetch. Must be > 0.
* @return values for the specified versions
@ -1246,7 +1246,7 @@ public class HStore implements HConstants {
try {
// Check the memcache
List<Cell> results = this.memcache.get(key, numVersions);
// If we got sufficient versions from memcache, return.
// If we got sufficient versions from memcache, return.
if (results.size() == numVersions) {
return results.toArray(new Cell[results.size()]);
}
@ -1323,9 +1323,18 @@ public class HStore implements HConstants {
}
}
/**
* Small method to check if we are over the max number of versions
* or we acheived this family max versions.
* The later happens when we have the situation described in HBASE-621.
* @param numVersions
* @param results
* @return
*/
private boolean hasEnoughVersions(final int numVersions,
final List<Cell> results) {
return numVersions > 0 && results.size() >= numVersions;
return (results.size() >= numVersions || results.size() >= family
.getMaxVersions());
}
/**
@ -1345,8 +1354,9 @@ public class HStore implements HConstants {
*/
List<HStoreKey> getKeys(final HStoreKey origin, final int versions)
throws IOException {
List<HStoreKey> keys = this.memcache.getKeys(origin, versions);
if (versions != ALL_VERSIONS && keys.size() >= versions) {
if (keys.size() >= versions) {
return keys;
}
@ -1391,7 +1401,7 @@ public class HStore implements HConstants {
}
// if we've collected enough versions, then exit the loop.
if (versions != ALL_VERSIONS && keys.size() >= versions) {
if (keys.size() >= versions) {
break;
}
}

View File

@ -610,7 +610,7 @@ class Memcache {
LOG.debug("internalGetKeys: " + key + ": expired, skipped");
}
}
if (versions != HConstants.ALL_VERSIONS && result.size() >= versions) {
if (result.size() >= versions) {
// We have enough results. Return.
break;
}

View File

@ -101,8 +101,8 @@ public class TestCompaction extends HBaseTestCase {
addContent(new HRegionIncommon(r), Bytes.toString(COLUMN_FAMILY));
Cell[] cellValues =
r.get(STARTROW, COLUMN_FAMILY_TEXT, 100 /*Too many*/);
// Assert that I can get > 5 versions (Should be at least 5 in there).
assertTrue(cellValues.length >= 5);
// Assert that I can get 3 versions since it is the max I should get
assertTrue(cellValues.length == 3);
r.flushcache();
r.compactStores();
// Now assert that there are 4 versions of a record only: thats the