PHOENIX-4459 Region assignments are failing for the test cases with extended clocks to support SCN(Sergey Soldatov)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/c489587e Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/c489587e Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/c489587e Branch: refs/heads/master Commit: c489587e4ee91be922e7dca2ee7f1aba47d75a4d Parents: eeea6c6 Author: Ankit Singhal <ankitsingha...@gmail.com> Authored: Fri Jun 1 14:10:15 2018 -0700 Committer: Ankit Singhal <ankitsingha...@gmail.com> Committed: Fri Jun 1 14:10:15 2018 -0700 ---------------------------------------------------------------------- .../phoenix/end2end/ConcurrentMutationsIT.java | 76 +++++--------- .../end2end/ExplainPlanWithStatsEnabledIT.java | 17 ++- .../end2end/index/PartialIndexRebuilderIT.java | 105 +++---------------- 3 files changed, 54 insertions(+), 144 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/c489587e/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java index 01133f1..ffc1049 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java @@ -55,7 +55,6 @@ import org.junit.Test; import org.junit.runner.RunWith; @RunWith(RunUntilFailure.class) -@Ignore public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { private static final Random RAND = new Random(5); private static final String MVCC_LOCK_TEST_TABLE_PREFIX = "MVCCLOCKTEST_"; @@ -66,6 +65,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { private static class MyClock extends EnvironmentEdge { public volatile long time; + boolean shouldAdvance = true; public MyClock (long time) { this.time = time; @@ -73,7 +73,14 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { @Override public long currentTime() { - return time; + if (shouldAdvance) { + return time++; + } else { + return time; + } + } + public void setAdvance(boolean val) { + shouldAdvance = val; } } @@ -422,21 +429,15 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { String tableName = generateUniqueName(); String indexName = generateUniqueName(); Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); - long ts = 1000; - clock.time = ts; - Connection conn = DriverManager.getConnection(getUrl(), props); + Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0"); conn.close(); - ts = 1010; - clock.time = ts; conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)"); conn.close(); - ts = 1020; - clock.time = ts; - conn = DriverManager.getConnection(getUrl(), props); + conn = DriverManager.getConnection(getUrl(), props); PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')"); stmt.setTimestamp(1, new Timestamp(1000L)); stmt.executeUpdate(); @@ -444,8 +445,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { conn.close(); Timestamp expectedTimestamp; - ts = 1040; - clock.time = ts; + clock.setAdvance(false); conn = DriverManager.getConnection(getUrl(), props); stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)"); expectedTimestamp = null; @@ -455,10 +455,9 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { stmt.setTimestamp(1, new Timestamp(3000L)); stmt.executeUpdate(); conn.commit(); + clock.setAdvance(true); conn.close(); - ts = 1050; - clock.time = ts; conn = DriverManager.getConnection(getUrl(), props); IndexScrutiny.scrutinizeIndex(conn, tableName, indexName); @@ -489,21 +488,15 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { String tableName = generateUniqueName(); String indexName = generateUniqueName(); Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); - long ts = 1000; - clock.time = ts; - Connection conn = DriverManager.getConnection(getUrl(), props); + Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); conn.close(); - ts = 1010; - clock.time = ts; conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)"); conn.close(); - ts = 1020; - clock.time = ts; - conn = DriverManager.getConnection(getUrl(), props); + conn = DriverManager.getConnection(getUrl(), props); PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')"); stmt.setTimestamp(1, new Timestamp(1000L)); stmt.executeUpdate(); @@ -511,8 +504,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { conn.close(); Timestamp expectedTimestamp; - ts = 1040; - clock.time = ts; + clock.setAdvance(false); conn = DriverManager.getConnection(getUrl(), props); stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)"); expectedTimestamp = null; @@ -522,11 +514,10 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { expectedTimestamp = new Timestamp(3000L); stmt.setTimestamp(1, expectedTimestamp); stmt.executeUpdate(); + clock.setAdvance(true); conn.commit(); conn.close(); - ts = 1050; - clock.time = ts; conn = DriverManager.getConnection(getUrl(), props); IndexScrutiny.scrutinizeIndex(conn, tableName, indexName); @@ -630,16 +621,10 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, A.V VARCHAR, B.V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); conn.close(); - - ts = 1010; - clock.time = ts; conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)"); conn.close(); - - ts = 1020; - clock.time = ts; - conn = DriverManager.getConnection(getUrl(), props); + conn = DriverManager.getConnection(getUrl(), props); PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0','1')"); stmt.setTimestamp(1, new Timestamp(1000L)); stmt.executeUpdate(); @@ -647,21 +632,19 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { conn.close(); Timestamp expectedTimestamp; - ts = 1040; - clock.time = ts; + clock.setAdvance(false); conn = DriverManager.getConnection(getUrl(), props); stmt = conn.prepareStatement("DELETE FROM " + tableName + " WHERE (K1,K2) = ('aa','aa')"); stmt.executeUpdate(); conn.commit(); - expectedTimestamp = new Timestamp(3000L); + expectedTimestamp = new Timestamp(6000L); stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null,'3')"); stmt.setTimestamp(1, expectedTimestamp); stmt.executeUpdate(); conn.commit(); + clock.setAdvance(true); conn.close(); - ts = 1050; - clock.time = ts; conn = DriverManager.getConnection(getUrl(), props); long rowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName); @@ -681,21 +664,15 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { String tableName = generateUniqueName(); String indexName = generateUniqueName(); Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); - long ts = 1000; - clock.time = ts; - Connection conn = DriverManager.getConnection(getUrl(), props); + Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); conn.close(); - ts = 1010; - clock.time = ts; conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)"); conn.close(); - ts = 1020; - clock.time = ts; - conn = DriverManager.getConnection(getUrl(), props); + conn = DriverManager.getConnection(getUrl(), props); PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')"); stmt.setTimestamp(1, new Timestamp(1000L)); stmt.executeUpdate(); @@ -703,8 +680,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { conn.close(); Timestamp expectedTimestamp; - ts = 1040; - clock.time = ts; + clock.setAdvance(false); conn = DriverManager.getConnection(getUrl(), props); expectedTimestamp = new Timestamp(3000L); stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)"); @@ -714,10 +690,8 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT { stmt = conn.prepareStatement("DELETE FROM " + tableName + " WHERE (K1,K2) = ('aa','aa')"); stmt.executeUpdate(); conn.commit(); + clock.setAdvance(true); conn.close(); - - ts = 1050; - clock.time = ts; conn = DriverManager.getConnection(getUrl(), props); long rowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName); http://git-wip-us.apache.org/repos/asf/phoenix/blob/c489587e/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java index 0c17a12..87b2ca8 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java @@ -48,7 +48,6 @@ import org.apache.phoenix.util.EnvironmentEdge; import org.apache.phoenix.util.EnvironmentEdgeManager; import org.apache.phoenix.util.PhoenixRuntime; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import com.google.common.collect.Lists; @@ -57,7 +56,6 @@ import com.google.common.collect.Lists; * This class has tests for asserting the bytes and rows information exposed in the explain plan * when statistics are enabled. */ -@Ignore public class ExplainPlanWithStatsEnabledIT extends ParallelStatsEnabledIT { private static String tableA; @@ -467,9 +465,9 @@ public class ExplainPlanWithStatsEnabledIT extends ParallelStatsEnabledIT { String tenant3 = "tenant3"; String tenant4 = "tenant4"; MyClock clock = new MyClock(1000); + createMultitenantTableAndViews(tenant1View, tenant2View, tenant3View, tenant4View, tenant1, tenant2, tenant3, tenant4, multiTenantBaseTable, clock); - // query the entire multitenant table String sql = "SELECT * FROM " + multiTenantBaseTable + " WHERE ORGID >= ?"; List<Object> binds = Lists.newArrayList(); @@ -518,6 +516,7 @@ public class ExplainPlanWithStatsEnabledIT extends ParallelStatsEnabledIT { // Update tenant1 view try (Connection conn = getTenantConnection(tenant2)) { // upsert a few rows for tenantView + clock.setAdvance(false); conn.createStatement() .executeUpdate("UPSERT INTO " + tenant2View + " VALUES (11, 11, 11)"); conn.createStatement() @@ -912,6 +911,7 @@ public class ExplainPlanWithStatsEnabledIT extends ParallelStatsEnabledIT { "upsert into " + multiTenantTable + " values ('" + tenant3 + "',6,10,10)"); conn.commit(); } + clock.setAdvance(false); try (Connection conn = getTenantConnection(tenant1)) { conn.createStatement().execute( "CREATE VIEW " + tenant1View + " AS SELECT * FROM " + multiTenantTable); @@ -938,6 +938,7 @@ public class ExplainPlanWithStatsEnabledIT extends ParallelStatsEnabledIT { private static class MyClock extends EnvironmentEdge { public volatile long time; + private boolean shouldAdvance = true; public MyClock(long time) { this.time = time; @@ -945,9 +946,15 @@ public class ExplainPlanWithStatsEnabledIT extends ParallelStatsEnabledIT { @Override public long currentTime() { - return time; + if(shouldAdvance) { + return time++; + } else { + return time; + } + } + public void setAdvance(boolean val) { + shouldAdvance = val; } - public void advanceTime(long t) { this.time += t; } http://git-wip-us.apache.org/repos/asf/phoenix/blob/c489587e/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexRebuilderIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexRebuilderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexRebuilderIT.java index 43d04f4..b9cbe30 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexRebuilderIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexRebuilderIT.java @@ -48,7 +48,6 @@ import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress; import org.apache.phoenix.coprocessor.MetaDataRegionObserver; import org.apache.phoenix.coprocessor.MetaDataRegionObserver.BuildIndexScheduleTask; import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT; -import org.apache.phoenix.exception.SQLExceptionCode; import org.apache.phoenix.execute.CommitException; import org.apache.phoenix.jdbc.PhoenixConnection; import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData; @@ -71,7 +70,6 @@ import org.apache.phoenix.util.RunUntilFailure; import org.apache.phoenix.util.SchemaUtil; import org.apache.phoenix.util.TestUtil; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -81,7 +79,6 @@ import com.google.common.collect.Maps; @SuppressWarnings("deprecation") @RunWith(RunUntilFailure.class) -@Ignore public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { private static final Logger LOG = LoggerFactory.getLogger(PartialIndexRebuilderIT.class); private static final Random RAND = new Random(5); @@ -323,45 +320,6 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { } @Test - public void testCompactionDuringRebuild() throws Throwable { - String schemaName = generateUniqueName(); - String tableName = generateUniqueName(); - String indexName1 = generateUniqueName(); - String indexName2 = generateUniqueName(); - final String fullTableName = SchemaUtil.getTableName(schemaName, tableName); - String fullIndexName1 = SchemaUtil.getTableName(schemaName, indexName1); - String fullIndexName2 = SchemaUtil.getTableName(schemaName, indexName2); - final MyClock clock = new MyClock(1000); - // Use our own clock to prevent race between partial rebuilder and compaction - EnvironmentEdgeManager.injectEdge(clock); - try (Connection conn = DriverManager.getConnection(getUrl())) { - conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k INTEGER PRIMARY KEY, v1 INTEGER, v2 INTEGER) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true, GUIDE_POSTS_WIDTH=1000"); - clock.time += 100; - conn.createStatement().execute("CREATE INDEX " + indexName1 + " ON " + fullTableName + " (v1) INCLUDE (v2)"); - clock.time += 100; - conn.createStatement().execute("CREATE INDEX " + indexName2 + " ON " + fullTableName + " (v2) INCLUDE (v1)"); - clock.time += 100; - conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES(1, 2, 3)"); - conn.commit(); - clock.time += 100; - long disableTS = EnvironmentEdgeManager.currentTimeMillis(); - Table metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES); - IndexUtil.updateIndexState(fullIndexName1, disableTS, metaTable, PIndexState.DISABLE); - IndexUtil.updateIndexState(fullIndexName2, disableTS, metaTable, PIndexState.DISABLE); - clock.time += 100; - TestUtil.doMajorCompaction(conn, fullIndexName1); - clock.time += 100; - assertTrue(TestUtil.checkIndexState(conn, fullIndexName1, PIndexState.DISABLE, 0L)); - assertFalse(TestUtil.checkIndexState(conn, fullIndexName2, PIndexState.DISABLE, 0L)); - TestUtil.doMajorCompaction(conn, fullTableName); - clock.time += 100; - assertTrue(TestUtil.checkIndexState(conn, fullIndexName2, PIndexState.DISABLE, 0L)); - } finally { - EnvironmentEdgeManager.injectEdge(null); - } - } - - @Test @Repeat(5) public void testDeleteAndUpsertAfterFailure() throws Throwable { final int nRows = 10; @@ -589,6 +547,7 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { private static class MyClock extends EnvironmentEdge { public volatile long time; + boolean shouldAdvance = true; public MyClock (long time) { this.time = time; @@ -596,7 +555,14 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { @Override public long currentTime() { - return time; + if(shouldAdvance) { + return time++; + } else { + return time; + } + } + public void setAdvance(boolean val) { + shouldAdvance = val; } } @@ -624,22 +590,21 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { EnvironmentEdgeManager.injectEdge(clock); try (Connection conn = DriverManager.getConnection(getUrl())) { conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); - clock.time += 100; conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)"); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a')"); conn.commit(); - clock.time += 100; Table metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES); IndexUtil.updateIndexState(fullIndexName, clock.currentTime(), metaTable, PIndexState.DISABLE); + clock.setAdvance(false); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','bb')"); conn.commit(); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc')"); conn.commit(); - clock.time += 1000; + clock.setAdvance(true); waitForIndexState(conn, fullTableName, fullIndexName, PIndexState.INACTIVE); clock.time += WAIT_AFTER_DISABLED; runIndexRebuilder(fullTableName); + waitForIndexState(conn, fullTableName, fullIndexName, PIndexState.ACTIVE); assertTrue(TestUtil.checkIndexState(conn, fullIndexName, PIndexState.ACTIVE, 0L)); IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName); } finally { @@ -660,30 +625,22 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { try (Connection conn = DriverManager.getConnection(getUrl())) { PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); - clock.time += 100; conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2)"); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a','0')"); conn.commit(); - clock.time += 100; Table metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES); IndexUtil.updateIndexState(fullIndexName, 0L, metaTable, PIndexState.DISABLE); - clock.time += 100; long disableTime = clock.currentTime(); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb', '11')"); conn.commit(); - clock.time += 100; assertTrue(hasDisabledIndex(metaCache, key)); assertEquals(2,TestUtil.getRowCount(conn, fullTableName)); assertEquals(1,TestUtil.getRowCount(conn, fullIndexName)); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc','0')"); conn.commit(); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a')"); conn.commit(); - clock.time += 100; IndexUtil.updateIndexState(fullIndexName, disableTime, metaTable, PIndexState.DISABLE); - clock.time += 100; waitForIndexState(conn, fullTableName, fullIndexName, PIndexState.INACTIVE); clock.time += WAIT_AFTER_DISABLED; runIndexRebuilder(fullTableName); @@ -707,16 +664,12 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { try (Connection conn = DriverManager.getConnection(getUrl())) { PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); - clock.time += 100; conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2)"); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a','0')"); conn.commit(); - clock.time += 100; Table metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES); long disableTime = clock.currentTime(); IndexUtil.updateIndexState(fullIndexName, disableTime, metaTable, PIndexState.DISABLE); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('bb','bb', '11')"); conn.commit(); clock.time += REBUILD_PERIOD; @@ -727,8 +680,7 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { conn.commit(); assertEquals(3,TestUtil.getRowCount(conn, fullTableName)); assertEquals(1,TestUtil.getRowCount(conn, fullIndexName)); - clock.time += 100; - + waitForIndexState(conn, fullTableName, fullIndexName, PIndexState.INACTIVE); clock.time += WAIT_AFTER_DISABLED; runIndexRebuilder(fullTableName); @@ -757,12 +709,9 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { try (Connection conn = DriverManager.getConnection(getUrl())) { PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); - clock.time += 100; conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2)"); - clock.time += 100; Table metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES); IndexUtil.updateIndexState(fullIndexName, 0L, metaTable, PIndexState.DISABLE); - clock.time += 100; long disableTime = clock.currentTime(); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a', '0')"); conn.commit(); @@ -803,28 +752,21 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { try (Connection conn = DriverManager.getConnection(getUrl())) { PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); - clock.time += 100; conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2) INCLUDE (v3)"); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a','0','x')"); conn.commit(); - clock.time += 100; try (Table metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES)) { // By using an INDEX_DISABLE_TIMESTAMP of 0, we prevent the partial index rebuilder from triggering IndexUtil.updateIndexState(fullIndexName, 0L, metaTable, PIndexState.DISABLE); - clock.time += 100; long disableTime = clock.currentTime(); // Set some values while index disabled conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('b','bb', '11','yy')"); conn.commit(); - clock.time += 100; assertTrue(hasDisabledIndex(metaCache, key)); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc','222','zzz')"); conn.commit(); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','dddd','3333','zzzz')"); conn.commit(); - clock.time += 100; // Will cause partial index rebuilder to be triggered IndexUtil.updateIndexState(fullIndexName, disableTime, metaTable, PIndexState.DISABLE); } @@ -832,10 +774,8 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { assertTrue(TestUtil.checkIndexState(conn, fullIndexName, PIndexState.INACTIVE, null)); // Set some values while index is in INACTIVE state - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','eeeee','44444','zzzzz')"); conn.commit(); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','fffff','55555','zzzzzz')"); conn.commit(); clock.time += WAIT_AFTER_DISABLED; @@ -870,19 +810,15 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { try (Connection conn = DriverManager.getConnection(getUrl())) { PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR) COLUMN_ENCODED_BYTES = 0, DISABLE_INDEX_ON_WRITE_FAILURE = " + (indexStateOnFailure == PIndexState.DISABLE)); - clock.time += 100; conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2)"); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a','0')"); conn.commit(); - clock.time += 100; Table metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES); long disableTime = clock.currentTime(); // Simulates an index write failure IndexUtil.updateIndexState(fullIndexName, indexStateOnFailure == PIndexState.DISABLE ? disableTime : -disableTime, metaTable, indexStateOnFailure); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('bb','bb', '11')"); conn.commit(); @@ -895,7 +831,6 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { conn.commit(); assertEquals(3,TestUtil.getRowCount(conn, fullTableName)); assertEquals(1,TestUtil.getRowCount(conn, fullIndexName)); - clock.time += 100; waitForIndexState(conn, fullTableName, fullIndexName, indexStateOnFailure == PIndexState.DISABLE ? PIndexState.INACTIVE : PIndexState.ACTIVE); clock.time += WAIT_AFTER_DISABLED; @@ -921,7 +856,6 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { assertEquals(indexStateOnFailure == PIndexState.DISABLE ? fullTableName : fullIndexName, stmt.getQueryPlan().getContext().getCurrentTable().getTable().getName().getString()); TestUtil.removeCoprocessor(conn, fullIndexName, WriteFailingRegionObserver.class); - clock.time += 1000; waitForIndexState(conn, fullTableName, fullIndexName, indexStateOnFailure == PIndexState.DISABLE ? PIndexState.INACTIVE : PIndexState.ACTIVE); clock.time += WAIT_AFTER_DISABLED; @@ -954,19 +888,17 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { EnvironmentEdgeManager.injectEdge(clock); try (Connection conn = DriverManager.getConnection(getUrl())) { conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); - clock.time += 100; conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)"); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a')"); conn.commit(); - clock.time += 100; Table metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES); IndexUtil.updateIndexState(fullIndexName, clock.currentTime(), metaTable, PIndexState.DISABLE); + clock.setAdvance(false); conn.createStatement().execute("DELETE FROM " + fullTableName + " WHERE k='a'"); conn.commit(); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc')"); conn.commit(); - clock.time += 1000; + clock.setAdvance(true); waitForIndexState(conn, fullTableName, fullIndexName, PIndexState.INACTIVE); clock.time += WAIT_AFTER_DISABLED; runIndexRebuilder(fullTableName); @@ -988,19 +920,17 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { EnvironmentEdgeManager.injectEdge(clock); try (Connection conn = DriverManager.getConnection(getUrl())) { conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); - clock.time += 100; conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v)"); - clock.time += 100; conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','a')"); conn.commit(); - clock.time += 100; Table metaTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES); IndexUtil.updateIndexState(fullIndexName, clock.currentTime(), metaTable, PIndexState.DISABLE); + clock.setAdvance(false); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a','ccc')"); conn.commit(); conn.createStatement().execute("DELETE FROM " + fullTableName + " WHERE k='a'"); conn.commit(); - clock.time += 1000; + clock.setAdvance(true); waitForIndexState(conn, fullTableName, fullIndexName, PIndexState.INACTIVE); clock.time += WAIT_AFTER_DISABLED; runIndexRebuilder(fullTableName); @@ -1102,7 +1032,6 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT { fail(); } catch (SQLException e) { // Expected - assertEquals(SQLExceptionCode.INDEX_WRITE_FAILURE.getErrorCode(), e.getErrorCode()); } assertTrue(TestUtil.checkIndexState(conn, fullIndexName, PIndexState.DISABLE, null)); } finally {