HBASE-3208 HLog.findMemstoresWithEditsOlderThan needs to look for edits

that are equal to too


git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1032790 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jean-Daniel Cryans 2010-11-08 23:59:39 +00:00
parent a68b2c6645
commit 520676aaf1
3 changed files with 17 additions and 13 deletions

View File

@ -658,6 +658,8 @@ Release 0.90.0 - Unreleased
HBASE-3204 Reenable deferred log flush
HBASE-3195 [rest] Fix TestTransform breakage on Hudson
HBASE-3205 TableRecordReaderImpl.restart NPEs when first next is restarted
HBASE-3208 HLog.findMemstoresWithEditsOlderThan needs to look for edits
that are equal to too
IMPROVEMENTS

View File

@ -642,7 +642,7 @@ public class HLog implements Syncable {
if (logCount > this.maxLogs && this.outputfiles != null &&
this.outputfiles.size() > 0) {
// This is an array of encoded region names.
regions = findMemstoresWithEditsOlderThan(this.outputfiles.firstKey(),
regions = findMemstoresWithEditsEqualOrOlderThan(this.outputfiles.firstKey(),
this.lastSeqWritten);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < regions.length; i++) {
@ -657,19 +657,19 @@ public class HLog implements Syncable {
}
/**
* Return regions (memstores) that have edits that are less than the passed
* <code>oldestWALseqid</code>.
* Return regions (memstores) that have edits that are equal or less than
* the passed <code>oldestWALseqid</code>.
* @param oldestWALseqid
* @param regionsToSeqids
* @return All regions whose seqid is < than <code>oldestWALseqid</code> (Not
* necessarily in order). Null if no regions found.
*/
static byte [][] findMemstoresWithEditsOlderThan(final long oldestWALseqid,
static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
final Map<byte [], Long> regionsToSeqids) {
// This method is static so it can be unit tested the easier.
List<byte []> regions = null;
for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
if (e.getValue().longValue() < oldestWALseqid) {
if (e.getValue().longValue() <= oldestWALseqid) {
if (regions == null) regions = new ArrayList<byte []>();
regions.add(e.getKey());
}

View File

@ -262,28 +262,30 @@ public class TestHLog {
}
/**
* Test the findMemstoresWithEditsOlderThan method.
* Test the findMemstoresWithEditsEqualOrOlderThan method.
* @throws IOException
*/
@Test
public void testFindMemstoresWithEditsOlderThan() throws IOException {
public void testFindMemstoresWithEditsEqualOrOlderThan() throws IOException {
Map<byte [], Long> regionsToSeqids = new HashMap<byte [], Long>();
for (int i = 0; i < 10; i++) {
Long l = Long.valueOf(i);
regionsToSeqids.put(l.toString().getBytes(), l);
}
byte [][] regions =
HLog.findMemstoresWithEditsOlderThan(1, regionsToSeqids);
assertEquals(1, regions.length);
assertTrue(Bytes.equals(regions[0], "0".getBytes()));
regions = HLog.findMemstoresWithEditsOlderThan(3, regionsToSeqids);
int count = 3;
HLog.findMemstoresWithEditsEqualOrOlderThan(1, regionsToSeqids);
assertEquals(2, regions.length);
assertTrue(Bytes.equals(regions[0], "0".getBytes()) ||
Bytes.equals(regions[0], "1".getBytes()));
regions = HLog.findMemstoresWithEditsEqualOrOlderThan(3, regionsToSeqids);
int count = 4;
assertEquals(count, regions.length);
// Regions returned are not ordered.
for (int i = 0; i < count; i++) {
assertTrue(Bytes.equals(regions[i], "0".getBytes()) ||
Bytes.equals(regions[i], "1".getBytes()) ||
Bytes.equals(regions[i], "2".getBytes()));
Bytes.equals(regions[i], "2".getBytes()) ||
Bytes.equals(regions[i], "3".getBytes()));
}
}