You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@omid.apache.org by oh...@apache.org on 2018/02/07 14:31:13 UTC

incubator-omid git commit: [OMID-85] Writing directly to HBase using specific version marks the write as a write that was done by a specific transaction. However, due to lack of shadow cells, getting the commit timestamp of the transaction can be done

Repository: incubator-omid
Updated Branches:
  refs/heads/phoenix-integration 7d6c03071 -> ea4c73954


[OMID-85] Writing directly to HBase using specific version marks the write as a write that was done by a specific transaction.
   However, due to lack of shadow cells, getting the commit timestamp of the transaction can be done only by access the commit table.
The motivation of this feature is to add the shadow cells during the write and save the commit table access.
 This feature is required by Apache Phoenix that during index creation adds the data table's entries, appeared before
 creation, to the index. In this case, the version and the commit timestamp should be the fence id and therefore, a direct write to HBase with the
 addition of shadow cells is required.


Project: http://git-wip-us.apache.org/repos/asf/incubator-omid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-omid/commit/ea4c7395
Tree: http://git-wip-us.apache.org/repos/asf/incubator-omid/tree/ea4c7395
Diff: http://git-wip-us.apache.org/repos/asf/incubator-omid/diff/ea4c7395

Branch: refs/heads/phoenix-integration
Commit: ea4c7395421fbd86d2dc2c9f7a53b16ae373f187
Parents: 7d6c030
Author: Ohad Shacham <oh...@yahoo-inc.com>
Authored: Wed Feb 7 16:29:47 2018 +0200
Committer: Ohad Shacham <oh...@yahoo-inc.com>
Committed: Wed Feb 7 16:29:47 2018 +0200

----------------------------------------------------------------------
 .../org/apache/omid/transaction/TTable.java     | 46 ++++++++++++--------
 .../omid/transaction/TestBasicTransaction.java  | 37 ++++++++++++++++
 2 files changed, 66 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/ea4c7395/hbase-client/src/main/java/org/apache/omid/transaction/TTable.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/omid/transaction/TTable.java b/hbase-client/src/main/java/org/apache/omid/transaction/TTable.java
index c408a25..658cbe6 100644
--- a/hbase-client/src/main/java/org/apache/omid/transaction/TTable.java
+++ b/hbase-client/src/main/java/org/apache/omid/transaction/TTable.java
@@ -316,6 +316,16 @@ public class TTable implements Closeable {
      * @throws IOException if a remote or network exception occurs.
      */
     public void put(Transaction tx, Put put) throws IOException {
+        put(tx, put, false);
+    }
+
+    /**
+     * @param put an instance of Put
+     * @param tx  an instance of transaction to be used
+     * @param autoCommit  denotes whether to automatically commit the put
+     * @throws IOException if a remote or network exception occurs.
+     */
+    public void put(Transaction tx, Put put, boolean autoCommit) throws IOException {
 
         throwExceptionIfOpSetsTimerange(put);
 
@@ -337,23 +347,25 @@ public class TTable implements Closeable {
                 Bytes.putLong(kv.getValueArray(), kv.getTimestampOffset(), writeTimestamp);
                 tsput.add(kv);
 
-                 byte[] conflictFree = put.getAttribute(CellUtils.CONFLICT_FREE_MUTATION);
-
-                 if (conflictFree != null && conflictFree[0]!=0) {
-                     transaction.addConflictFreeWriteSetElement(
-                             new HBaseCellId(table,
-                                     CellUtil.cloneRow(kv),
-                                     CellUtil.cloneFamily(kv),
-                                     CellUtil.cloneQualifier(kv),
-                                     kv.getTimestamp()));
-                 } else {
-                     transaction.addWriteSetElement(
-                             new HBaseCellId(table,
-                                     CellUtil.cloneRow(kv),
-                                     CellUtil.cloneFamily(kv),
-                                     CellUtil.cloneQualifier(kv),
-                                     kv.getTimestamp()));
-                 }
+                if (autoCommit) {
+                    tsput.add(CellUtil.cloneFamily(kv),
+                            CellUtils.addShadowCellSuffix(CellUtil.cloneQualifier(kv), 0, CellUtil.cloneQualifier(kv).length),
+                            kv.getTimestamp(),
+                            Bytes.toBytes(kv.getTimestamp()));
+                } else {
+                    byte[] conflictFree = put.getAttribute(CellUtils.CONFLICT_FREE_MUTATION);
+                    HBaseCellId cellId = new HBaseCellId(table,
+                            CellUtil.cloneRow(kv),
+                            CellUtil.cloneFamily(kv),
+                            CellUtil.cloneQualifier(kv),
+                            kv.getTimestamp());
+
+                    if (conflictFree != null && conflictFree[0]!=0) {
+                        transaction.addConflictFreeWriteSetElement(cellId);
+                    } else {
+                        transaction.addWriteSetElement(cellId);
+                    }
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-omid/blob/ea4c7395/hbase-client/src/test/java/org/apache/omid/transaction/TestBasicTransaction.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/test/java/org/apache/omid/transaction/TestBasicTransaction.java b/hbase-client/src/test/java/org/apache/omid/transaction/TestBasicTransaction.java
index a07be90..1b793a1 100644
--- a/hbase-client/src/test/java/org/apache/omid/transaction/TestBasicTransaction.java
+++ b/hbase-client/src/test/java/org/apache/omid/transaction/TestBasicTransaction.java
@@ -437,4 +437,41 @@ public class TestBasicTransaction extends OmidTestBase {
 
     }
 
+    @Test(timeOut = 30_000)
+    public void testAutoCommit(ITestContext context)
+            throws Exception {
+
+        TransactionManager tm = newTransactionManager(context);
+        TTable tt = new TTable(hbaseConf, TEST_TABLE);
+
+        byte[] rowName1 = Bytes.toBytes("row1");
+        byte[] famName1 = Bytes.toBytes(TEST_FAMILY);
+        byte[] colName1 = Bytes.toBytes("col1");
+        byte[] dataValue1 = Bytes.toBytes("testWrite-1");
+
+        Transaction tx1 = tm.begin();
+
+        Put row1 = new Put(rowName1);
+        row1.add(famName1, colName1, dataValue1);
+        tt.put(tx1, row1);
+
+        Transaction tx2 = tm.begin();
+
+        Transaction tx3 = tm.begin();
+
+        Get g = new Get(rowName1).setMaxVersions();
+        g.addColumn(famName1, colName1);
+        Result r = tt.get(tx3, g);
+        assertEquals(r.size(), 0, "Unexpected size for read.");
+
+        row1 = new Put(rowName1);
+        row1.add(famName1, colName1, dataValue1);
+        tt.put(tx2, row1, true);
+
+        r = tt.get(tx3, g);
+        assertEquals(r.size(), 1, "Unexpected size for read.");
+
+        tt.close();
+    }
+
 }