Skip to content

Commit 4669cd5

Browse files
HIVE-29073: Overlay modified session level metaconf to new hmsclient connection (#6042)
1 parent 2fdb839 commit 4669cd5

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6465,6 +6465,21 @@ public List<Function> getFunctionsInDb(String dbName, String pattern) throws Hiv
64656465

64666466
public void setMetaConf(String propName, String propValue) throws HiveException {
64676467
try {
6468+
/*
6469+
* Updates the 'conf' object with session-level metastore variables
6470+
* ('metaConfVars'). This object is used to initialize the
6471+
* Thrift client connection to the Hive Metastore, ensuring that any
6472+
* session-specific overrides are propagated to the underlying connection.
6473+
*
6474+
* For reference on how this 'conf' object is consumed, see the client
6475+
* instantiation logic in:
6476+
* org.apache.hadoop.hive.ql.metadata.Hive#createMetaStoreClient()
6477+
*/
6478+
if (Arrays.stream(MetastoreConf.metaConfVars)
6479+
.anyMatch(s -> s.getVarname().equals(propName))) {
6480+
// Storing varname prevents conflicts with HiveServer2-level configurations
6481+
conf.set(propName, propValue);
6482+
}
64686483
getMSC().setMetaConf(propName, propValue);
64696484
} catch (TException te) {
64706485
throw new HiveException(te);

standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/client/ThriftHiveMetaStoreClient.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ private void open() throws MetaException {
763763
LOG.error(errMsg, e);
764764
}
765765
if (isConnected) {
766+
// Set the beeline session modified metaConfVars for new HMS connection
767+
overlaySessionModifiedMetaConf();
766768
break;
767769
}
768770
}
@@ -792,6 +794,23 @@ private void open() throws MetaException {
792794
snapshotActiveConf();
793795
}
794796

797+
private void overlaySessionModifiedMetaConf() {
798+
for (MetastoreConf.ConfVars confVar : MetastoreConf.metaConfVars) {
799+
String confVal = conf.get(confVar.getVarname());
800+
if (!org.apache.commons.lang3.StringUtils.isBlank(confVal)) {
801+
try {
802+
setMetaConf(confVar.getVarname(), confVal);
803+
} catch (TException e) {
804+
LOG.error(
805+
"Failed to set metastore config for {} with value {}",
806+
confVar.getVarname(),
807+
confVal,
808+
e);
809+
}
810+
}
811+
}
812+
}
813+
795814
// wraps the underlyingTransport in the appropriate transport based on mode of authentication
796815
private TTransport createAuthBinaryTransport(URI store, TTransport underlyingTransport)
797816
throws MetaException {

standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ public String toString() {
225225
ConfVars.HMS_HANDLER_ATTEMPTS,
226226
ConfVars.HMS_HANDLER_INTERVAL,
227227
ConfVars.HMS_HANDLER_FORCE_RELOAD_CONF,
228-
ConfVars.PARTITION_NAME_WHITELIST_PATTERN,
229228
ConfVars.ORM_RETRIEVE_MAPNULLS_AS_EMPTY_STRINGS,
230229
ConfVars.USERS_IN_ADMIN_ROLE,
231230
ConfVars.HIVE_TXN_MANAGER,
@@ -244,18 +243,26 @@ public String toString() {
244243
ConfVars.AGGREGATE_STATS_CACHE_MAX_READER_WAIT,
245244
ConfVars.AGGREGATE_STATS_CACHE_MAX_FULL,
246245
ConfVars.AGGREGATE_STATS_CACHE_CLEAN_UNTIL,
247-
ConfVars.DISALLOW_INCOMPATIBLE_COL_TYPE_CHANGES,
248246
ConfVars.FILE_METADATA_THREADS,
249247
ConfVars.METASTORE_CLIENT_FILTER_ENABLED,
250248
ConfVars.METASTORE_SERVER_FILTER_ENABLED,
251249
ConfVars.METASTORE_PARTITIONS_PARAMETERS_INCLUDE_PATTERN,
252-
ConfVars.METASTORE_PARTITIONS_PARAMETERS_EXCLUDE_PATTERN
250+
ConfVars.METASTORE_PARTITIONS_PARAMETERS_EXCLUDE_PATTERN,
251+
// Add metaConfVars here as well
252+
ConfVars.TRY_DIRECT_SQL,
253+
ConfVars.TRY_DIRECT_SQL_DDL,
254+
ConfVars.CLIENT_SOCKET_TIMEOUT,
255+
ConfVars.PARTITION_NAME_WHITELIST_PATTERN,
256+
ConfVars.PARTITION_ORDER_EXPR,
257+
ConfVars.CAPABILITY_CHECK,
258+
ConfVars.DISALLOW_INCOMPATIBLE_COL_TYPE_CHANGES,
259+
ConfVars.EXPRESSION_PROXY_CLASS
253260
};
254261

255262
/**
256263
* User configurable Metastore vars
257264
*/
258-
private static final MetastoreConf.ConfVars[] metaConfVars = {
265+
public static final MetastoreConf.ConfVars[] metaConfVars = {
259266
ConfVars.TRY_DIRECT_SQL,
260267
ConfVars.TRY_DIRECT_SQL_DDL,
261268
ConfVars.CLIENT_SOCKET_TIMEOUT,

standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetastoreHttpHeaders.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ public void testHttpHeaders() throws Exception {
9696
public void testIllegalHttpHeaders() throws Exception {
9797
MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METASTORE_CLIENT_ADDITIONAL_HEADERS,
9898
String.format("%s%s", testHeaderKey1, testHeaderVal1));
99-
msc = new TestHiveMetaStoreClient(conf);
99+
try {
100+
msc = new TestHiveMetaStoreClient(conf);
101+
} catch (Exception ignored) {
102+
/*
103+
* This try catch is added because of setMetaConf in
104+
* org.apache.hadoop.hive.metastore.client.ThriftHiveMetaStoreClient.overlaySessionModifiedMetaConf
105+
* Because of wrong header (Negative Test) the exception is thrown during Client creation itself
106+
*/
107+
}
100108
boolean exceptionThrown = false;
101109
try {
102110
Database db = new DatabaseBuilder().setName("testHttpHeader").create(msc, conf);

standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ public void testListener() throws Exception {
262262
// Test adding multiple partitions in a single partition-set, atomically.
263263
int currentTime = (int)System.currentTimeMillis();
264264
HiveMetaStoreClient hmsClient = new HiveMetaStoreClient(conf);
265+
// A ConfigChangeEvent will be triggered on new Client creation because of
266+
// org.apache.hadoop.hive.metastore.client.ThriftHiveMetaStoreClient#overlaySessionModifiedMetaConf()
267+
++listSize;
265268
table = hmsClient.getTable(dbName, "tmptbl");
266269
Partition partition1 = new Partition(Arrays.asList("20110101"), dbName, "tmptbl", currentTime,
267270
currentTime, table.getSd(), table.getParameters());

0 commit comments

Comments
 (0)