You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2019/01/28 23:58:24 UTC

[kudu] 04/05: [java] deflake RYW tests in TestKuduClient

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

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit c7c902a08b8229612078357c7bb65927e4e4dbac
Author: Hao Hao <ha...@cloudera.com>
AuthorDate: Sun Jan 27 12:48:04 2019 -0800

    [java] deflake RYW tests in TestKuduClient
    
    RYW tests in TestKuduClient is flaky which fails with AssertionError
    when verifying the chosen snapshot timestamp returned from the server
    is larger than the previous propagated timestamp before the scan.
    
    It turns out to be a test only issue, which due to incorrect structure
    of the test. It aims to test READ_YOUR_WRITE mode for multiple clients,
    while the same client was being used. The distinction is important,
    because we want to ensure a single client can still preserve
    read-your-writes and read-your-reads session guarantees even there are
    concurrent reads/writes performed by other clients in READ_YOUR_WRITE
    scan mode.
    
    Without the fix, 192/1000 runs of TestKuduClient failed with this error.
    With the fix, 0/1000 runs of TestKuduClient failed.
    
    Change-Id: I951abb9197f7e6b6a4c70cdf89948206840ddeda
    Reviewed-on: http://gerrit.cloudera.org:8080/12276
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <ad...@cloudera.com>
---
 .../java/org/apache/kudu/client/AsyncKuduScanner.java |  4 ++--
 .../java/org/apache/kudu/client/TestKuduClient.java   | 19 +++++++++++++------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduScanner.java b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduScanner.java
index 71b1146..36bb0af 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduScanner.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduScanner.java
@@ -421,8 +421,8 @@ public final class AsyncKuduScanner {
               resp.scanTimestamp != AsyncKuduClient.NO_TIMESTAMP) {
             // If the server-assigned timestamp is present in the tablet
             // server's response, store it in the scanner. The stored value
-            // is used for read operations at other tablet servers in the
-            // context of the same scan.
+            // is used for read operations in READ_AT_SNAPSHOT mode at
+            // other tablet servers in the context of the same scan.
             htTimestamp = resp.scanTimestamp;
           }
 
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
index e11a58e..930abf2 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
@@ -1056,11 +1056,17 @@ public class TestKuduClient {
       Callable<Void> callable = new Callable<Void>() {
         @Override
         public Void call() throws Exception {
+          // Create a new client.
+          AsyncKuduClient asyncKuduClient = new AsyncKuduClient
+                  .AsyncKuduClientBuilder(harness.getMasterAddressesAsString())
+                  .defaultAdminOperationTimeoutMs(harness.DEFAULT_SLEEP)
+                  .build();
           // From the same client continuously performs inserts to a tablet
           // in the given flush mode.
-          KuduSession session = client.newSession();
+          KuduClient kuduClient = asyncKuduClient.syncClient();
+          KuduSession session = kuduClient.newSession();
           session.setFlushMode(flushMode);
-          KuduTable table = client.openTable(TABLE_NAME);
+          KuduTable table = kuduClient.openTable(TABLE_NAME);
           for (int i = 0; i < 3; i++) {
             for (int j = 100 * i; j < 100 * (i + 1); j++) {
               Insert insert = table.newInsert();
@@ -1079,14 +1085,13 @@ public class TestKuduClient {
             // reads will not "go back in time" regarding writes that other
             // clients have done.
             for (int k = 0; k < 3; k++) {
-              AsyncKuduScanner scanner = asyncClient.newScannerBuilder(table)
+              AsyncKuduScanner scanner = asyncKuduClient.newScannerBuilder(table)
                       .readMode(AsyncKuduScanner.ReadMode.READ_YOUR_WRITES)
                       .replicaSelection(replicaSelection)
                       .build();
               KuduScanner syncScanner = new KuduScanner(scanner);
-              long preTs = asyncClient.getLastPropagatedTimestamp();
-              assertNotEquals(AsyncKuduClient.NO_TIMESTAMP,
-                  asyncClient.getLastPropagatedTimestamp());
+              long preTs = asyncKuduClient.getLastPropagatedTimestamp();
+              assertNotEquals(AsyncKuduClient.NO_TIMESTAMP, preTs);
 
               long row_count = countRowsInScan(syncScanner);
               long expected_count = 100L * (i + 1);
@@ -1100,6 +1105,8 @@ public class TestKuduClient {
               syncScanner.close();
             }
           }
+
+          kuduClient.close();
           return null;
         }
       };