Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.2 687d04cb5 -> 332caa000
PHOENIX-4576 Fix LocalIndexSplitMergeIT tests failing in master branch - addendum(Rajeshbabu) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/332caa00 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/332caa00 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/332caa00 Branch: refs/heads/4.x-HBase-1.2 Commit: 332caa000024a01562945e18b5e7ea43d816593e Parents: 687d04c Author: Rajeshbabu Chintaguntla <rajeshb...@apache.org> Authored: Tue Mar 20 19:38:03 2018 +0530 Committer: Rajeshbabu Chintaguntla <rajeshb...@apache.org> Committed: Tue Mar 20 19:38:03 2018 +0530 ---------------------------------------------------------------------- .../phoenix/end2end/LocalIndexSplitMergeIT.java | 59 ++++++++++++++++++++ .../IndexHalfStoreFileReaderGenerator.java | 8 ++- 2 files changed, 65 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/332caa00/phoenix-core/src/it/java/org/apache/phoenix/end2end/LocalIndexSplitMergeIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LocalIndexSplitMergeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LocalIndexSplitMergeIT.java index 409e98f..dc3e5d3 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/LocalIndexSplitMergeIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/LocalIndexSplitMergeIT.java @@ -263,4 +263,63 @@ public class LocalIndexSplitMergeIT extends BaseTest { } } + @Test + public void testLocalIndexScanWithMergeSpecialCase() throws Exception { + String schemaName = generateUniqueName(); + String tableName = schemaName + "." + generateUniqueName(); + String indexName = "IDX_" + generateUniqueName(); + TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false); + createBaseTable(tableName, "('a','aaaab','def')"); + Connection conn1 = getConnectionForLocalIndexTest(); + try { + String[] strings = + { "aa", "aaa", "aaaa", "bb", "cc", "dd", "dff", "g", "h", "i", "j", "k", "l", + "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; + for (int i = 0; i < 26; i++) { + conn1.createStatement() + .execute("UPSERT INTO " + tableName + " values('" + strings[i] + "'," + i + + "," + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')"); + } + conn1.commit(); + conn1.createStatement() + .execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)"); + conn1.createStatement() + .execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)"); + + HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin(); + List<HRegionInfo> regionsOfUserTable = + MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), + admin.getConnection(), physicalTableName, false); + admin.mergeRegions(regionsOfUserTable.get(0).getEncodedNameAsBytes(), + regionsOfUserTable.get(1).getEncodedNameAsBytes(), false); + regionsOfUserTable = + MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), + admin.getConnection(), physicalTableName, false); + + while (regionsOfUserTable.size() != 3) { + Thread.sleep(100); + regionsOfUserTable = + MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), + admin.getConnection(), physicalTableName, false); + } + String query = "SELECT t_id,k1,v1 FROM " + tableName; + ResultSet rs = conn1.createStatement().executeQuery(query); + for (int j = 0; j < 26; j++) { + assertTrue(rs.next()); + assertEquals(strings[25-j], rs.getString("t_id")); + assertEquals(25-j, rs.getInt("k1")); + assertEquals(strings[j], rs.getString("V1")); + } + query = "SELECT t_id,k1,k3 FROM " + tableName; + rs = conn1.createStatement().executeQuery(query); + for (int j = 0; j < 26; j++) { + assertTrue(rs.next()); + assertEquals(strings[j], rs.getString("t_id")); + assertEquals(j, rs.getInt("k1")); + assertEquals(j + 2, rs.getInt("k3")); + } + } finally { + conn1.close(); + } + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/332caa00/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java index 12fa47a..e41086b 100644 --- a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java +++ b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/IndexHalfStoreFileReaderGenerator.java @@ -17,6 +17,8 @@ */ package org.apache.hadoop.hbase.regionserver; +import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_START_ROW_SUFFIX; + import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; @@ -366,8 +368,10 @@ public class IndexHalfStoreFileReaderGenerator extends BaseRegionObserver { // If the region start key is not the prefix of the scan start row then we can return empty // scanners. This is possible during merge where one of the child region scan should not return any // results as we go through merged region. - if (Bytes.compareTo(scan.getStartRow(), 0, startKey.length == 0 ? endKey.length - : startKey.length, startKey.length == 0 ? new byte[endKey.length] : startKey, 0, + int prefixLength = + scan.getAttribute(SCAN_START_ROW_SUFFIX) == null ? (startKey.length == 0 ? endKey.length + : startKey.length) : (scan.getStartRow().length - scan.getAttribute(SCAN_START_ROW_SUFFIX).length); + if (Bytes.compareTo(scan.getStartRow(), 0, prefixLength, (startKey.length == 0 ? new byte[endKey.length] : startKey), 0, startKey.length == 0 ? endKey.length : startKey.length) != 0) { return keyValueScanners; }