PHOENIX-2855 Workaround Increment TimeRange not being serialized for HBase 1.2


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1161ab16
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1161ab16
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1161ab16

Branch: refs/heads/4.x-HBase-1.0
Commit: 1161ab16af40bdfc045268bfb2fe1c184c9cefb8
Parents: 3dafacb
Author: James Taylor <[email protected]>
Authored: Fri Apr 22 18:26:34 2016 -0700
Committer: James Taylor <[email protected]>
Committed: Fri Apr 22 18:48:08 2016 -0700

----------------------------------------------------------------------
 .../coprocessor/SequenceRegionObserver.java     |  7 +++++++
 .../org/apache/phoenix/schema/Sequence.java     | 20 ++++++++++++++++----
 2 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1161ab16/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
index 4bc1ef5..2e2d580 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
@@ -132,6 +132,13 @@ public class SequenceRegionObserver extends 
BaseRegionObserver {
                     for (Cell cq : entry.getValue()) {
                        long value = Bytes.toLong(cq.getValueArray(), 
cq.getValueOffset());
                         get.addColumn(cf, CellUtil.cloneQualifier(cq));
+                        long cellTimestamp = cq.getTimestamp();
+                        // Workaround HBASE-15698 by using the lowest of the 
timestamps found
+                        // on the Increment or any of its Cells.
+                        if (cellTimestamp > 0 && cellTimestamp < maxTimestamp) 
{
+                            maxTimestamp = cellTimestamp;
+                            
get.setTimeRange(MetaDataProtocol.MIN_TABLE_TIMESTAMP, maxTimestamp);
+                        }
                         validateOnly &= 
(Sequence.ValueOp.VALIDATE_SEQUENCE.ordinal() == value);
                     }
                 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1161ab16/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
index 9c1a74b..9598ace 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
@@ -350,9 +350,10 @@ public class Sequence {
     }
 
 
-    @SuppressWarnings("deprecation")
     public Increment newIncrement(long timestamp, Sequence.ValueOp action, 
long numToAllocate) {
-        Increment inc = new Increment(key.getKey());
+        byte[] incKey = key.getKey();
+        byte[] incValue = Bytes.toBytes((long)action.ordinal());
+        Increment inc = new Increment(incKey);
         // It doesn't matter what we set the amount too - we always use the 
values we get
         // from the Get we do to prevent any race conditions. All columns that 
get added
         // are returned with their current value
@@ -363,8 +364,19 @@ public class Sequence {
             throw new RuntimeException(e); // Impossible
         }
         for (KeyValue kv : SEQUENCE_KV_COLUMNS) {
-            // We don't care about the amount, as we'll add what gets looked 
up on the server-side
-            inc.addColumn(kv.getFamily(), kv.getQualifier(), action.ordinal());
+            try {
+                // Store the timestamp on the cell as well as HBase 1.2 seems 
to not
+                // be serializing over the time range (see HBASE-15698).
+                Cell cell = new KeyValue(incKey, 0, incKey.length, 
+                        kv.getFamilyArray(), kv.getFamilyOffset(), 
kv.getFamilyLength(),
+                        kv.getQualifierArray(), kv.getQualifierOffset(), 
kv.getQualifierLength(),
+                        timestamp,
+                        KeyValue.Type.Put,
+                        incValue, 0, incValue.length);
+                inc.add(cell);
+            } catch (IOException e) {
+                throw new RuntimeException(e); // Impossible
+            }
         }
         return inc;
     }

Reply via email to