-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-27172: Add the HMS client connection timeout config #4150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |
|
|
||
| package org.apache.hadoop.hive.metastore; | ||
|
|
||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
|
|
@@ -27,9 +29,11 @@ | |
| import org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder; | ||
| import org.apache.hadoop.hive.metastore.conf.MetastoreConf; | ||
| import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars; | ||
| import org.apache.hadoop.util.StringUtils; | ||
| import org.apache.thrift.transport.TTransportException; | ||
| import org.junit.After; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
|
|
@@ -43,9 +47,10 @@ public class TestHiveMetaStoreTimeout { | |
| protected static HiveMetaStoreClient client; | ||
| protected static Configuration conf; | ||
| protected static Warehouse warehouse; | ||
| protected static int port; | ||
|
|
||
| @BeforeClass | ||
| public static void setUp() throws Exception { | ||
| public static void startMetaStoreServer() throws Exception { | ||
| HMSHandler.testTimeoutEnabled = true; | ||
| conf = MetastoreConf.newMetastoreConf(); | ||
| MetastoreConf.setClass(conf, ConfVars.EXPRESSION_PROXY_CLASS, | ||
|
|
@@ -54,19 +59,25 @@ public static void setUp() throws Exception { | |
| TimeUnit.MILLISECONDS); | ||
| MetaStoreTestUtils.setConfForStandloneMode(conf); | ||
| warehouse = new Warehouse(conf); | ||
| client = new HiveMetaStoreClient(conf); | ||
| port = MetaStoreTestUtils.startMetaStoreWithRetry(conf); | ||
| MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); | ||
| MetastoreConf.setBoolVar(conf, ConfVars.EXECUTE_SET_UGI, false); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDown() throws Exception { | ||
| public static void tearDown() { | ||
| HMSHandler.testTimeoutEnabled = false; | ||
| try { | ||
| client.close(); | ||
| } catch (Throwable e) { | ||
| System.err.println("Unable to close metastore"); | ||
| System.err.println(StringUtils.stringifyException(e)); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Before | ||
| public void setup() throws MetaException { | ||
| client = new HiveMetaStoreClient(conf); | ||
| } | ||
|
|
||
| @After | ||
| public void cleanup() { | ||
| client.close(); | ||
| client = null; | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -96,9 +107,8 @@ public void testTimeout() throws Exception { | |
| try { | ||
| client.createDatabase(db); | ||
| Assert.fail("should throw timeout exception."); | ||
| } catch (MetaException e) { | ||
| Assert.assertTrue("unexpected MetaException", e.getMessage().contains("Timeout when " + | ||
| "executing method: create_database")); | ||
| } catch (TTransportException e) { | ||
| Assert.assertTrue("unexpected Exception", e.getMessage().contains("Read timed out")); | ||
| } | ||
|
|
||
| // restore | ||
|
|
@@ -117,7 +127,7 @@ public void testResetTimeout() throws Exception { | |
| .build(conf); | ||
| try { | ||
| client.createDatabase(db); | ||
| } catch (MetaException e) { | ||
| } catch (Exception e) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we have changed to use the remote MetaStore server in this test class, so the timeout exception was wrapped in |
||
| Assert.fail("should not throw timeout exception: " + e.getMessage()); | ||
| } | ||
| client.dropDatabase(dbName, true, true); | ||
|
|
@@ -130,13 +140,28 @@ public void testResetTimeout() throws Exception { | |
| try { | ||
| client.createDatabase(db); | ||
| Assert.fail("should throw timeout exception."); | ||
| } catch (MetaException e) { | ||
| Assert.assertTrue("unexpected MetaException", e.getMessage().contains("Timeout when " + | ||
| "executing method: create_database")); | ||
| } catch (TTransportException e) { | ||
| Assert.assertTrue("unexpected Exception", e.getMessage().contains("Read timed out")); | ||
| } | ||
| } | ||
|
|
||
| // restore | ||
| client.dropDatabase(dbName, true, true); | ||
| client.setMetaConf(ConfVars.CLIENT_SOCKET_TIMEOUT.getVarname(), "10s"); | ||
| @Test | ||
| public void testConnectionTimeout() throws Exception { | ||
| Configuration newConf = new Configuration(conf); | ||
| MetastoreConf.setTimeVar(newConf, ConfVars.CLIENT_CONNECTION_TIMEOUT, 1000, | ||
| TimeUnit.MILLISECONDS); | ||
| // fake host to mock connection time out | ||
| MetastoreConf.setVar(newConf, ConfVars.THRIFT_URIS, "thrift://1.1.1.1:" + port); | ||
| MetastoreConf.setLongVar(newConf, ConfVars.THRIFT_CONNECTION_RETRIES, 1); | ||
|
|
||
| Future<Void> future = Executors.newSingleThreadExecutor().submit(() -> { | ||
| try(HiveMetaStoreClient c = new HiveMetaStoreClient(newConf)) { | ||
| Assert.fail("should throw connection timeout exception."); | ||
| } catch (MetaException e) { | ||
| Assert.assertTrue("unexpected Exception", e.getMessage().contains("connect timed out")); | ||
| } | ||
| return null; | ||
| }); | ||
| future.get(5, TimeUnit.SECONDS); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This test code hacks
HMSHandlerclass, I will refactor this in a new PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to repeat the whole setup for every test or it's possible to extract just the HMSHandler part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed! Have separated the start of MetaStore Server into a
BeforeClassmethod.