Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit 7a5af64

Browse files
committed
Feature: Add option for destination database name prefix.
1 parent ac86065 commit 7a5af64

File tree

7 files changed

+309
-10
lines changed

7 files changed

+309
-10
lines changed

main/src/main/java/com/airbnb/reair/batch/hive/MetastoreReplicationJob.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ private void mergeConfiguration(Configuration inputConfig, Configuration merged)
317317
ConfigurationKeys.DEST_CLUSTER_METASTORE_URL,
318318
ConfigurationKeys.DEST_HDFS_ROOT,
319319
ConfigurationKeys.DEST_HDFS_TMP,
320+
ConfigurationKeys.DEST_CLUSTER_METASTORE_DB_PREFIX,
320321
ConfigurationKeys.BATCH_JOB_METASTORE_BLACKLIST,
321322
ConfigurationKeys.BATCH_JOB_CLUSTER_FACTORY_CLASS,
322323
ConfigurationKeys.BATCH_JOB_OUTPUT_DIR,

main/src/main/java/com/airbnb/reair/incremental/configuration/ConfiguredClusterFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,19 @@ public Cluster getDestCluster() throws ConfigurationException {
5555
ConfigurationKeys.DEST_HDFS_ROOT);
5656
String destHdfsTmp = conf.get(
5757
ConfigurationKeys.DEST_HDFS_TMP);
58+
// Note that the DEST_CLUSTER_METASTORE_DB_PREFIX is a special config that only exists on the
59+
// dest cluster (but not on the src cluster).
60+
String destDbPrefix = conf.get(
61+
ConfigurationKeys.DEST_CLUSTER_METASTORE_DB_PREFIX);
5862
return new HardCodedCluster(
5963
destClusterName,
6064
destMetastoreUrl.getHost(),
6165
destMetastoreUrl.getPort(),
6266
null,
6367
null,
6468
new Path(destHdfsRoot),
65-
new Path(destHdfsTmp));
69+
new Path(destHdfsTmp),
70+
destDbPrefix);
6671
}
6772

6873
@Override

main/src/main/java/com/airbnb/reair/incremental/configuration/HardCodedCluster.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.airbnb.reair.incremental.configuration;
22

3+
import com.airbnb.reair.common.DbPrefixHiveMetastoreClient;
4+
import com.airbnb.reair.common.HiveMetastoreClient;
35
import com.airbnb.reair.common.HiveMetastoreException;
46
import com.airbnb.reair.common.ThriftHiveMetastoreClient;
57

@@ -17,7 +19,8 @@ public class HardCodedCluster implements Cluster {
1719
private String jobtrackerPort;
1820
private Path hdfsRoot;
1921
private Path tmpDir;
20-
private ThreadLocal<ThriftHiveMetastoreClient> metastoreClient;
22+
private String dbNamePrefix;
23+
private ThreadLocal<HiveMetastoreClient> metastoreClient;
2124

2225
/**
2326
* Constructor with specific values.
@@ -29,6 +32,7 @@ public class HardCodedCluster implements Cluster {
2932
* @param jobtrackerPort port of the job tracker
3033
* @param hdfsRoot the path for the root HDFS directory
3134
* @param tmpDir the path for the temporary HDFS directory (should be under root)
35+
* @param dbNamePrefix optional prefix for all databases in the Hive metastore.
3236
*/
3337
public HardCodedCluster(
3438
String name,
@@ -37,15 +41,38 @@ public HardCodedCluster(
3741
String jobtrackerHost,
3842
String jobtrackerPort,
3943
Path hdfsRoot,
40-
Path tmpDir) {
44+
Path tmpDir,
45+
String dbNamePrefix) {
4146
this.name = name;
4247
this.metastoreHost = metastoreHost;
4348
this.metastorePort = metastorePort;
4449
this.jobtrackerHost = jobtrackerHost;
4550
this.jobtrackerPort = jobtrackerPort;
4651
this.hdfsRoot = hdfsRoot;
4752
this.tmpDir = tmpDir;
48-
this.metastoreClient = new ThreadLocal<ThriftHiveMetastoreClient>();
53+
this.dbNamePrefix = dbNamePrefix;
54+
this.metastoreClient = new ThreadLocal<>();
55+
}
56+
57+
/**
58+
* Constructor with specific values, with a default dbNamePrefix of null.
59+
*/
60+
public HardCodedCluster(
61+
String name,
62+
String metastoreHost,
63+
int metastorePort,
64+
String jobtrackerHost,
65+
String jobtrackerPort,
66+
Path hdfsRoot,
67+
Path tmpDir) {
68+
this(name,
69+
metastoreHost,
70+
metastorePort,
71+
jobtrackerHost,
72+
jobtrackerPort,
73+
hdfsRoot,
74+
tmpDir,
75+
null);
4976
}
5077

5178
public String getMetastoreHost() {
@@ -58,11 +85,17 @@ public int getMetastorePort() {
5885

5986
/**
6087
* Get a cached ThreadLocal metastore client.
88+
*
89+
* <p>Also applies a DbPrefixHiveMetastoreClient wrapper if dbNamePrefix is not null or
90+
* empty.
6191
*/
62-
public ThriftHiveMetastoreClient getMetastoreClient() throws HiveMetastoreException {
63-
ThriftHiveMetastoreClient result = this.metastoreClient.get();
92+
public HiveMetastoreClient getMetastoreClient() throws HiveMetastoreException {
93+
HiveMetastoreClient result = this.metastoreClient.get();
6494
if (result == null) {
6595
result = new ThriftHiveMetastoreClient(getMetastoreHost(), getMetastorePort());
96+
if (dbNamePrefix != null && !dbNamePrefix.isEmpty()) {
97+
result = new DbPrefixHiveMetastoreClient(result, dbNamePrefix);
98+
}
6699
this.metastoreClient.set(result);
67100
}
68101
return result;

main/src/main/java/com/airbnb/reair/incremental/deploy/ConfigurationKeys.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public class ConfigurationKeys {
5252
public static final String DEST_HDFS_ROOT = "airbnb.reair.clusters.dest.hdfs.root";
5353
// The root of the temporary directory for storing temporary files on the destination cluster
5454
public static final String DEST_HDFS_TMP = "airbnb.reair.clusters.dest.hdfs.tmp";
55+
// Prefix to add to any databases on the destination cluster. Mostly used for production testing.
56+
public static final String DEST_CLUSTER_METASTORE_DB_PREFIX =
57+
"airbnb.reair.clusters.dest.metastore.db.prefix";
5558

5659
// Class to use for filtering out entries from the audit log
5760
public static final String OBJECT_FILTER_CLASS = "airbnb.reair.object.filter";

main/src/main/java/com/airbnb/reair/incremental/deploy/HiveCopy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.airbnb.reair.common.ArgumentException;
44
import com.airbnb.reair.common.CliUtils;
5+
import com.airbnb.reair.common.HiveMetastoreClient;
56
import com.airbnb.reair.common.HiveObjectSpec;
6-
import com.airbnb.reair.common.ThriftHiveMetastoreClient;
77
import com.airbnb.reair.incremental.DirectoryCopier;
88
import com.airbnb.reair.incremental.ReplicationUtils;
99
import com.airbnb.reair.incremental.RunInfo;
@@ -160,7 +160,7 @@ public static int main(String[] args) throws Exception {
160160

161161
if ("copy-unpartitioned-table".equals(op)) {
162162
LOG.info("Copying an unpartitioned table");
163-
ThriftHiveMetastoreClient ms = srcCluster.getMetastoreClient();
163+
HiveMetastoreClient ms = srcCluster.getMetastoreClient();
164164
Table srcTable = ms.getTable(spec.getDbName(), spec.getTableName());
165165
CopyUnpartitionedTableTask job = new CopyUnpartitionedTableTask(conf,
166166
destinationObjectFactory, conflictHandler, srcCluster, destCluster, spec,
@@ -172,7 +172,7 @@ public static int main(String[] args) throws Exception {
172172
}
173173
} else if ("copy-partitioned-table".equals(op)) {
174174
LOG.info("Copying a partitioned table");
175-
ThriftHiveMetastoreClient ms = srcCluster.getMetastoreClient();
175+
HiveMetastoreClient ms = srcCluster.getMetastoreClient();
176176
Table srcTable = ms.getTable(spec.getDbName(), spec.getTableName());
177177
CopyPartitionedTableTask job = new CopyPartitionedTableTask(conf, destinationObjectFactory,
178178
conflictHandler, srcCluster, destCluster, spec, ReplicationUtils.getLocation(srcTable));
@@ -183,7 +183,7 @@ public static int main(String[] args) throws Exception {
183183
}
184184
} else if (op.equals("copy-partition")) {
185185
LOG.info("Copying a partition");
186-
ThriftHiveMetastoreClient ms = srcCluster.getMetastoreClient();
186+
HiveMetastoreClient ms = srcCluster.getMetastoreClient();
187187
Partition srcPartition =
188188
ms.getPartition(spec.getDbName(), spec.getTableName(), spec.getPartitionName());
189189
CopyPartitionTask job = new CopyPartitionTask(conf, destinationObjectFactory, conflictHandler,

main/src/main/resources/batch_replication_configuration_template.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
</comment>
6363
</property>
6464

65+
<property>
66+
<name>airbnb.reair.clusters.dest.metastore.db.prefix</name>
67+
<value></value>
68+
<comment>Optional prefix to add to destination Hive database names.</comment>
69+
</property>
70+
6571
<property>
6672
<name>airbnb.reair.clusters.batch.output.dir</name>
6773
<value>hdfs://airfs-test/user/test/test_output</value>

0 commit comments

Comments
 (0)