You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@omid.apache.org by yo...@apache.org on 2019/02/25 11:55:05 UTC

[incubator-omid] 02/02: [OMID-133] When TTable autoflush is false, before read/scan flush tables.

This is an automated email from the ASF dual-hosted git repository.

yonigo pushed a commit to branch 1.0.1
in repository https://gitbox.apache.org/repos/asf/incubator-omid.git

commit d30f70930f416e8234be7778fcccaca7984653ee
Author: Yonatan Gottesman <yo...@gmail.com>
AuthorDate: Mon Feb 25 12:32:51 2019 +0200

    [OMID-133] When TTable autoflush is false, before read/scan flush tables.
---
 .../src/main/java/org/apache/omid/transaction/TTable.java     | 11 ++++++++---
 .../test/java/org/apache/omid/transaction/TestAutoFlush.java  |  4 ++++
 2 files changed, 12 insertions(+), 3 deletions(-)

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 44f0708..869a013 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
@@ -181,6 +181,8 @@ public class TTable implements Closeable {
 
         throwExceptionIfOpSetsTimerange(get);
 
+        flushCommits();
+
         HBaseTransaction transaction = enforceHBaseTransactionAsParam(tx);
 
         final long readTimestamp = transaction.getReadTimestamp();
@@ -466,7 +468,7 @@ public class TTable implements Closeable {
     public ResultScanner getScanner(Transaction tx, Scan scan) throws IOException {
 
         throwExceptionIfOpSetsTimerange(scan);
-
+        flushCommits();
         HBaseTransaction transaction = enforceHBaseTransactionAsParam(tx);
 
         Scan tsscan = new Scan(scan);
@@ -670,8 +672,9 @@ public class TTable implements Closeable {
         return table;
     }
 
-    public void setAutoFlush(boolean autoFlush) {
+    public void setAutoFlush(boolean autoFlush) throws IOException {
         this.autoFlush = autoFlush;
+        flushCommits();
     }
 
     public boolean isAutoFlush() {
@@ -680,7 +683,9 @@ public class TTable implements Closeable {
 
     public void flushCommits() throws IOException {
         try {
-            table.batch(this.mutations, new Object[mutations.size()]);
+            if (this.mutations.size() > 0) {
+                table.batch(this.mutations, new Object[mutations.size()]);
+            }
         } catch (InterruptedException e) {
             Thread.interrupted();
             throw new RuntimeException(e);
diff --git a/hbase-client/src/test/java/org/apache/omid/transaction/TestAutoFlush.java b/hbase-client/src/test/java/org/apache/omid/transaction/TestAutoFlush.java
index fac64ac..ac0a3f0 100644
--- a/hbase-client/src/test/java/org/apache/omid/transaction/TestAutoFlush.java
+++ b/hbase-client/src/test/java/org/apache/omid/transaction/TestAutoFlush.java
@@ -52,6 +52,10 @@ public class TestAutoFlush extends OmidTestBase {
         Result result = table.getHTable().get(get);
         assertEquals(result.size(), 0, "Writes are already in DB");
 
+        //data should be readable within same transaction
+        result = table.get(t,get);
+        assertEquals(result.size(), 1, "Writes should be read by same transaction");
+
         tm.commit(t);
 
         // After commit, both the cell and shadow cell should be there.