diff --git a/CHANGES.txt b/CHANGES.txt index 96af8eb808a..2a45e1c4aa3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -131,6 +131,8 @@ Trunk (unreleased changes) duration of compaction. HADOOP-2592 Scanning, a region can let out a row that its not supposed to have + HADOOP-2493 hbase will split on row when the start and end row is the + same cause data loss (Bryan Duxbury via Stack) IMPROVEMENTS HADOOP-2401 Add convenience put method that takes writable diff --git a/src/java/org/apache/hadoop/hbase/HRegion.java b/src/java/org/apache/hadoop/hbase/HRegion.java index cab43ddb2e6..46763a27873 100644 --- a/src/java/org/apache/hadoop/hbase/HRegion.java +++ b/src/java/org/apache/hadoop/hbase/HRegion.java @@ -654,7 +654,8 @@ public class HRegion implements HConstants { */ boolean needsSplit(Text midKey) { HStore.HStoreSize biggest = largestHStore(midKey); - if (biggest == null) { + if (biggest == null || midKey.getLength() == 0 || + (midKey.equals(getStartKey()) && midKey.equals(getEndKey())) ) { return false; } long triggerSize = this.desiredMaxFileSize + (this.desiredMaxFileSize / 2); diff --git a/src/java/org/apache/hadoop/hbase/HStore.java b/src/java/org/apache/hadoop/hbase/HStore.java index 85e3e911920..bcdcdc94209 100644 --- a/src/java/org/apache/hadoop/hbase/HStore.java +++ b/src/java/org/apache/hadoop/hbase/HStore.java @@ -2020,9 +2020,28 @@ public class HStore implements HConstants { } } MapFile.Reader r = this.readers.get(mapIndex); - WritableComparable midkey = r.midKey(); + + // seek back to the beginning of mapfile + r.reset(); + + // get the first and last keys + HStoreKey firstKey = new HStoreKey(); + HStoreKey lastKey = new HStoreKey(); + Writable value = new ImmutableBytesWritable(); + r.next((WritableComparable)firstKey, value); + r.finalKey((WritableComparable)lastKey); + + // get the midkey + HStoreKey midkey = (HStoreKey)r.midKey(); + if (midkey != null) { midKey.set(((HStoreKey)midkey).getRow()); + // if the midkey is the same as the first and last keys, then we cannot + // (ever) split this region. + if (midkey.getRow().equals(firstKey.getRow()) && + midkey.getRow().equals(lastKey.getRow())) { + return new HStoreSize(aggregateSize, maxSize, false); + } } } catch(IOException e) { LOG.warn("Failed getting store size for " + this.storeName, e); diff --git a/src/java/org/apache/hadoop/hbase/HStoreFile.java b/src/java/org/apache/hadoop/hbase/HStoreFile.java index 3e553ae31f2..f2f2797f51c 100644 --- a/src/java/org/apache/hadoop/hbase/HStoreFile.java +++ b/src/java/org/apache/hadoop/hbase/HStoreFile.java @@ -770,11 +770,18 @@ public class HStoreFile implements HConstants { } /** {@inheritDoc} */ - @SuppressWarnings({ "unused"}) @Override public synchronized void finalKey(WritableComparable key) throws IOException { - throw new UnsupportedOperationException("Unsupported"); + if (top) { + checkKey(key); + super.finalKey(key); + } else { + reset(); + Writable value = new ImmutableBytesWritable(); + + key = super.getClosest(midkey, value, true); + } } /** {@inheritDoc} */