kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From granthe...@apache.org
Subject [kudu] branch master updated: [java] Add unit tests demonstrating good behavior of scan tokens when range partitions are dropped
Date Thu, 13 Jun 2019 20:55:02 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new c430886  [java] Add unit tests demonstrating good behavior of scan tokens when range
partitions are dropped
c430886 is described below

commit c4308869580c6cb8b57a809395883a0b2614f883
Author: Will Berkeley <wdberkeley@gmail.com>
AuthorDate: Fri Jun 7 14:04:53 2019 -0700

    [java] Add unit tests demonstrating good behavior of scan tokens when range partitions
are dropped
    
    It turns out that scan tokens in the Java client behave nicely with
    respect to dropping range partitions- one can drop a range partition
    anytime after creating the tokens and the tokens can still be used.
    There is a case where some tablets in the dropped partition will still
    return rows, while others don't, but that can be looked at as a
    manifestation of the fact that tablet alters aren't linearizable in Kudu
    (yet?).
    
    Change-Id: Ib25ea2b62321934313c9c8852f0bc00b28bf7f2b
    Reviewed-on: http://gerrit.cloudera.org:8080/13565
    Reviewed-by: Adar Dembo <adar@cloudera.com>
    Reviewed-by: Grant Henke <granthenke@apache.org>
    Tested-by: Kudu Jenkins
---
 .../java/org/apache/kudu/client/TestScanToken.java | 68 +++++++++++++++++++++-
 1 file changed, 67 insertions(+), 1 deletion(-)

diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestScanToken.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestScanToken.java
index da5758e..1d2da18 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestScanToken.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestScanToken.java
@@ -19,6 +19,7 @@ package org.apache.kudu.client;
 
 import com.google.common.collect.ImmutableList;
 import org.apache.kudu.ColumnSchema;
+import org.apache.kudu.client.KuduScanner;
 import org.apache.kudu.Schema;
 import org.apache.kudu.Type;
 import org.apache.kudu.test.KuduTestHarness;
@@ -29,15 +30,16 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import static org.apache.kudu.test.ClientTestUtil.countRowsInScan;
 import static org.apache.kudu.test.ClientTestUtil.countScanTokenRows;
+import static org.apache.kudu.test.ClientTestUtil.createBasicSchemaInsert;
 import static org.apache.kudu.test.ClientTestUtil.createDefaultTable;
 import static org.apache.kudu.test.ClientTestUtil.createManyStringsSchema;
 import static org.apache.kudu.test.ClientTestUtil.getBasicSchema;
 import static org.apache.kudu.test.ClientTestUtil.loadDefaultTable;
-import static org.apache.kudu.test.ClientTestUtil.scanTableToStrings;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -274,6 +276,70 @@ public class TestScanToken {
     assertEquals(0, countRowsInScan(token.intoScanner(client)));
   }
 
+  /**
+   * Tests scan token creation and execution on a table with interleaved range partition
drops.
+   */
+  @Test
+  public void testScanTokensInterleavedRangePartitionDrops() throws Exception {
+    Schema schema = getBasicSchema();
+    CreateTableOptions createOptions = new CreateTableOptions();
+    createOptions.addHashPartitions(ImmutableList.of("key"), 2);
+
+    final int numRows = 30;
+    PartialRow lower0 = schema.newPartialRow();
+    PartialRow upper0 = schema.newPartialRow();
+    lower0.addInt("key", 0);
+    upper0.addInt("key", numRows / 3);
+    createOptions.addRangePartition(lower0, upper0);
+
+    PartialRow lower1 = schema.newPartialRow();
+    PartialRow upper1 = schema.newPartialRow();
+    lower1.addInt("key", numRows / 3);
+    upper1.addInt("key", 2 * numRows / 3);
+    createOptions.addRangePartition(lower1, upper1);
+
+    PartialRow lower2 = schema.newPartialRow();
+    PartialRow upper2 = schema.newPartialRow();
+    lower2.addInt("key", 2 * numRows / 3);
+    upper2.addInt("key", numRows);
+    createOptions.addRangePartition(lower2, upper2);
+
+    KuduTable table = client.createTable(testTableName, schema, createOptions);
+    KuduSession session = client.newSession();
+    for (int i = 0; i < numRows; i++) {
+      session.apply(createBasicSchemaInsert(table, i));
+    }
+
+    // Build the scan tokens.
+    List<KuduScanToken> tokens = client.newScanTokenBuilder(table).build();
+    assertEquals(6, tokens.size());
+
+    // Drop the range partition [10, 20).
+    AlterTableOptions dropMiddleOptions = new AlterTableOptions();
+    dropMiddleOptions.dropRangePartition(lower1, upper1);
+    client.alterTable(table.getName(), dropMiddleOptions);
+
+    // Rehydrate the tokens.
+    List<KuduScanner> scanners = new ArrayList<>();
+    for (KuduScanToken token : tokens) {
+      scanners.add(token.intoScanner(client));
+    }
+
+    // Drop the range partition [20, 30).
+    AlterTableOptions dropEndOptions = new AlterTableOptions();
+    dropEndOptions.dropRangePartition(lower2, upper2);
+    client.alterTable(table.getName(), dropEndOptions);
+
+    // Check the scanners work. The scanners for the tablets in the range [10, 20) definitely
won't
+    // see any rows. The scanners for the tablets in the range [20, 30) might see rows.
+    int scannedRows = 0;
+    for (KuduScanner scanner : scanners) {
+      scannedRows += countRowsInScan(scanner);
+    }
+    assertTrue(String.format("%d >= %d / 3?", scannedRows, numRows), scannedRows >=
numRows / 3);
+    assertTrue(String.format("%d <= 2 * %d / 3?", scannedRows, numRows), scannedRows <=
2 * numRows / 3);
+  }
+
   /** Test that scanRequestTimeout makes it from the scan token to the underlying Scanner
class. */
   @Test
   public void testScanRequestTimeout() throws IOException {


Mime
View raw message