From 25613ad29cf9bdf7e0001d3aad8af9f421758af0 Mon Sep 17 00:00:00 2001 From: anastas Date: Mon, 7 May 2018 13:58:28 +0300 Subject: [PATCH] My squashed commits --- .../apache/hadoop/hbase/ByteBufferKeyValue.java | 6 ++--- .../regionserver/ByteBufferChunkKeyValue.java | 17 ++++++++++++++ .../hadoop/hbase/regionserver/CellArrayMap.java | 2 +- .../hadoop/hbase/regionserver/CellChunkMap.java | 14 +++++++---- .../hadoop/hbase/regionserver/CellFlatMap.java | 27 ++++++++++++++-------- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/ByteBufferKeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/ByteBufferKeyValue.java index 760d02c956..ed5d5de183 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/ByteBufferKeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/ByteBufferKeyValue.java @@ -34,9 +34,9 @@ import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesti @InterfaceAudience.Private public class ByteBufferKeyValue extends ByteBufferExtendedCell { - protected final ByteBuffer buf; - protected final int offset; - protected final int length; + protected ByteBuffer buf; + protected int offset; + protected int length; private long seqId = 0; public static final int FIXED_OVERHEAD = ClassSize.OBJECT + ClassSize.REFERENCE diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ByteBufferChunkKeyValue.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ByteBufferChunkKeyValue.java index 8278c420ff..f9539d20a2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ByteBufferChunkKeyValue.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ByteBufferChunkKeyValue.java @@ -36,6 +36,11 @@ public class ByteBufferChunkKeyValue extends ByteBufferKeyValue { super(buf, offset, length); } + // dummy constructor to the dummy reusable cell where each field is going tobe updated later + public ByteBufferChunkKeyValue() { + super(null, -1, -1); + } + public ByteBufferChunkKeyValue(ByteBuffer buf, int offset, int length, long seqId) { super(buf, offset, length, seqId); } @@ -45,4 +50,16 @@ public class ByteBufferChunkKeyValue extends ByteBufferKeyValue { // The chunkId is embedded at the 0th offset of the bytebuffer return ByteBufferUtils.toInt(buf, 0); } + + public void setBuffer(ByteBuffer buf){ + this.buf = buf; + } + + public void setOffset(int offset) { + this.offset = offset; + } + + public void setLength(int length) { + this.length = length; + } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellArrayMap.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellArrayMap.java index d364eee141..d01318b5af 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellArrayMap.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellArrayMap.java @@ -47,7 +47,7 @@ public class CellArrayMap extends CellFlatMap { } @Override - protected Cell getCell(int i) { + protected Cell getCell(int i, ByteBufferChunkKeyValue outputCell) { if( (i < minCellIdx) || (i >= maxCellIdx) ) return null; return block[i]; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellChunkMap.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellChunkMap.java index 3efae81040..1e2bfb435b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellChunkMap.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellChunkMap.java @@ -21,8 +21,6 @@ package org.apache.hadoop.hbase.regionserver; import java.nio.ByteBuffer; - -import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting; import org.apache.hadoop.hbase.Cell; import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.util.Bytes; @@ -94,7 +92,7 @@ public class CellChunkMap extends CellFlatMap { @Override - protected Cell getCell(int i) { + protected Cell getCell(int i, ByteBufferChunkKeyValue outputCell) { // get the index of the relevant chunk inside chunk array int chunkIndex = (i / numOfCellRepsInChunk); ByteBuffer block = chunks[chunkIndex].getData();// get the ByteBuffer of the relevant chunk @@ -129,6 +127,14 @@ public class CellChunkMap extends CellFlatMap { + chunk.isFromPool() + ". We were looking for a cell at index " + i); } - return new ByteBufferChunkKeyValue(buf, offsetOfCell, lengthOfCell, cellSeqID); + if (outputCell == null) { + return new ByteBufferChunkKeyValue(buf,offsetOfCell,lengthOfCell,cellSeqID); + } else { + outputCell.setOffset(offsetOfCell); + outputCell.setLength(lengthOfCell); + outputCell.setBuffer(buf); + outputCell.setSequenceId(cellSeqID); + return outputCell; + } } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellFlatMap.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellFlatMap.java index 17e64b0678..f1db90cd1f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellFlatMap.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellFlatMap.java @@ -50,6 +50,11 @@ public abstract class CellFlatMap implements NavigableMap { protected int maxCellIdx = 0; // the index of the cell after the maximal cell (for sub-sets) private boolean descending = false; + // dummy cell to save the overhead of creating new cell object any binary search step + // the buffer, offset and length are going to be initialized in getCell() + ThreadLocal reusableSearchCell = + ThreadLocal.withInitial(() -> new ByteBufferChunkKeyValue()); + /* C-tor */ public CellFlatMap(Comparator comparator, int min, int max, boolean d){ this.comparator = comparator; @@ -62,7 +67,7 @@ public abstract class CellFlatMap implements NavigableMap { protected abstract CellFlatMap createSubCellFlatMap(int min, int max, boolean descending); /* Returns the i-th cell in the cell block */ - protected abstract Cell getCell(int i); + protected abstract Cell getCell(int i, ByteBufferChunkKeyValue outputCell); /** * Binary search for a given key in between given boundaries of the array. @@ -82,9 +87,11 @@ public abstract class CellFlatMap implements NavigableMap { int begin = minCellIdx; int end = maxCellIdx - 1; + ByteBufferChunkKeyValue reusableCell = reusableSearchCell.get(); + while (begin <= end) { int mid = (begin + end) >>> 1; - Cell midCell = getCell(mid); + Cell midCell = getCell(mid, reusableCell); int compareRes = comparator.compare(midCell, needle); if (compareRes == 0) { @@ -212,7 +219,7 @@ public abstract class CellFlatMap implements NavigableMap { if (isEmpty()) { return null; } - return descending ? getCell(maxCellIdx - 1) : getCell(minCellIdx); + return descending ? getCell(maxCellIdx - 1, null) : getCell(minCellIdx, null); } @Override @@ -220,7 +227,7 @@ public abstract class CellFlatMap implements NavigableMap { if (isEmpty()) { return null; } - return descending ? getCell(minCellIdx) : getCell(maxCellIdx - 1); + return descending ? getCell(minCellIdx, null) : getCell(maxCellIdx - 1, null); } @Override @@ -231,7 +238,7 @@ public abstract class CellFlatMap implements NavigableMap { int index = find(k); // If index>=0 there's a key exactly equal index = (index>=0) ? index-1 : -(index); - return (index < minCellIdx || index >= maxCellIdx) ? null : getCell(index); + return (index < minCellIdx || index >= maxCellIdx) ? null : getCell(index, null); } @Override @@ -241,7 +248,7 @@ public abstract class CellFlatMap implements NavigableMap { } int index = find(k); index = (index>=0) ? index : -(index); - return (index < minCellIdx || index >= maxCellIdx) ? null : getCell(index); + return (index < minCellIdx || index >= maxCellIdx) ? null : getCell(index, null); } @Override @@ -251,7 +258,7 @@ public abstract class CellFlatMap implements NavigableMap { } int index = find(k); index = (index>=0) ? index : -(index)+1; - return (index < minCellIdx || index >= maxCellIdx) ? null : getCell(index); + return (index < minCellIdx || index >= maxCellIdx) ? null : getCell(index, null); } @Override @@ -261,7 +268,7 @@ public abstract class CellFlatMap implements NavigableMap { } int index = find(k); index = (index>=0) ? index+1 : -(index)+1; - return (index < minCellIdx || index >= maxCellIdx) ? null : getCell(index); + return (index < minCellIdx || index >= maxCellIdx) ? null : getCell(index, null); } @Override @@ -278,7 +285,7 @@ public abstract class CellFlatMap implements NavigableMap { @Override public Cell get(Object o) { int index = find((Cell) o); - return (index >= 0) ? getCell(index) : null; + return (index >= 0) ? getCell(index, null) : null; } // -------------------------------- Entry's getters -------------------------------- @@ -438,7 +445,7 @@ public abstract class CellFlatMap implements NavigableMap { @Override public Cell next() { - Cell result = getCell(index); + Cell result = getCell(index, null); if (descending) { index--; } else { -- 2.14.3 (Apple Git-98)