Repository: phoenix Updated Branches: refs/heads/3.0 507476b9b -> 8be081fdc
New test to repro skip scan after manual splits Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/8be081fd Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/8be081fd Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/8be081fd Branch: refs/heads/3.0 Commit: 8be081fdc29fc49d57492adf9c99d72b2e4b8092 Parents: 507476b Author: James Taylor <jtay...@salesforce.com> Authored: Mon Jul 28 13:05:56 2014 -0700 Committer: James Taylor <jtay...@salesforce.com> Committed: Mon Jul 28 13:05:56 2014 -0700 ---------------------------------------------------------------------- .../end2end/SkipScanAfterManualSplit.java | 100 ++----------------- 1 file changed, 8 insertions(+), 92 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/8be081fd/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanAfterManualSplit.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanAfterManualSplit.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanAfterManualSplit.java index 99405f2..219f6f0 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanAfterManualSplit.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanAfterManualSplit.java @@ -27,15 +27,10 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.List; import java.util.Map; -import java.util.Random; -import java.util.Set; import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.client.HBaseAdmin; -import org.apache.hadoop.hbase.client.HTableInterface; -import org.apache.hadoop.hbase.client.ResultScanner; -import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.util.Bytes; import org.apache.phoenix.jdbc.PhoenixConnection; import org.apache.phoenix.query.ConnectionQueryServices; @@ -48,7 +43,6 @@ import org.junit.experimental.categories.Category; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; @Category(HBaseManagedTimeTest.class) public class SkipScanAfterManualSplit extends BaseHBaseManagedTimeIT { @@ -64,13 +58,10 @@ public class SkipScanAfterManualSplit extends BaseHBaseManagedTimeIT { } PAYLOAD = buf.toString(); } - //private static final String SPLIT_POINT = "j"; private static final String TABLE_NAME = "S"; private static final byte[] TABLE_NAME_BYTES = Bytes.toBytes(TABLE_NAME); private static final int MIN_CHAR = 'a'; private static final int MAX_CHAR = 'z'; - //private static final int PERC_TO_SELECT = 4; - private static final Random RAND = new Random(); @BeforeClass @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class) @@ -112,16 +103,6 @@ public class SkipScanAfterManualSplit extends BaseHBaseManagedTimeIT { conn.close(); } - public static int doFullScan(ConnectionQueryServices services) throws Exception{ - HTableInterface ht = services.getTable(TABLE_NAME_BYTES); - ResultScanner scanner = ht.getScanner(new Scan()); - int count = 0; - while (scanner.next() != null) { - count++; - } - return count; - } - private static void traceRegionBoundaries(ConnectionQueryServices services) throws Exception { List<String> boundaries = Lists.newArrayList(); List<HRegionLocation> regions = services.getAllTableRegions(TABLE_NAME_BYTES); @@ -131,20 +112,6 @@ public class SkipScanAfterManualSplit extends BaseHBaseManagedTimeIT { System.out.println("Region boundaries:\n" + boundaries); } - protected int getTotalRows() { - return (MAX_CHAR - MIN_CHAR) * (MAX_CHAR - MIN_CHAR); - } - protected Set<String> getRandomRows(int nRows) { - Set<String> pks = Sets.newHashSetWithExpectedSize(nRows); - while (pks.size() < nRows) { - int c1 = MIN_CHAR + (Math.abs(RAND.nextInt()) % (MAX_CHAR - MIN_CHAR)); - int c2 = MIN_CHAR + (Math.abs(RAND.nextInt()) % (MAX_CHAR - MIN_CHAR)); - String pk = Character.toString((char)c1) + Character.toString((char)c2); - pks.add(pk); - } - return pks; - } - @Ignore @Test public void testManualSplit() throws Exception { @@ -163,76 +130,25 @@ public class SkipScanAfterManualSplit extends BaseHBaseManagedTimeIT { nRegions = services.getAllTableRegions(TABLE_NAME_BYTES).size(); nTries++; } + // Split finished by this time, but cache isn't updated until + // table is accessed assertEquals(nRegions, nInitialRegions); - /* works - nTries = 0; - while (nRegions == nInitialRegions && nTries < 10) { - Thread.sleep(1000); - int count = doFullScan(services); - assertEquals(26, count); - nRegions = services.getAllTableRegions(TABLE_NAME_BYTES).size(); - nTries++; - } - assertNotEquals(nRegions, nInitialRegions); - */ - /* - nTries = 0; - while (nRegions == nInitialRegions && nTries < 10) { - Thread.sleep(1000); - ResultSet rs = conn.createStatement().executeQuery("SELECT count(*) FROM " + TABLE_NAME); - assertTrue(rs.next()); - assertEquals(26, rs.getInt(1)); - nRegions = services.getAllTableRegions(TABLE_NAME_BYTES).size(); - nTries++; - } - assertNotEquals(nRegions, nInitialRegions); - */ - /* - String select1 = "SELECT "; - StringBuilder buf = new StringBuilder("count(*) FROM " + TABLE_NAME + " WHERE a IN ("); - int nRows = getTotalRows() * PERC_TO_SELECT / 100; - for (int i = 0; i < nRows; i++) { - buf.append("?,"); - } - buf.setCharAt(buf.length()-1, ')'); - String query = buf.toString(); - */ int nRows = 25; String query = "SELECT count(*) FROM S WHERE a IN ('tl','jt','ju','rj','hj','vt','hh','br','ga','vn','th','sv','dl','mj','is','op','ug','sq','mv','qe','kq','xy','ek','aa','ae')"; - /* - PreparedStatement stmt1 = conn.prepareStatement(select1 + query); - PreparedStatement stmt2 = conn.prepareStatement(select2 + query); - int param = 1; - List<String> pks = Lists.newArrayList(); - for (String pk : getRandomRows(nRows)) { - stmt1.setString(param, pk); - stmt2.setString(param, pk); - pks.add(pk); - param++; - } - ResultSet rs1 = stmt1.executeQuery(); - */ ResultSet rs1 = conn.createStatement().executeQuery(query); assertTrue(rs1.next()); - //ResultSet rs2 = stmt2.executeQuery(); - //assertTrue(rs2.next()); traceRegionBoundaries(services); nRegions = services.getAllTableRegions(TABLE_NAME_BYTES).size(); + // Region cache has been updated, as there are more regions now assertNotEquals(nRegions, nInitialRegions); - //assertEquals(nRows, rs2.getInt(1)); if (nRows != rs1.getInt(1)) { - ResultSet rs3 = conn.createStatement().executeQuery(query); - assertTrue(rs3.next()); - assertEquals(nRows, rs3.getInt(1)); - } - /* - StringBuilder failedStmt = new StringBuilder("SELECT count(*) FROM " + TABLE_NAME + " WHERE a IN ("); - for (String pk : pks) { - failedStmt.append("'" + pk + "',"); + // Run the same query again and it always passes now + // (as region cache is up-to-date) + ResultSet r2 = conn.createStatement().executeQuery(query); + assertTrue(r2.next()); + assertEquals(nRows, r2.getInt(1)); } - failedStmt.setCharAt(failedStmt.length()-1, ')'); - */ assertEquals(nRows, rs1.getInt(1)); } finally { admin.close();