This is an automated email from the ASF dual-hosted git repository.
tchoi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 0c059c6e9bb HIVE-26920: Add new view
'replication_failover_failback_metrics' in sys db to capture failover and
failback metrics (#4023) (Amit Saonerkar, reviewed by Teddy Choi)
0c059c6e9bb is described below
commit 0c059c6e9bba35f353cd3212c5c01e86eba51125
Author: atsaonerk <[email protected]>
AuthorDate: Wed Feb 8 13:32:16 2023 +0530
HIVE-26920: Add new view 'replication_failover_failback_metrics' in sys db
to capture failover and failback metrics (#4023) (Amit Saonerkar, reviewed by
Teddy Choi)
---
.../parse/TestReplicationOptimisedBootstrap.java | 94 +++++++++++++++---
.../parse/TestReplicationScenariosAcidTables.java | 88 ++++++++---------
.../parse/TestScheduledReplicationScenarios.java | 16 ++--
.../upgrade/hive/hive-schema-4.0.0.hive.sql | 17 ++++
...upgrade-4.0.0-alpha-1-to-4.0.0-alpha-2.hive.sql | 16 ++++
.../hadoop/hive/ql/exec/repl/ReplDumpTask.java | 105 ++++++++++++++-------
.../hadoop/hive/ql/exec/repl/ReplLoadTask.java | 55 +++++++++--
.../hive/ql/parse/ReplicationSemanticAnalyzer.java | 2 +-
.../hadoop/hive/ql/stats/StatsUpdaterThread.java | 2 +-
.../results/clientpositive/llap/resourceplan.q.out | 4 +
.../llap/strict_managed_tables_sysdb.q.out | 6 ++
.../test/results/clientpositive/llap/sysdb.q.out | 11 ++-
.../apache/hadoop/hive/common/repl/ReplConst.java | 10 ++
.../hive/metastore/utils/MetaStoreUtils.java | 6 +-
.../hive/metastore/PartitionManagementTask.java | 2 +-
15 files changed, 316 insertions(+), 118 deletions(-)
diff --git
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationOptimisedBootstrap.java
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationOptimisedBootstrap.java
index 1068fe4ecba..91f8f76e1ff 100644
---
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationOptimisedBootstrap.java
+++
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationOptimisedBootstrap.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hive.ql.parse;
+import org.apache.commons.lang3.math.NumberUtils;
import org.apache.hadoop.fs.ContentSummary;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
@@ -67,6 +68,11 @@ import static
org.apache.hadoop.hdfs.protocol.HdfsConstants.QUOTA_RESET;
import static
org.apache.hadoop.hive.common.repl.ReplConst.REPL_ENABLE_BACKGROUND_THREAD;
import static
org.apache.hadoop.hive.common.repl.ReplConst.REPL_TARGET_DB_PROPERTY;
import static
org.apache.hadoop.hive.common.repl.ReplConst.REPL_FAILOVER_ENDPOINT;
+import static
org.apache.hadoop.hive.common.repl.ReplConst.REPL_METRICS_FAILBACK_COUNT;
+import static
org.apache.hadoop.hive.common.repl.ReplConst.REPL_METRICS_FAILOVER_COUNT;
+import static
org.apache.hadoop.hive.common.repl.ReplConst.REPL_METRICS_LAST_FAILBACK_ENDTIME;
+import static
org.apache.hadoop.hive.common.repl.ReplConst.REPL_METRICS_LAST_FAILBACK_STARTTIME;
+import static
org.apache.hadoop.hive.common.repl.ReplConst.REPL_METRICS_LAST_FAILOVER_TYPE;
import static
org.apache.hadoop.hive.common.repl.ReplConst.TARGET_OF_REPLICATION;
import static
org.apache.hadoop.hive.metastore.ReplChangeManager.SOURCE_OF_REPLICATION;
import static
org.apache.hadoop.hive.ql.exec.repl.OptimisedBootstrapUtils.EVENT_ACK_FILE;
@@ -616,6 +622,10 @@ public class TestReplicationOptimisedBootstrap extends
BaseReplicationScenariosA
assertTrue(tablesBootstrapped.containsAll(Arrays.asList("t1", "t2",
"t3")));
+ // Get source or replica database properties and verify replication
metrics properties
+ Map<String, String> sourceParams =
replica.getDatabase(replicatedDbName).getParameters();
+ verifyReplicationMetricsStatistics(sourceParams, 1, 1,
ReplConst.FailoverType.UNPLANNED.toString());
+
// Do a reverse load, this should do a bootstrap load for the tables in
table_diff and incremental for the rest.
primary.load(primaryDbName, replicatedDbName, withClause);
@@ -635,10 +645,9 @@ public class TestReplicationOptimisedBootstrap extends
BaseReplicationScenariosA
.run("select place from t5 where country = 'china'")
.verifyResults(new String[] { "beejing" });
- // Check for correct db Properties set.
-
+ // Get target or primary database properties and verify replication
metrics properties
Map<String, String> targetParams =
primary.getDatabase(primaryDbName).getParameters();
- Map<String, String> sourceParams =
replica.getDatabase(replicatedDbName).getParameters();
+ verifyReplicationMetricsStatistics(targetParams, 1, 1,
ReplConst.FailoverType.UNPLANNED.toString());
// Check the properties on the new target database.
assertTrue(targetParams.containsKey(TARGET_OF_REPLICATION));
@@ -1321,20 +1330,24 @@ public class TestReplicationOptimisedBootstrap extends
BaseReplicationScenariosA
}
@Test
public void testReverseFailoverBeforeOptimizedBootstrap() throws Throwable {
+ // Do bootstrap dump and load
primary.run("use " + primaryDbName)
.run("create table t1 (id string)")
.run("insert into table t1 values ('A')")
.dump(primaryDbName);
replica.load(replicatedDbName, primaryDbName);
+ // Do incremental dump and load
primary.dump(primaryDbName);
replica.load(replicatedDbName, primaryDbName);
//initiate a controlled failover from primary to replica.
List<String> failoverConfigs = Arrays.asList("'" +
HiveConf.ConfVars.HIVE_REPL_FAILOVER_START + "'='true'");
primary.dump(primaryDbName, failoverConfigs);
replica.load(replicatedDbName, primaryDbName, failoverConfigs);
+
+ //modify primary after failover.
primary.run("use " + primaryDbName)
- .run("insert into t1 values('B')"); //modify primary after
failover.
+ .run("insert into t1 values('B')");
//initiate a controlled failover from replica to primary before the first
cycle of optimized bootstrap is run.
WarehouseInstance.Tuple reverseDump = replica.run("use " +
replicatedDbName)
.run("create table t2 (col int)")
@@ -1354,9 +1367,9 @@ public class TestReplicationOptimisedBootstrap extends
BaseReplicationScenariosA
HashSet<String> tableDiffEntries = getTablesFromTableDiffFile(new
Path(reverseDump.dumpLocation), conf);
assertTrue(!tableDiffEntries.isEmpty()); // we have modified a table t1 at
source
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
MetaStoreUtils.FailoverEndpoint.TARGET));
//do a second dump, this dump should NOT be failover ready as some tables
need to be bootstrapped (here it is t1).
@@ -1372,11 +1385,21 @@ public class TestReplicationOptimisedBootstrap extends
BaseReplicationScenariosA
.run(String.format("select * from %s.t2", primaryDbName))
.verifyResults(new String[]{"1", "2"});
-
assertFalse(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
MetaStoreUtils.FailoverEndpoint.TARGET));
+ // Get source and target database properties after optimised bootstrap
+ Map<String, String> sourceParams =
replica.getDatabase(replicatedDbName).getParameters();
+ Map<String, String> targetParams =
primary.getDatabase(primaryDbName).getParameters();
+
+ // verify db failback metrics are set properly for source db after
optimised bootstrap
+ verifyReplicationMetricsStatistics(sourceParams, 1, 2,
ReplConst.FailoverType.PLANNED.toString());
+
+ // verify db failback metrics are set properly for target db after
optimised bootstrap
+ verifyReplicationMetricsStatistics(targetParams, 1, 1,
ReplConst.FailoverType.PLANNED.toString());
+
//do a third dump, this should be failover ready.
reverseDump = replica.dump(replicatedDbName, failoverConfigs);
dumpPath = new Path(reverseDump.dumpLocation,
ReplUtils.REPL_HIVE_BASE_DIR);
@@ -1384,11 +1407,20 @@ public class TestReplicationOptimisedBootstrap extends
BaseReplicationScenariosA
assertTrue(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
primary.load(primaryDbName, replicatedDbName, failoverConfigs);
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.TARGET));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
+ sourceParams = replica.getDatabase(replicatedDbName).getParameters();
+ targetParams = primary.getDatabase(primaryDbName).getParameters();
+
+ // verify db failback metrics are set properly for source db after
optimised bootstrap
+ verifyReplicationMetricsStatistics(sourceParams, 1, 3,
ReplConst.FailoverType.PLANNED.toString());
+
+ // verify db failback metrics are set properly for target db after
optimised bootstrap
+ verifyReplicationMetricsStatistics(targetParams, 1, 2,
ReplConst.FailoverType.PLANNED.toString());
+
//initiate a failover from primary to replica.
WarehouseInstance.Tuple forwardDump = primary.dump(primaryDbName,
failoverConfigs);
assertTrue(fs.exists(new Path(forwardDump.dumpLocation, EVENT_ACK_FILE)));
@@ -1407,10 +1439,19 @@ public class TestReplicationOptimisedBootstrap extends
BaseReplicationScenariosA
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
replica.load(replicatedDbName, primaryDbName, failoverConfigs);
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
MetaStoreUtils.FailoverEndpoint.TARGET));
+
+ sourceParams = replica.getDatabase(replicatedDbName).getParameters();
+ targetParams = primary.getDatabase(primaryDbName).getParameters();
+
+ // verify db failback metrics are set properly for source db after
optimised bootstrap
+ verifyReplicationMetricsStatistics(sourceParams, 2, 4,
ReplConst.FailoverType.PLANNED.toString());
+
+ // verify db failback metrics are set properly for target db after
optimised bootstrap
+ verifyReplicationMetricsStatistics(targetParams, 2, 3,
ReplConst.FailoverType.PLANNED.toString());
}
@Test
public void testOptimizedBootstrapWithControlledFailover() throws Throwable {
@@ -1453,9 +1494,9 @@ public class TestReplicationOptimisedBootstrap extends
BaseReplicationScenariosA
HashSet<String> tableDiffEntries = getTablesFromTableDiffFile(new
Path(reverseDump.dumpLocation), conf);
assertTrue(!tableDiffEntries.isEmpty());
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
MetaStoreUtils.FailoverEndpoint.TARGET));
// second cycle of optimized bootstrap
@@ -1474,4 +1515,29 @@ public class TestReplicationOptimisedBootstrap extends
BaseReplicationScenariosA
assertFalse(primary.getDatabase(primaryDbName).getParameters().containsKey(REPL_FAILOVER_ENDPOINT));
assertFalse(replica.getDatabase(replicatedDbName).getParameters().containsKey(REPL_FAILOVER_ENDPOINT));
}
+
+ private void verifyReplicationMetricsStatistics(Map<String, String>
dbParams, int expectedFailbackCount, int expectedFailoverCount, String
expectedFailoverType) {
+ // verify failover metrics
+
assertTrue(dbParams.containsKey(ReplConst.REPL_METRICS_LAST_FAILOVER_TYPE));
+ String failoverType =
dbParams.get(ReplConst.REPL_METRICS_LAST_FAILOVER_TYPE);
+ assertEquals(failoverType, expectedFailoverType);
+
+ assertTrue(dbParams.containsKey(ReplConst.REPL_METRICS_FAILOVER_COUNT));
+ String failoverCount = dbParams.get(ReplConst.REPL_METRICS_FAILOVER_COUNT);
+ assertEquals(NumberUtils.toInt(failoverCount, 0), expectedFailoverCount);
+
+ // verify failback metrics
+
assertTrue(dbParams.containsKey(ReplConst.REPL_METRICS_LAST_FAILBACK_STARTTIME));
+ String failbackStartTime =
dbParams.get(ReplConst.REPL_METRICS_LAST_FAILBACK_STARTTIME);
+ assertNotEquals(NumberUtils.toLong(failbackStartTime, 0), 0);
+
+ assertTrue(dbParams.containsKey(ReplConst.REPL_METRICS_FAILBACK_COUNT));
+ String failbackCount = dbParams.get(ReplConst.REPL_METRICS_FAILBACK_COUNT);
+ assertEquals(NumberUtils.toInt(failbackCount, 0), expectedFailbackCount);
+
+
assertTrue(dbParams.containsKey(ReplConst.REPL_METRICS_LAST_FAILBACK_ENDTIME));
+ String failbackEndTime =
dbParams.get(ReplConst.REPL_METRICS_LAST_FAILBACK_ENDTIME);
+ assertNotEquals(NumberUtils.toLong(failbackEndTime, 0), 0);
+ }
+
}
diff --git
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcidTables.java
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcidTables.java
index f3d086eafd9..fda11c127e4 100644
---
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcidTables.java
+++
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcidTables.java
@@ -285,7 +285,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
FileSystem fs = new Path(dumpData.dumpLocation).getFileSystem(conf);
Path dumpPath = new Path(dumpData.dumpLocation,
ReplUtils.REPL_HIVE_BASE_DIR);
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
replica.load(replicatedDbName, primaryDbName, failoverConfigs)
.run("use " + replicatedDbName)
@@ -296,7 +296,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
Database db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertFalse(MetaStoreUtils.isDbBeingFailedOver(db));
+ assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(db));
primary.run("use " + primaryDbName)
.run("insert into t1 values(1)")
@@ -342,7 +342,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString())));
assertTrue(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
FailoverMetaData failoverMD = new FailoverMetaData(dumpPath, conf);
@@ -380,7 +380,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
+ assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.LOAD_ACKNOWLEDGEMENT.toString())));
Path dbRootDir = new Path(dumpData.dumpLocation).getParent();
@@ -391,7 +391,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
dumpPath = new Path(dumpData.dumpLocation, ReplUtils.REPL_HIVE_BASE_DIR);
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.LOAD_ACKNOWLEDGEMENT.toString())));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
assertFalse(ReplChangeManager.isSourceOfReplication(replica.getDatabase(replicatedDbName)));
@@ -408,7 +408,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(new DumpMetaData(dumpPath, conf).getDumpType() ==
DumpType.PRE_OPTIMIZED_BOOTSTRAP);
assertTrue(fs.exists(new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString())));
db = replica.getDatabase(replicatedDbName);
- assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
+ assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
//do a second reverse dump.
primary.load(primaryDbName, replicatedDbName);
@@ -432,7 +432,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertFalse(primaryDb == null);
assertFalse(ReplUtils.isFirstIncPending(primaryDb.getParameters()));
assertTrue(MetaStoreUtils.isTargetOfReplication(primaryDb));
- assertFalse(MetaStoreUtils.isDbBeingFailedOver(primaryDb));
+ assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primaryDb));
assertTrue(fs.exists(new Path(dumpPath, LOAD_ACKNOWLEDGEMENT.toString())));
assertFalse(ReplChangeManager.isSourceOfReplication(primaryDb));
assertTrue(ReplChangeManager.isSourceOfReplication(replica.getDatabase(replicatedDbName)));
@@ -440,7 +440,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
reverseDumpData = replica.run("insert into t3 values (3)")
.run("insert into t2 partition(name='Bob') values(30)")
.dump(replicatedDbName);
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(replica.getDatabase(replicatedDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(replica.getDatabase(replicatedDbName)));
primary.load(primaryDbName, replicatedDbName)
.run("select rank from t2 order by rank")
@@ -465,7 +465,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
FileSystem fs = new Path(dumpData.dumpLocation).getFileSystem(conf);
Path dumpPath = new Path(dumpData.dumpLocation,
ReplUtils.REPL_HIVE_BASE_DIR);
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
replica.load(replicatedDbName, primaryDbName, failoverConfigs)
.run("use " + replicatedDbName)
@@ -476,7 +476,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
Database db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertFalse(MetaStoreUtils.isDbBeingFailedOver(db));
+ assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(db));
dumpData = primary.run("use " + primaryDbName)
.run("insert into t1 values(1)")
@@ -490,7 +490,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString())));
assertTrue(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
replica.load(replicatedDbName, primaryDbName, failoverConfigs)
@@ -509,7 +509,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(new Path(dumpPath, LOAD_ACKNOWLEDGEMENT.toString())));
db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
+ assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
dumpData = primary.run("create table t3(id int)")
.run("insert into t3 values (3)")
@@ -518,7 +518,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertEquals(new DumpMetaData(dumpPath, conf).getDumpType(),
DumpType.INCREMENTAL);
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
assertFalse(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
replica.load(replicatedDbName, primaryDbName)
.run("show tables")
.verifyResults(new String[]{"t1", "t2", "t3"})
@@ -533,7 +533,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertFalse(MetaStoreUtils.isDbBeingFailedOver(db));
+ assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(db));
}
@Test
@@ -557,7 +557,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
Path dumpPath = new Path(dumpData.dumpLocation,
ReplUtils.REPL_HIVE_BASE_DIR);
assertFalse(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
replica.load(replicatedDbName, primaryDbName)
.run("use " + replicatedDbName)
@@ -578,7 +578,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(dumpAckFile));
assertTrue(fs.exists(failoverMdFile));
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
FailoverMetaData previousFmd = new FailoverMetaData(dumpPath, conf);
Long failoverEventId = previousFmd.getFailoverEventId();
@@ -599,7 +599,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(failoverMdFile));
Assert.assertEquals(failoverMdModifTime,
(Long)fs.getFileStatus(failoverMdFile).getModificationTime());
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
assertTrue(failoverEventId >= Long.parseLong(dumpData.lastReplicationId));
FailoverMetaData currentFmd = new FailoverMetaData(dumpPath, conf);
@@ -618,7 +618,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
Database db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
+ assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.LOAD_ACKNOWLEDGEMENT.toString())));
WarehouseInstance.Tuple reverseDumpData = replica.run("use " +
replicatedDbName)
@@ -635,7 +635,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
assertTrue(new DumpMetaData(dumpPath, conf).getDumpType() ==
DumpType.PRE_OPTIMIZED_BOOTSTRAP);
db = replica.getDatabase(replicatedDbName);
- assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
+ assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
primary.load(primaryDbName, replicatedDbName, retainPrevDumpDir);
//do a second reverse dump.
@@ -662,7 +662,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
.dump(replicatedDbName);
dumpPath = new Path(reverseDumpData.dumpLocation,
ReplUtils.REPL_HIVE_BASE_DIR);
fs.exists(new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString()));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(replica.getDatabase(replicatedDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(replica.getDatabase(replicatedDbName)));
primary.load(primaryDbName, replicatedDbName)
.run("use " + primaryDbName)
@@ -692,7 +692,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
Path dumpPath = new Path(dumpData.dumpLocation,
ReplUtils.REPL_HIVE_BASE_DIR);
assertFalse(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
replica.load(replicatedDbName, primaryDbName)
.run("use " + replicatedDbName)
@@ -711,7 +711,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString())));
assertTrue(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
replica.load(replicatedDbName, primaryDbName, failoverConfigs)
@@ -727,7 +727,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
Database db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
+ assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.LOAD_ACKNOWLEDGEMENT.toString())));
WarehouseInstance.Tuple reverseDumpData = replica.run("use " +
replicatedDbName)
@@ -744,7 +744,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
assertTrue(new DumpMetaData(dumpPath, conf).getDumpType() ==
DumpType.PRE_OPTIMIZED_BOOTSTRAP);
db = replica.getDatabase(replicatedDbName);
- assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
+ assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
fs.delete(dumpAckFile, false);
assertFalse(fs.exists(dumpAckFile));
@@ -759,7 +759,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(new DumpMetaData(dumpPath, conf).getDumpType() ==
DumpType.PRE_OPTIMIZED_BOOTSTRAP);
assertTrue(fs.exists(dumpAckFile));
db = replica.getDatabase(replicatedDbName);
- assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
+ assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
primary.load(primaryDbName, replicatedDbName);
dumpData = replica.dump(replicatedDbName, retainPrevDumpDir);
@@ -785,18 +785,18 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
.dump(replicatedDbName, retainPrevDumpDir);
dumpPath = new Path(reverseDumpData.dumpLocation,
ReplUtils.REPL_HIVE_BASE_DIR);
dumpAckFile = new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString());
-
assertFalse(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
MetaStoreUtils.FailoverEndpoint.TARGET));
fs.delete(dumpAckFile);
replica.run("ALTER DATABASE " + replicatedDbName + " SET DBPROPERTIES('" +
ReplConst.REPL_FAILOVER_ENDPOINT + "'='"
+ MetaStoreUtils.FailoverEndpoint.TARGET + "')");
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
MetaStoreUtils.FailoverEndpoint.TARGET));
assertFalse(fs.exists(dumpAckFile));
dumpData = replica.dump(replicatedDbName, retainPrevDumpDir);
assertEquals(reverseDumpData.dumpLocation, dumpData.dumpLocation);
fs.exists(dumpAckFile);
-
assertFalse(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(replica.getDatabase(replicatedDbName),
MetaStoreUtils.FailoverEndpoint.TARGET));
primary.load(primaryDbName, replicatedDbName, retainPrevDumpDir)
@@ -825,7 +825,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
Path dumpPath = new Path(dumpData.dumpLocation,
ReplUtils.REPL_HIVE_BASE_DIR);
assertFalse(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
replica.load(replicatedDbName, primaryDbName)
.run("use " + replicatedDbName)
@@ -845,7 +845,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(dumpAckFile));
assertTrue(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertTrue(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
fs.delete(dumpAckFile, false);
@@ -860,7 +860,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
assertTrue(fs.exists(new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
replica.load(replicatedDbName, primaryDbName)
.run("use " + replicatedDbName)
@@ -875,7 +875,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
.run("select id from t3")
.verifyResults(new String[]{"2"});
assertTrue(fs.exists(new Path(dumpPath, LOAD_ACKNOWLEDGEMENT.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(replica.getDatabase(replicatedDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(replica.getDatabase(replicatedDbName)));
}
@Test
@@ -892,7 +892,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
FileSystem fs = new Path(dumpData.dumpLocation).getFileSystem(conf);
Path dumpPath = new Path(dumpData.dumpLocation,
ReplUtils.REPL_HIVE_BASE_DIR);
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
replica.load(replicatedDbName, primaryDbName, failoverConfigs)
.run("use " + replicatedDbName)
@@ -903,7 +903,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
Database db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertFalse(MetaStoreUtils.isDbBeingFailedOver(db));
+ assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(db));
dumpData = primary.run("use " + primaryDbName)
.run("insert into t1 values(1)")
@@ -916,7 +916,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString())));
assertTrue(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertTrue(fs.exists(failoverReadyMarker));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
replica.load(replicatedDbName, primaryDbName, failoverConfigs)
@@ -933,7 +933,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(new Path(dumpPath, LOAD_ACKNOWLEDGEMENT.toString())));
db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
+ assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
assert
"true".equals(db.getParameters().get(REPL_ENABLE_BACKGROUND_THREAD));
}
@@ -954,7 +954,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
FileSystem fs = new Path(dumpData.dumpLocation).getFileSystem(conf);
Path dumpPath = new Path(dumpData.dumpLocation,
ReplUtils.REPL_HIVE_BASE_DIR);
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
replica.load(replicatedDbName, primaryDbName, failoverConfigs)
.run("use " + replicatedDbName)
@@ -965,7 +965,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
Database db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertFalse(MetaStoreUtils.isDbBeingFailedOver(db));
+ assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(db));
dumpData = primary.run("use " + primaryDbName)
.run("insert into t1 values(1)")
@@ -978,7 +978,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString())));
assertTrue(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertTrue(fs.exists(failoverReadyMarker));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
replica.load(replicatedDbName, primaryDbName, failoverConfigs)
@@ -995,13 +995,13 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(new Path(dumpPath, LOAD_ACKNOWLEDGEMENT.toString())));
db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
+ assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET));
dumpData = primary.run("insert into t1 values (5)")
.dump(primaryDbName, retainPrevDumpDir);
dumpPath = new Path(dumpData.dumpLocation, ReplUtils.REPL_HIVE_BASE_DIR);
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
Path dumpAck = new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString());
assertTrue(fs.exists(dumpAck));
fs.delete(dumpAck, false);
@@ -1009,13 +1009,13 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(failoverReadyMarker));
primary.run("ALTER DATABASE " + primaryDbName + " SET DBPROPERTIES('" +
ReplConst.REPL_FAILOVER_ENDPOINT + "'='"
+ MetaStoreUtils.FailoverEndpoint.SOURCE + "')");
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(primaryDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
WarehouseInstance.Tuple newDumpData = primary.dump(primaryDbName,
retainPrevDumpDir);
assertEquals(newDumpData.dumpLocation, dumpData.dumpLocation);
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(primaryDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(primaryDbName)));
assertTrue(fs.exists(new Path(dumpPath, DUMP_ACKNOWLEDGEMENT.toString())));
assertFalse(fs.exists(new Path(dumpPath,
FailoverMetaData.FAILOVER_METADATA)));
assertFalse(fs.exists(new Path(dumpPath,
ReplAck.FAILOVER_READY_MARKER.toString())));
@@ -1026,7 +1026,7 @@ public class TestReplicationScenariosAcidTables extends
BaseReplicationScenarios
assertTrue(fs.exists(new Path(dumpPath, LOAD_ACKNOWLEDGEMENT.toString())));
db = replica.getDatabase(replicatedDbName);
assertTrue(MetaStoreUtils.isTargetOfReplication(db));
- assertFalse(MetaStoreUtils.isDbBeingFailedOver(db));
+ assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(db));
}
private long getLatestDumpDirModifTime(Path dumpRoot) throws Exception {
diff --git
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestScheduledReplicationScenarios.java
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestScheduledReplicationScenarios.java
index 1887587ddbb..ff7733d2b9b 100644
---
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestScheduledReplicationScenarios.java
+++
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestScheduledReplicationScenarios.java
@@ -300,9 +300,9 @@ public class TestScheduledReplicationScenarios extends
BaseReplicationScenariosA
Path failoverReadyMarker = new Path(dumpRoot, String.valueOf(next) +
File.separator + ReplUtils.REPL_HIVE_BASE_DIR
+ File.separator + ReplAck.FAILOVER_READY_MARKER.toString());
assertTrue(fs.exists(failoverReadyMarker));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(sourceDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(sourceDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(replica.getDatabase(replicaDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(replica.getDatabase(replicaDbName),
MetaStoreUtils.FailoverEndpoint.TARGET));
primary.run("alter scheduled query repl_dump_p1 disabled")
@@ -331,7 +331,7 @@ public class TestScheduledReplicationScenarios extends
BaseReplicationScenariosA
Database primaryDb = primary.getDatabase(sourceDbName);
assertFalse(primaryDb == null);
assertTrue(MetaStoreUtils.isTargetOfReplication(primaryDb));
- assertFalse(MetaStoreUtils.isDbBeingFailedOver(primaryDb));
+ assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primaryDb));
next = Integer.parseInt(ReplDumpWork.getTestInjectDumpDir()) + 1;
ackPath = new Path(dumpRoot,
@@ -339,7 +339,7 @@ public class TestScheduledReplicationScenarios extends
BaseReplicationScenariosA
+ File.separator +
ReplAck.LOAD_ACKNOWLEDGEMENT.toString());
waitForAck(fs, ackPath, DEFAULT_PROBE_TIMEOUT);
assertFalse(ReplUtils.isFirstIncPending(primary.getDatabase(sourceDbName).getParameters()));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(replica.getDatabase(replicaDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(replica.getDatabase(replicaDbName)));
//Start failback from here.
replica.run("alter scheduled query repl_dump_p2 defined as repl dump "
+ replicaDbName + " WITH(" + startFailoverClause + ')');
@@ -353,9 +353,9 @@ public class TestScheduledReplicationScenarios extends
BaseReplicationScenariosA
failoverReadyMarker = new Path(dumpRoot, String.valueOf(next) +
File.separator + ReplUtils.REPL_HIVE_BASE_DIR
+ File.separator + ReplAck.FAILOVER_READY_MARKER.toString());
assertTrue(fs.exists(failoverReadyMarker));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(replica.getDatabase(replicaDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(replica.getDatabase(replicaDbName),
MetaStoreUtils.FailoverEndpoint.SOURCE));
-
assertTrue(MetaStoreUtils.isDbBeingFailedOverAtEndpoint(primary.getDatabase(sourceDbName),
+
assertTrue(MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(primary.getDatabase(sourceDbName),
MetaStoreUtils.FailoverEndpoint.TARGET));
replica.run("alter scheduled query repl_dump_p2 disabled")
@@ -382,7 +382,7 @@ public class TestScheduledReplicationScenarios extends
BaseReplicationScenariosA
Database replicaDb = replica.getDatabase(replicaDbName);
assertFalse(replicaDb == null);
assertTrue(MetaStoreUtils.isTargetOfReplication(replicaDb));
- assertFalse(MetaStoreUtils.isDbBeingFailedOver(replicaDb));
+ assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(replicaDb));
next = Integer.parseInt(ReplDumpWork.getTestInjectDumpDir()) + 1;
ackPath = new Path(dumpRoot,
@@ -390,7 +390,7 @@ public class TestScheduledReplicationScenarios extends
BaseReplicationScenariosA
+ File.separator +
ReplAck.LOAD_ACKNOWLEDGEMENT.toString());
waitForAck(fs, ackPath, DEFAULT_PROBE_TIMEOUT);
assertFalse(ReplUtils.isFirstIncPending(replica.getDatabase(replicaDbName).getParameters()));
-
assertFalse(MetaStoreUtils.isDbBeingFailedOver(primary.getDatabase(sourceDbName)));
+
assertFalse(MetaStoreUtils.isDbBeingPlannedFailedOver(primary.getDatabase(sourceDbName)));
} finally {
primary.run("drop database if exists " + sourceDbName + "
cascade").run("drop scheduled query repl_dump_p1");
diff --git a/metastore/scripts/upgrade/hive/hive-schema-4.0.0.hive.sql
b/metastore/scripts/upgrade/hive/hive-schema-4.0.0.hive.sql
index 577778c6d62..65e4e5eaf2a 100644
--- a/metastore/scripts/upgrade/hive/hive-schema-4.0.0.hive.sql
+++ b/metastore/scripts/upgrade/hive/hive-schema-4.0.0.hive.sql
@@ -1586,6 +1586,23 @@ TBLPROPERTIES (
FROM \"NOTIFICATION_LOG\""
);
+CREATE OR REPLACE VIEW `REPLICATION_FAILOVER_FAILBACK_METRICS` (
+ `DB_NAME`,
+ `DB_REPL_METRICS_NAME`,
+ `DB_REPL_METRICS_VALUE`
+) AS
+SELECT DISTINCT
+ A.`NAME`,
+ B.`PARAM_KEY`,
+ B.`PARAM_VALUE`
+FROM SYS.DBS A
+JOIN SYS.DATABASE_PARAMS B
+WHERE
+ A.DB_ID=B.DB_ID
+ AND
+ B.PARAM_KEY LIKE 'repl_metrics%';
+
+
CREATE DATABASE IF NOT EXISTS INFORMATION_SCHEMA;
USE INFORMATION_SCHEMA;
diff --git
a/metastore/scripts/upgrade/hive/upgrade-4.0.0-alpha-1-to-4.0.0-alpha-2.hive.sql
b/metastore/scripts/upgrade/hive/upgrade-4.0.0-alpha-1-to-4.0.0-alpha-2.hive.sql
index 0d5af37fe02..91481455554 100644
---
a/metastore/scripts/upgrade/hive/upgrade-4.0.0-alpha-1-to-4.0.0-alpha-2.hive.sql
+++
b/metastore/scripts/upgrade/hive/upgrade-4.0.0-alpha-1-to-4.0.0-alpha-2.hive.sql
@@ -219,6 +219,22 @@ SELECT
CQ_TBLPROPERTIES
FROM COMPACTION_QUEUE;
+CREATE OR REPLACE VIEW `REPLICATION_FAILOVER_FAILBACK_METRICS` (
+ `DB_NAME`,
+ `DB_REPL_METRICS_NAME`,
+ `DB_REPL_METRICS_VALUE`
+) AS
+SELECT DISTINCT
+ A.`NAME`,
+ B.`PARAM_KEY`,
+ B.`PARAM_VALUE`
+FROM SYS.DBS A
+JOIN SYS.DATABASE_PARAMS B
+WHERE
+ A.DB_ID=B.DB_ID
+ AND
+ B.PARAM_KEY LIKE 'repl_metrics%';
+
CREATE OR REPLACE VIEW `TRANSACTIONS` (
`TXN_ID`,
`STATE`,
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTask.java
b/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTask.java
index 6b14febc176..3e3ae8e18d6 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTask.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTask.java
@@ -18,6 +18,7 @@
package org.apache.hadoop.hive.ql.exec.repl;
import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.math.NumberUtils;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
@@ -260,6 +261,25 @@ public class ReplDumpTask extends Task<ReplDumpWork>
implements Serializable {
// Before starting optimised bootstrap, check if the first
incremental is done to ensure database is in
// consistent state.
isFirstIncrementalPending(work.dbNameOrPattern, getHive());
+ Database database = getHive().getDatabase(work.dbNameOrPattern);
+ if (database != null) {
+ HashMap<String, String> params = new
HashMap<>(database.getParameters());
+ long failbackStartTime = System.currentTimeMillis();
+ params.put(ReplConst.REPL_METRICS_LAST_FAILBACK_STARTTIME,
Long.toString(failbackStartTime));
+ LOG.info("Replication Metrics: Setting replication metrics
failback start time for database: {} to: {} ", work.dbNameOrPattern,
failbackStartTime);
+ if (!MetaStoreUtils.isDbBeingPlannedFailedOver(database)) { //
if this is failback due to unplanned failover
+ LOG.info("Replication Metrics: Setting last failover type
for database: {} to: {} ", work.dbNameOrPattern,
ReplConst.FailoverType.UNPLANNED.toString());
+ params.put(ReplConst.REPL_METRICS_LAST_FAILOVER_TYPE,
ReplConst.FailoverType.UNPLANNED.toString());
+
+ int failoverCount = 1 +
NumberUtils.toInt(params.getOrDefault(ReplConst.REPL_METRICS_FAILOVER_COUNT,
"0"), 0);
+ LOG.info("Replication Metrics: Setting replication metrics
failover count for database: {} to: {} ", work.dbNameOrPattern, failoverCount);
+ params.put(ReplConst.REPL_METRICS_FAILOVER_COUNT,
Integer.toString(failoverCount));
+ }
+ database.setParameters(params);
+ getHive().alterDatabase(work.dbNameOrPattern, database);
+ } else {
+ LOG.debug("Database {} does not exist. Cannot set replication
failover failback metrics", work.dbNameOrPattern);
+ }
// Get the last replicated event id from the database.
String dbEventId =
getReplEventIdFromDatabase(work.dbNameOrPattern, getHive());
// Get the last replicated event id from the database with
respect to target.
@@ -369,12 +389,12 @@ public class ReplDumpTask extends Task<ReplDumpWork>
implements Serializable {
FileSystem fs = previousValidHiveDumpDir.getFileSystem(conf);
Database db = getHive().getDatabase(work.dbNameOrPattern);
if (isPrevFailoverReadyMarkerPresent) {
- if (MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.SOURCE)) {
+ if (MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.SOURCE)) {
//Since previous valid dump is failover ready and
repl.failover.endpoint is set for source, just rollback
// the failover process initiated in the previous iteration.
LOG.info("Rolling back failover initiated in previous dump
iteration.");
fs.delete(new Path(previousValidHiveDumpDir,
ReplAck.FAILOVER_READY_MARKER.toString()), true);
- } else if (MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET)) {
+ } else if (MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET)) {
//Since previous valid dump is failover ready and
repl.failover.endpoint is set for target,
// this means it is first dump operation in the reverse direction.
LOG.info("Switching to bootstrap dump as this is the first dump
execution after failover.");
@@ -481,6 +501,7 @@ public class ReplDumpTask extends Task<ReplDumpWork>
implements Serializable {
private void finishRemainingTasks() throws HiveException {
+ Database database = getHive().getDatabase(work.dbNameOrPattern);
boolean isFailoverInProgress = shouldFailover() && !work.isBootstrap() &&
!createEventMarker;
if (isFailoverInProgress) {
Utils.create(new Path(work.getCurrentDumpPath(),
ReplUtils.REPL_HIVE_BASE_DIR + File.separator
@@ -492,26 +513,38 @@ public class ReplDumpTask extends Task<ReplDumpWork>
implements Serializable {
// Check if we need to unset database properties after successful
optimised bootstrap.
if (work.isSecondDumpAfterFailover()) {
- Hive hiveDb = getHive();
- Database database = hiveDb.getDatabase(work.dbNameOrPattern);
- LinkedHashMap<String, String> dbParams = new
LinkedHashMap<>(database.getParameters());
- LOG.debug("Database {} params before removal {}", work.dbNameOrPattern,
dbParams);
- dbParams.remove(TARGET_OF_REPLICATION);
- dbParams.remove(CURR_STATE_ID_TARGET.toString());
- dbParams.remove(CURR_STATE_ID_SOURCE.toString());
- dbParams.remove(REPL_TARGET_DB_PROPERTY);
- dbParams.remove(ReplConst.REPL_ENABLE_BACKGROUND_THREAD);
- dbParams.remove(REPL_RESUME_STARTED_AFTER_FAILOVER);
- if (!isFailoverInProgress) {
- // if we have failover endpoint from controlled failover remove it.
- dbParams.remove(ReplConst.REPL_FAILOVER_ENDPOINT);
+ if (database != null) {
+ HashMap<String, String> dbParams = new
HashMap<>(database.getParameters());
+ LOG.debug("Database {} params before removal {}",
work.dbNameOrPattern, dbParams);
+ dbParams.remove(TARGET_OF_REPLICATION);
+ dbParams.remove(CURR_STATE_ID_TARGET.toString());
+ dbParams.remove(CURR_STATE_ID_SOURCE.toString());
+ dbParams.remove(REPL_TARGET_DB_PROPERTY);
+ dbParams.remove(ReplConst.REPL_ENABLE_BACKGROUND_THREAD);
+ dbParams.remove(REPL_RESUME_STARTED_AFTER_FAILOVER);
+ if (!isFailoverInProgress) {
+ // if we have failover endpoint from controlled failover remove it.
+ dbParams.remove(ReplConst.REPL_FAILOVER_ENDPOINT);
+ }
+
+ LOG.info("Removing {} property from the database {} after successful
optimised bootstrap dump", String.join(",",
+ new String[]{TARGET_OF_REPLICATION,
CURR_STATE_ID_TARGET.toString(), CURR_STATE_ID_SOURCE.toString(),
+ REPL_TARGET_DB_PROPERTY}), work.dbNameOrPattern);
+
+ int failbackCount = 1 +
NumberUtils.toInt(dbParams.getOrDefault(ReplConst.REPL_METRICS_FAILBACK_COUNT,
"0"), 0);
+ LOG.info("Replication Metrics: Setting replication metrics failback
count for database: {} to: {} ", work.dbNameOrPattern, failbackCount);
+ dbParams.put(ReplConst.REPL_METRICS_FAILBACK_COUNT,
Integer.toString(failbackCount));
+
+ long failbackEndTime = System.currentTimeMillis();
+ dbParams.put(ReplConst.REPL_METRICS_LAST_FAILBACK_ENDTIME,
Long.toString(failbackEndTime));
+ LOG.info("Replication Metrics: Setting replication metrics failback
end time for database: {} to: {} ", work.dbNameOrPattern, failbackEndTime);
+
+ database.setParameters(dbParams);
+ getHive().alterDatabase(work.dbNameOrPattern, database);
+ LOG.debug("Database {} params after removal {}", work.dbNameOrPattern,
dbParams);
+ } else {
+ LOG.debug("Database {} does not exist. Cannot set replication failover
and failback metrics", work.dbNameOrPattern);
}
- database.setParameters(dbParams);
- LOG.info("Removing {} property from the database {} after successful
optimised bootstrap dump", String.join(",",
- new String[] { TARGET_OF_REPLICATION,
CURR_STATE_ID_TARGET.toString(), CURR_STATE_ID_SOURCE.toString(),
- REPL_TARGET_DB_PROPERTY }), work.dbNameOrPattern);
- hiveDb.alterDatabase(work.dbNameOrPattern, database);
- LOG.debug("Database {} paramas after removal {}", work.dbNameOrPattern,
dbParams);
}
Utils.create(dumpAckFile, conf);
prepareReturnValues(work.getResultValues());
@@ -850,8 +883,20 @@ public class ReplDumpTask extends Task<ReplDumpWork>
implements Serializable {
setReplSourceFor(hiveDb, dbName, db);
}
if (shouldFailover()) {
- if (!MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.SOURCE)) {
- setReplFailoverEnabledAtSource(db);
+ if (!MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.SOURCE)) {
+ // set repl failover enabled at source
+ HashMap<String, String> params = new HashMap<>(db.getParameters());
+ params.put(ReplConst.REPL_FAILOVER_ENDPOINT,
MetaStoreUtils.FailoverEndpoint.SOURCE.toString());
+
+ params.put(ReplConst.REPL_METRICS_LAST_FAILOVER_TYPE,
ReplConst.FailoverType.PLANNED.toString());
+ LOG.info("Replication Metrics: Setting last failover type for
database: {} to: {} ", dbName, ReplConst.FailoverType.PLANNED.toString());
+
+ int failoverCount = 1 +
NumberUtils.toInt(params.getOrDefault(ReplConst.REPL_METRICS_FAILOVER_COUNT,
"0"), 0);
+ LOG.info("Replication Metrics: Setting replication metrics failover
count for target database: {} to: {} ", dbName, failoverCount);
+ params.put(ReplConst.REPL_METRICS_FAILOVER_COUNT,
Integer.toString(failoverCount));
+
+ db.setParameters(params);
+ getHive().alterDatabase(work.dbNameOrPattern, db);
}
fetchFailoverMetadata(hiveDb);
assert work.getFailoverMetadata().isValidMetadata();
@@ -1129,7 +1174,7 @@ public class ReplDumpTask extends Task<ReplDumpWork>
implements Serializable {
collector = new BootstrapDumpMetricCollector(work.dbNameOrPattern,
dumpRoot.toString(), conf, executorId);
} else if (isFailover) {
// db property ReplConst.FAILOVER_ENDPOINT is only set during planned
failover.
- String failoverType =
MetaStoreUtils.isDbBeingFailedOver(getHive().getDatabase(work.dbNameOrPattern))
?
+ String failoverType =
MetaStoreUtils.isDbBeingPlannedFailedOver(getHive().getDatabase(work.dbNameOrPattern))
?
ReplConst.FailoverType.PLANNED.toString() :
ReplConst.FailoverType.UNPLANNED.toString();
if (isPreOptimisedBootstrap) {
collector = new
PreOptimizedBootstrapDumpMetricCollector(work.dbNameOrPattern,
dumpRoot.toString(), conf, executorId,
@@ -1435,18 +1480,6 @@ public class ReplDumpTask extends Task<ReplDumpWork>
implements Serializable {
dmd.write(true);
}
}
-
- private void setReplFailoverEnabledAtSource(Database db) throws
HiveException {
- Map<String, String> params = db.getParameters();
- if (params != null) {
- params.put(ReplConst.REPL_FAILOVER_ENDPOINT,
MetaStoreUtils.FailoverEndpoint.SOURCE.toString());
- } else {
-
db.setParameters(Collections.singletonMap(ReplConst.REPL_FAILOVER_ENDPOINT,
- MetaStoreUtils.FailoverEndpoint.SOURCE.toString()));
- }
- getHive().alterDatabase(work.dbNameOrPattern, db);
- }
-
private void setReplSourceFor(Hive hiveDb, String dbName, Database db)
throws HiveException {
if (!ReplChangeManager.isSourceOfReplication(db)) {
// Check if the schedule name is available else set the query value
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplLoadTask.java
b/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplLoadTask.java
index f577b169d44..82f30d1f26a 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplLoadTask.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplLoadTask.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hive.ql.exec.repl;
+import org.apache.commons.lang3.math.NumberUtils;
import org.apache.hadoop.hive.common.ValidTxnList;
import org.apache.hadoop.hive.common.repl.ReplConst;
import org.apache.hadoop.fs.Options;
@@ -612,18 +613,25 @@ public class ReplLoadTask extends Task<ReplLoadWork>
implements Serializable {
public void run() throws SemanticException {
try {
Database db = getHive().getDatabase(work.getTargetDatabase());
- if (MetaStoreUtils.isDbBeingFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET)) {
+ if (MetaStoreUtils.isDbBeingPlannedFailedOverAtEndpoint(db,
MetaStoreUtils.FailoverEndpoint.TARGET)) {
return;
}
- Map<String, String> params = db.getParameters();
- if (params == null) {
- params = new HashMap<>();
- db.setParameters(params);
- }
+ HashMap<String, String> params = new
HashMap<>(db.getParameters());
+
LOG.info("Setting failover endpoint:{} to TARGET for database:
{}", ReplConst.REPL_FAILOVER_ENDPOINT, db.getName());
params.put(ReplConst.REPL_FAILOVER_ENDPOINT,
MetaStoreUtils.FailoverEndpoint.TARGET.toString());
LOG.info("Setting {} for database: {}",
ReplConst.REPL_ENABLE_BACKGROUND_THREAD, db.getName());
params.put(ReplConst.REPL_ENABLE_BACKGROUND_THREAD,"true");
+
+ // we are here due to planned failover
+ params.put(ReplConst.REPL_METRICS_LAST_FAILOVER_TYPE,
ReplConst.FailoverType.PLANNED.toString());
+ LOG.info("Replication Metrics: Setting last failover type for
database: {} to: {} ", db.getName(), ReplConst.FailoverType.PLANNED.toString());
+
+ int failoverCount = 1 +
NumberUtils.toInt(params.getOrDefault(ReplConst.REPL_METRICS_FAILOVER_COUNT,
"0"), 0);
+ LOG.info("Replication Metrics: Setting replication metrics
failover count for database: {} to: {} ", db.getName(), failoverCount);
+ params.put(ReplConst.REPL_METRICS_FAILOVER_COUNT,
Integer.toString(failoverCount));
+
+ db.setParameters(params);
getHive().alterDatabase(work.getTargetDatabase(), db);
} catch (HiveException e) {
throw new SemanticException(e);
@@ -640,16 +648,26 @@ public class ReplLoadTask extends Task<ReplLoadWork>
implements Serializable {
try {
Hive hiveDb = getHive();
Database db = hiveDb.getDatabase(work.getTargetDatabase());
- LinkedHashMap<String, String> params = new
LinkedHashMap<>(db.getParameters());
+ HashMap<String, String> params = new
HashMap<>(db.getParameters());
LOG.debug("Database {} properties before removal {}",
work.getTargetDatabase(), params);
params.remove(REPL_RESUME_STARTED_AFTER_FAILOVER);
params.remove(SOURCE_OF_REPLICATION);
if (!work.shouldFailover()) {
params.remove(REPL_FAILOVER_ENDPOINT);
}
- db.setParameters(params);
+
LOG.info("Removed {} property from database {} after successful
optimised bootstrap load.",
SOURCE_OF_REPLICATION, work.getTargetDatabase());
+
+ int failbackCount = 1 +
NumberUtils.toInt(params.getOrDefault(ReplConst.REPL_METRICS_FAILBACK_COUNT,
"0"), 0);
+ LOG.info("Replication Metrics: Setting replication metrics
failback count for database: {} to: {} ", db.getName(), failbackCount);
+ params.put(ReplConst.REPL_METRICS_FAILBACK_COUNT,
Integer.toString(failbackCount));
+
+ long failbackEndTime = System.currentTimeMillis();
+ params.put(ReplConst.REPL_METRICS_LAST_FAILBACK_ENDTIME,
Long.toString(failbackEndTime));
+ LOG.info("Replication Metrics: Setting replication metrics
failback end time for database: {} to: {} ", db.getName(), failbackEndTime);
+
+ db.setParameters(params);
hiveDb.alterDatabase(work.getTargetDatabase(), db);
LOG.debug("Database {} poperties after removal {}",
work.getTargetDatabase(), params);
} catch (HiveException e) {
@@ -777,6 +795,23 @@ public class ReplLoadTask extends Task<ReplLoadWork>
implements Serializable {
LOG.error("The database {} is already source of replication.",
targetDb.getName());
throw new Exception("Failover target was not source of replication");
}
+ Map<String, String> params = targetDb.getParameters();
+ if (params == null) {
+ params = new HashMap<>();
+ }
+
+ long failbackStartTime = System.currentTimeMillis();
+ params.put(ReplConst.REPL_METRICS_LAST_FAILBACK_STARTTIME,
Long.toString(failbackStartTime));
+ LOG.info("Replication Metrics: Setting replication metrics failback
starttime for database: {} to: {} ", targetDb.getName(), failbackStartTime);
+ if (!MetaStoreUtils.isDbBeingPlannedFailedOver(targetDb)) { // if this
is failback due to unplanned failover
+ LOG.info("Replication Metrics: Setting last failover type for
database: {} to: {} ", targetDb.getName(),
ReplConst.FailoverType.UNPLANNED.toString());
+ params.put(ReplConst.REPL_METRICS_LAST_FAILOVER_TYPE,
ReplConst.FailoverType.UNPLANNED.toString());
+
+ int failoverCount = 1 +
NumberUtils.toInt(params.getOrDefault(ReplConst.REPL_METRICS_FAILOVER_COUNT,
"0"), 0);
+ LOG.info("Replication Metrics: Setting replication metrics failover
count for database: {} to: {} ", targetDb.getName(), failoverCount);
+ params.put(ReplConst.REPL_METRICS_FAILOVER_COUNT,
Integer.toString(failoverCount));
+ }
+
work.getMetricCollector().reportStageStart(STAGE_NAME, new HashMap<>());
boolean isTableDiffPresent =
checkFileExists(new Path(work.dumpDirectory).getParent(), conf,
TABLE_DIFF_COMPLETE_DIRECTORY);
@@ -804,6 +839,8 @@ public class ReplLoadTask extends Task<ReplLoadWork>
implements Serializable {
createReplLoadCompleteAckTask();
work.getMetricCollector().reportStageEnd(STAGE_NAME, Status.SUCCESS);
work.getMetricCollector().reportEnd(Status.SUCCESS);
+ targetDb.setParameters(params);
+ getHive().alterDatabase(work.dbNameToLoadIn, targetDb);
return 0;
} else if (work.isSecondFailover) {
// DROP the tables extra on target, which are not on source cluster.
@@ -838,7 +875,7 @@ public class ReplLoadTask extends Task<ReplLoadWork>
implements Serializable {
if (!MetaStoreUtils.isTargetOfReplication(targetDb)) {
props.put(ReplConst.TARGET_OF_REPLICATION, ReplConst.TRUE);
}
- if (!work.shouldFailover() &&
MetaStoreUtils.isDbBeingFailedOver(targetDb)) {
+ if (!work.shouldFailover() &&
MetaStoreUtils.isDbBeingPlannedFailedOver(targetDb)) {
props.put(ReplConst.REPL_FAILOVER_ENDPOINT, "");
}
if (!props.isEmpty()) {
diff --git
a/ql/src/java/org/apache/hadoop/hive/ql/parse/ReplicationSemanticAnalyzer.java
b/ql/src/java/org/apache/hadoop/hive/ql/parse/ReplicationSemanticAnalyzer.java
index 65c5c344555..0e810f13d6b 100644
---
a/ql/src/java/org/apache/hadoop/hive/ql/parse/ReplicationSemanticAnalyzer.java
+++
b/ql/src/java/org/apache/hadoop/hive/ql/parse/ReplicationSemanticAnalyzer.java
@@ -397,7 +397,7 @@ public class ReplicationSemanticAnalyzer extends
BaseSemanticAnalyzer {
String failoverType = "";
try {
// check whether ReplConst.FAILOVER_ENDPOINT is set
- failoverType =
MetaStoreUtils.isDbBeingFailedOver(db.getDatabase(dbNameToLoadIn)) ?
ReplConst.FailoverType.PLANNED.toString() :
ReplConst.FailoverType.UNPLANNED.toString();
+ failoverType =
MetaStoreUtils.isDbBeingPlannedFailedOver(db.getDatabase(dbNameToLoadIn)) ?
ReplConst.FailoverType.PLANNED.toString() :
ReplConst.FailoverType.UNPLANNED.toString();
} catch (HiveException e) {
throw new RuntimeException(e);
}
diff --git
a/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUpdaterThread.java
b/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUpdaterThread.java
index 43c41ebbaef..2f6dd2c378e 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUpdaterThread.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUpdaterThread.java
@@ -624,7 +624,7 @@ public class StatsUpdaterThread extends Thread implements
MetaStoreThread {
SessionState.start(ss); // This is the first call, open the session
}
TableName tb = req.tableName;
- if (MetaStoreUtils.isDbBeingFailedOver(rs.getDatabase(tb.getCat(),
tb.getDb()))) {
+ if
(MetaStoreUtils.isDbBeingPlannedFailedOver(rs.getDatabase(tb.getCat(),
tb.getDb()))) {
LOG.info("Skipping table: {} as it belongs to database which is being
failed over." + tb.getTable());
return true;
}
diff --git a/ql/src/test/results/clientpositive/llap/resourceplan.q.out
b/ql/src/test/results/clientpositive/llap/resourceplan.q.out
index cd9c57dd31d..3e1f906c411 100644
--- a/ql/src/test/results/clientpositive/llap/resourceplan.q.out
+++ b/ql/src/test/results/clientpositive/llap/resourceplan.q.out
@@ -218,6 +218,10 @@ sys partitions hive_test_user
USER DELETE true -1 hive_test_user
sys partitions hive_test_user USER INSERT true
-1 hive_test_user
sys partitions hive_test_user USER SELECT true
-1 hive_test_user
sys partitions hive_test_user USER UPDATE true
-1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER DELETE true -1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER INSERT true -1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER SELECT true -1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER UPDATE true -1 hive_test_user
sys replication_metrics hive_test_user USER DELETE
true -1 hive_test_user
sys replication_metrics hive_test_user USER INSERT
true -1 hive_test_user
sys replication_metrics hive_test_user USER SELECT
true -1 hive_test_user
diff --git
a/ql/src/test/results/clientpositive/llap/strict_managed_tables_sysdb.q.out
b/ql/src/test/results/clientpositive/llap/strict_managed_tables_sysdb.q.out
index e509d588687..9f4d87ef5ca 100644
--- a/ql/src/test/results/clientpositive/llap/strict_managed_tables_sysdb.q.out
+++ b/ql/src/test/results/clientpositive/llap/strict_managed_tables_sysdb.q.out
@@ -308,6 +308,10 @@ sys partitions hive_test_user
USER DELETE true -1 hive_test_user
sys partitions hive_test_user USER INSERT true
-1 hive_test_user
sys partitions hive_test_user USER SELECT true
-1 hive_test_user
sys partitions hive_test_user USER UPDATE true
-1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER DELETE true -1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER INSERT true -1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER SELECT true -1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER UPDATE true -1 hive_test_user
sys replication_metrics hive_test_user USER DELETE
true -1 hive_test_user
sys replication_metrics hive_test_user USER INSERT
true -1 hive_test_user
sys replication_metrics hive_test_user USER SELECT
true -1 hive_test_user
@@ -506,6 +510,7 @@ PREHOOK: Output: sys@partition_keys
PREHOOK: Output: sys@partition_params
PREHOOK: Output: sys@partition_stats_view
PREHOOK: Output: sys@partitions
+PREHOOK: Output: sys@replication_failover_failback_metrics
PREHOOK: Output: sys@replication_metrics
PREHOOK: Output: sys@replication_metrics_orig
PREHOOK: Output: sys@role_map
@@ -569,6 +574,7 @@ POSTHOOK: Output: sys@partition_keys
POSTHOOK: Output: sys@partition_params
POSTHOOK: Output: sys@partition_stats_view
POSTHOOK: Output: sys@partitions
+POSTHOOK: Output: sys@replication_failover_failback_metrics
POSTHOOK: Output: sys@replication_metrics
POSTHOOK: Output: sys@replication_metrics_orig
POSTHOOK: Output: sys@role_map
diff --git a/ql/src/test/results/clientpositive/llap/sysdb.q.out
b/ql/src/test/results/clientpositive/llap/sysdb.q.out
index 616b57a4274..526cd682570 100644
--- a/ql/src/test/results/clientpositive/llap/sysdb.q.out
+++ b/ql/src/test/results/clientpositive/llap/sysdb.q.out
@@ -264,6 +264,10 @@ sys partitions hive_test_user
USER DELETE true -1 hive_test_user
sys partitions hive_test_user USER INSERT true
-1 hive_test_user
sys partitions hive_test_user USER SELECT true
-1 hive_test_user
sys partitions hive_test_user USER UPDATE true
-1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER DELETE true -1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER INSERT true -1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER SELECT true -1 hive_test_user
+sys replication_failover_failback_metrics hive_test_user
USER UPDATE true -1 hive_test_user
sys replication_metrics hive_test_user USER DELETE
true -1 hive_test_user
sys replication_metrics hive_test_user USER INSERT
true -1 hive_test_user
sys replication_metrics hive_test_user USER SELECT
true -1 hive_test_user
@@ -779,6 +783,9 @@ partitions part_id
partitions part_name
partitions sd_id
partitions tbl_id
+replication_failover_failback_metrics db_name
+replication_failover_failback_metrics db_repl_metrics_name
+replication_failover_failback_metrics db_repl_metrics_value
replication_metrics dump_execution_id
replication_metrics metadata
replication_metrics policy_name
@@ -1305,7 +1312,7 @@ POSTHOOK: query: select count(*) from sds
POSTHOOK: type: QUERY
POSTHOOK: Input: sys@sds
#### A masked pattern was here ####
-78
+79
PREHOOK: query: select param_key, param_value from sd_params order by
param_key, param_value limit 5
PREHOOK: type: QUERY
PREHOOK: Input: sys@sd_params
@@ -1715,6 +1722,7 @@ default sys partition_keys BASE_TABLE NULL
NULL NULL NULL NULL YES NO NULL
default sys partition_params BASE_TABLE NULL NULL
NULL NULL NULL YES NO NULL
default sys partition_stats_view VIEW NULL NULL NULL
NULL NULL NO NO NULL
default sys partitions BASE_TABLE NULL NULL NULL
NULL NULL YES NO NULL
+default sys replication_failover_failback_metrics VIEW NULL
NULL NULL NULL NULL NO NO NULL
default sys replication_metrics VIEW NULL NULL NULL
NULL NULL NO NO NULL
default sys replication_metrics_orig BASE_TABLE NULL
NULL NULL NULL NULL YES NO NULL
default sys role_map BASE_TABLE NULL NULL NULL
NULL NULL YES NO NULL
@@ -1842,6 +1850,7 @@ information_schema views
sys compactions
sys locks
sys partition_stats_view
+sys replication_failover_failback_metrics
sys replication_metrics
sys table_stats_view
sys transactions
diff --git
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/common/repl/ReplConst.java
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/common/repl/ReplConst.java
index 9641149f6cc..54e2b12afd9 100644
---
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/common/repl/ReplConst.java
+++
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/common/repl/ReplConst.java
@@ -92,4 +92,14 @@ public class ReplConst {
PLANNED,
UNPLANNED;
}
+
+ /**
+ * Database level property to keep track of failover and failback metrics
+ * Property values are set during failover and optimised bootstrap time.
+ */
+ public static final String REPL_METRICS_FAILOVER_COUNT =
"repl.metrics.failover.count";
+ public static final String REPL_METRICS_LAST_FAILOVER_TYPE =
"repl.metrics.last.failover.type";
+ public static final String REPL_METRICS_FAILBACK_COUNT =
"repl.metrics.failback.count";
+ public static final String REPL_METRICS_LAST_FAILBACK_STARTTIME =
"repl.metrics.last.failback.starttime";
+ public static final String REPL_METRICS_LAST_FAILBACK_ENDTIME =
"repl.metrics.last.failback.endtime";
}
diff --git
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java
index 00c278ec51b..9cc59c6c5b7 100644
---
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java
+++
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java
@@ -274,7 +274,7 @@ public class MetaStoreUtils {
return dbParameters != null &&
ReplConst.TRUE.equalsIgnoreCase(dbParameters.get(ReplConst.REPL_INCOMPATIBLE));
}
- public static boolean isDbBeingFailedOver(Database db) {
+ public static boolean isDbBeingPlannedFailedOver(Database db) {
assert (db != null);
Map<String, String> dbParameters = db.getParameters();
if (dbParameters == null) {
@@ -285,7 +285,7 @@ public class MetaStoreUtils {
||
FailoverEndpoint.TARGET.toString().equalsIgnoreCase(dbFailoverEndPoint);
}
- public static boolean isDbBeingFailedOverAtEndpoint(Database db,
FailoverEndpoint endPoint) {
+ public static boolean isDbBeingPlannedFailedOverAtEndpoint(Database db,
FailoverEndpoint endPoint) {
if (db == null) {
return false;
}
@@ -310,7 +310,7 @@ public class MetaStoreUtils {
assert (db != null);
if (isBackgroundThreadsEnabledForRepl(db)) {
return false;
- } else if (isDbBeingFailedOver(db)) {
+ } else if (isDbBeingPlannedFailedOver(db)) {
LOG.info("Skipping all the tables which belong to database: {} as it is
being failed over", db.getName());
return true;
} else if (isTargetOfReplication(db)) {
diff --git
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PartitionManagementTask.java
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PartitionManagementTask.java
index bd87483a6c7..a9ef163a9b0 100644
---
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PartitionManagementTask.java
+++
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PartitionManagementTask.java
@@ -234,7 +234,7 @@ public class PartitionManagementTask implements
MetastoreTaskThread {
IMetaStoreClient msc = null;
try {
msc = new HiveMetaStoreClient(conf);
- if
(MetaStoreUtils.isDbBeingFailedOver((msc.getDatabase(msckInfo.getCatalogName(),
msckInfo.getDbName())))) {
+ if
(MetaStoreUtils.isDbBeingPlannedFailedOver((msc.getDatabase(msckInfo.getCatalogName(),
msckInfo.getDbName())))) {
LOG.info("Skipping table: {} as it belongs to database being failed
over." + msckInfo.getTableName());
return;
}