hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkris...@apache.org
Subject hbase git commit: HBASE-18251 Remove unnecessary traversing to the first and last keys in the CellSet (Toshihoro Suzuki)
Date Wed, 16 Aug 2017 06:12:53 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-2 b2afd6c24 -> 8fa637103


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/8fa63710
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/8fa63710
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/8fa63710

Branch: refs/heads/branch-2
Commit: 8fa6371039e21cee1c7f76d299786a2fb5ed68ee
Parents: b2afd6c
Author: Ramkrishna <ramkrishna.s.vasudevan@intel.com>
Authored: Wed Aug 16 11:05:43 2017 +0530
Committer: Ramkrishna <ramkrishna.s.vasudevan@intel.com>
Committed: Wed Aug 16 11:42:40 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/8fa63710/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/8fa63710/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) {


Mime
View raw message