From 8fa6371039e21cee1c7f76d299786a2fb5ed68ee Mon Sep 17 00:00:00 2001 From: Ramkrishna Date: Wed, 16 Aug 2017 11:05:43 +0530 Subject: [PATCH] HBASE-18251 Remove unnecessary traversing to the first and last keys in the CellSet (Toshihoro Suzuki) --- .../hbase/regionserver/CellFlatMap.java | 63 ++++++++++++++++--- .../hadoop/hbase/regionserver/CellSet.java | 7 +-- 2 files changed, 57 insertions(+), 13 deletions(-) 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 c83a382d670..aff601851dc 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 @@ -282,37 +282,85 @@ public abstract class CellFlatMap implements NavigableMap { } // -------------------------------- Entry's getters -------------------------------- - // all interfaces returning Entries are unsupported because we are dealing only with the keys + + private static class CellFlatMapEntry implements Entry { + private final Cell cell; + + public CellFlatMapEntry (Cell cell) { + this.cell = cell; + } + + @Override + public Cell getKey() { + return cell; + } + + @Override + public Cell getValue() { + return cell; + } + + @Override + public Cell setValue(Cell value) { + throw new UnsupportedOperationException(); + } + } + @Override public Entry lowerEntry(Cell k) { - throw new UnsupportedOperationException(); + Cell cell = lowerKey(k); + if (cell == null) { + return null; + } + return new CellFlatMapEntry(cell); } @Override public Entry higherEntry(Cell k) { - throw new UnsupportedOperationException(); + Cell cell = higherKey(k); + if (cell == null) { + return null; + } + return new CellFlatMapEntry(cell); } @Override public Entry ceilingEntry(Cell k) { - throw new UnsupportedOperationException(); + Cell cell = ceilingKey(k); + if (cell == null) { + return null; + } + return new CellFlatMapEntry(cell); } @Override public Entry floorEntry(Cell k) { - throw new UnsupportedOperationException(); + Cell cell = floorKey(k); + if (cell == null) { + return null; + } + return new CellFlatMapEntry(cell); } @Override public Entry firstEntry() { - throw new UnsupportedOperationException(); + Cell cell = firstKey(); + if (cell == null) { + return null; + } + return new CellFlatMapEntry(cell); } @Override public Entry lastEntry() { - throw new UnsupportedOperationException(); + Cell cell = lastKey(); + if (cell == null) { + return null; + } + return new CellFlatMapEntry(cell); } + // The following 2 methods (pollFirstEntry, pollLastEntry) are unsupported because these are updating methods. @Override public Entry pollFirstEntry() { throw new UnsupportedOperationException(); @@ -323,7 +371,6 @@ public abstract class CellFlatMap implements NavigableMap { throw new UnsupportedOperationException(); } - // -------------------------------- Updates -------------------------------- // All updating methods below are unsupported. // Assuming an array of Cells will be allocated externally, diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellSet.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellSet.java index 48262a9e153..6da57d35cf9 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellSet.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellSet.java @@ -126,15 +126,12 @@ public class CellSet implements NavigableSet { throw new UnsupportedOperationException("Not implemented"); } - // TODO: why do we have a double traversing through map? Recall we have Cell to Cell mapping... - // First for first/last key, which actually returns Cell and then get for the same Cell? - // TODO: Consider just return the first/lastKey(), should be twice more effective... public Cell first() { - return this.delegatee.get(this.delegatee.firstKey()); + return this.delegatee.firstEntry().getValue(); } public Cell last() { - return this.delegatee.get(this.delegatee.lastKey()); + return this.delegatee.lastEntry().getValue(); } public boolean add(Cell e) {