You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by bu...@apache.org on 2017/08/20 21:30:28 UTC

[31/50] [abbrv] hbase git commit: HBASE-18251 Remove unnecessary traversing to the first and last keys in the CellSet (Toshihoro Suzuki)

HBASE-18251 Remove unnecessary traversing to the first and last keys in
the CellSet (Toshihoro Suzuki)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/9da4e690
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/9da4e690
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/9da4e690

Branch: refs/heads/HBASE-18467
Commit: 9da4e6906e9d7f62b8a8fe5dc996b066dac4066e
Parents: b087818
Author: Ramkrishna <ra...@intel.com>
Authored: Wed Aug 16 11:05:43 2017 +0530
Committer: Ramkrishna <ra...@intel.com>
Committed: Wed Aug 16 11:06:31 2017 +0530

----------------------------------------------------------------------
 .../hadoop/hbase/regionserver/CellFlatMap.java  | 63 +++++++++++++++++---
 .../hadoop/hbase/regionserver/CellSet.java      |  7 +--
 2 files changed, 57 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/9da4e690/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellFlatMap.java
----------------------------------------------------------------------
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 c83a382..aff6018 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<Cell,Cell> {
   }
 
   // -------------------------------- Entry's getters --------------------------------
-  // all interfaces returning Entries are unsupported because we are dealing only with the keys
+
+  private static class CellFlatMapEntry implements Entry<Cell, Cell> {
+    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<Cell, Cell> lowerEntry(Cell k) {
-    throw new UnsupportedOperationException();
+    Cell cell = lowerKey(k);
+    if (cell == null) {
+      return null;
+    }
+    return new CellFlatMapEntry(cell);
   }
 
   @Override
   public Entry<Cell, Cell> higherEntry(Cell k) {
-    throw new UnsupportedOperationException();
+    Cell cell = higherKey(k);
+    if (cell == null) {
+      return null;
+    }
+    return new CellFlatMapEntry(cell);
   }
 
   @Override
   public Entry<Cell, Cell> ceilingEntry(Cell k) {
-    throw new UnsupportedOperationException();
+    Cell cell = ceilingKey(k);
+    if (cell == null) {
+      return null;
+    }
+    return new CellFlatMapEntry(cell);
   }
 
   @Override
   public Entry<Cell, Cell> floorEntry(Cell k) {
-    throw new UnsupportedOperationException();
+    Cell cell = floorKey(k);
+    if (cell == null) {
+      return null;
+    }
+    return new CellFlatMapEntry(cell);
   }
 
   @Override
   public Entry<Cell, Cell> firstEntry() {
-    throw new UnsupportedOperationException();
+    Cell cell = firstKey();
+    if (cell == null) {
+      return null;
+    }
+    return new CellFlatMapEntry(cell);
   }
 
   @Override
   public Entry<Cell, Cell> 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<Cell, Cell> pollFirstEntry() {
     throw new UnsupportedOperationException();
@@ -323,7 +371,6 @@ public abstract class CellFlatMap implements NavigableMap<Cell,Cell> {
     throw new UnsupportedOperationException();
   }
 
-
   // -------------------------------- Updates --------------------------------
   // All updating methods below are unsupported.
   // Assuming an array of Cells will be allocated externally,

http://git-wip-us.apache.org/repos/asf/hbase/blob/9da4e690/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellSet.java
----------------------------------------------------------------------
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 48262a9..6da57d3 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<Cell>  {
     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) {