HBASE-3572 memstore lab can leave half inited data structs

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1075494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan Rawson 2011-02-28 19:16:51 +00:00
parent 8607a22a7b
commit 0a44f87441
2 changed files with 13 additions and 1 deletions

View File

@ -120,6 +120,7 @@ Release 0.90.2 - Unreleased
(Himanshu Vashishtha via garyh)
HBASE-3576 MasterAddressTracker is registered to ZooKeeperWatcher twice
HBASE-3561 OPTS arguments are duplicated
HBASE-3572 memstore lab can leave half inited data structs (bad!)
IMPROVEMENTS
HBASE-3542 MultiGet methods in Thrift

View File

@ -154,6 +154,7 @@ public class MemStoreLAB {
private byte[] data;
private static final int UNINITIALIZED = -1;
private static final int OOM = -2;
/**
* Offset for the next allocation, or the sentinel value -1
* which implies that the chunk is still uninitialized.
@ -182,7 +183,13 @@ public class MemStoreLAB {
*/
public void init() {
assert nextFreeOffset.get() == UNINITIALIZED;
data = new byte[size];
try {
data = new byte[size];
} catch (OutOfMemoryError e) {
boolean failInit = nextFreeOffset.compareAndSet(UNINITIALIZED, OOM);
assert failInit; // should be true.
throw e;
}
// Mark that it's ready for use
boolean initted = nextFreeOffset.compareAndSet(
UNINITIALIZED, 0);
@ -207,6 +214,10 @@ public class MemStoreLAB {
Thread.yield();
continue;
}
if (oldOffset == OOM) {
// doh we ran out of ram. return -1 to chuck this away.
return -1;
}
if (oldOffset + size > data.length) {
return -1; // alloc doesn't fit