You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "zhangbutao (via GitHub)" <gi...@apache.org> on 2023/06/14 13:59:36 UTC
[GitHub] [hive] zhangbutao opened a new pull request, #4418: HIVE-27440: Improve data connector cache
zhangbutao opened a new pull request, #4418:
URL: https://github.com/apache/hive/pull/4418
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
3. Ensure you have added or run the appropriate tests for your PR:
4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX: Your PR title ...'.
5. Be sure to keep the PR description updated to reflect all changes.
6. Please write your PR title to summarize what this PR proposes.
7. If possible, provide a concise example to reproduce the issue for a faster review.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
`DataConnectorProviderFactory `uses HashMap to cache data connector instances, and there is no way to invalidate the cache unless you restart the MetaStore.
What is more serious is that if you drop or alter the dataconnector, the cache will not change, and you maybe use a invalid dataconnector next time.
I think we can improve the dataconnector cache from the two aspects:
1. Use Caffeine with a maxmumsize e.g. 100 to cache data connector instead of HashMap, and set a expire time after the last accessing. And we also should close the underlying datasource connection using Caffeine RemovalListener.
2. After executing Drop or Alter DDL on a dataConnector, we should update cache to clean the dataConnector to avoid using the invalid dataConnector next time.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
Existing Qtest and Local Hive cluster env.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] akshat0395 commented on a diff in pull request #4418: HIVE-27440: Improve data connector cache
Posted by "akshat0395 (via GitHub)" <gi...@apache.org>.
akshat0395 commented on code in PR #4418:
URL: https://github.com/apache/hive/pull/4418#discussion_r1229974610
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/DataConnectorProviderFactory.java:
##########
@@ -18,29 +18,52 @@
package org.apache.hadoop.hive.metastore.dataconnector;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.RemovalCause;
+import com.github.benmanes.caffeine.cache.RemovalListener;
+import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hive.metastore.IHMSHandler;
import org.apache.hadoop.hive.metastore.api.DataConnector;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.DatabaseType;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.*;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.DERBY_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.MSSQL_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.MYSQL_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.ORACLE_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.POSTGRES_TYPE;
public class DataConnectorProviderFactory {
- Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
+ static final Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
- private static Map<String, IDataConnectorProvider> cache = null;
+ private static Cache<String, IDataConnectorProvider> dataConnectorCache = null;
private static DataConnectorProviderFactory singleton = null;
private static IHMSHandler hmsHandler = null;
+ private static class CacheRemoveListener implements RemovalListener<String, IDataConnectorProvider> {
+ @Override
+ public void onRemoval(@Nullable String dcName, @Nullable IDataConnectorProvider dataConnectorProvider,
+ @NonNull RemovalCause cause) {
+ try {
+ dataConnectorProvider.close();
Review Comment:
Can we add a log here, saying `Closing dataConnectorProvider` this might help while going through stack track if it is ever closed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] zhangbutao commented on a diff in pull request #4418: HIVE-27440: Improve data connector cache
Posted by "zhangbutao (via GitHub)" <gi...@apache.org>.
zhangbutao commented on code in PR #4418:
URL: https://github.com/apache/hive/pull/4418#discussion_r1230494305
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/DataConnectorProviderFactory.java:
##########
@@ -18,29 +18,52 @@
package org.apache.hadoop.hive.metastore.dataconnector;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.RemovalCause;
+import com.github.benmanes.caffeine.cache.RemovalListener;
+import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hive.metastore.IHMSHandler;
import org.apache.hadoop.hive.metastore.api.DataConnector;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.DatabaseType;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.*;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.DERBY_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.MSSQL_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.MYSQL_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.ORACLE_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.POSTGRES_TYPE;
public class DataConnectorProviderFactory {
- Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
+ static final Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
- private static Map<String, IDataConnectorProvider> cache = null;
+ private static Cache<String, IDataConnectorProvider> dataConnectorCache = null;
private static DataConnectorProviderFactory singleton = null;
private static IHMSHandler hmsHandler = null;
+ private static class CacheRemoveListener implements RemovalListener<String, IDataConnectorProvider> {
+ @Override
+ public void onRemoval(@Nullable String dcName, @Nullable IDataConnectorProvider dataConnectorProvider,
+ @NonNull RemovalCause cause) {
+ try {
+ dataConnectorProvider.close();
Review Comment:
Added a log.
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/DataConnectorProviderFactory.java:
##########
@@ -18,29 +18,52 @@
package org.apache.hadoop.hive.metastore.dataconnector;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.RemovalCause;
+import com.github.benmanes.caffeine.cache.RemovalListener;
+import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hive.metastore.IHMSHandler;
import org.apache.hadoop.hive.metastore.api.DataConnector;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.DatabaseType;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.*;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.DERBY_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.MSSQL_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.MYSQL_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.ORACLE_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.POSTGRES_TYPE;
public class DataConnectorProviderFactory {
- Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
+ static final Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
- private static Map<String, IDataConnectorProvider> cache = null;
+ private static Cache<String, IDataConnectorProvider> dataConnectorCache = null;
private static DataConnectorProviderFactory singleton = null;
private static IHMSHandler hmsHandler = null;
+ private static class CacheRemoveListener implements RemovalListener<String, IDataConnectorProvider> {
+ @Override
+ public void onRemoval(@Nullable String dcName, @Nullable IDataConnectorProvider dataConnectorProvider,
+ @NonNull RemovalCause cause) {
+ try {
+ dataConnectorProvider.close();
+ } catch (Exception e) {
+ LOG.warn("Exception when closing dataconnectorprovider: {} due to: {}" + dcName, e.getMessage());
+ }
+ }
+ }
+
private DataConnectorProviderFactory(IHMSHandler hmsHandler) {
- cache = new HashMap<String, IDataConnectorProvider>();
+ dataConnectorCache = Caffeine.newBuilder()
+ .removalListener(new CacheRemoveListener())
+ .maximumSize(100)
Review Comment:
I think it is not necessary to make this configurable. We usually don't restrict cache size, but to avoid the extrem case to influence metastore memory, I set the maximumsize to 100 and this is enough for data connector.
BTW, the cache expire is one hour, and after one hour, the cache will be updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] sonarcloud[bot] commented on pull request #4418: HIVE-27440: Improve data connector cache
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #4418:
URL: https://github.com/apache/hive/pull/4418#issuecomment-1591515107
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=4418)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=BUG) [1 Bug](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=4418&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=4418&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=4418&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=CODE_SMELL) [10 Code Smells](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=4418&metric=coverage&view=list) No Coverage information
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=4418&metric=duplicated_lines_density&view=list) No Duplication information
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] akshat0395 commented on a diff in pull request #4418: HIVE-27440: Improve data connector cache
Posted by "akshat0395 (via GitHub)" <gi...@apache.org>.
akshat0395 commented on code in PR #4418:
URL: https://github.com/apache/hive/pull/4418#discussion_r1229975590
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/DataConnectorProviderFactory.java:
##########
@@ -18,29 +18,52 @@
package org.apache.hadoop.hive.metastore.dataconnector;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.RemovalCause;
+import com.github.benmanes.caffeine.cache.RemovalListener;
+import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hive.metastore.IHMSHandler;
import org.apache.hadoop.hive.metastore.api.DataConnector;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.DatabaseType;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.*;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.DERBY_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.MSSQL_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.MYSQL_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.ORACLE_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.POSTGRES_TYPE;
public class DataConnectorProviderFactory {
- Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
+ static final Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
- private static Map<String, IDataConnectorProvider> cache = null;
+ private static Cache<String, IDataConnectorProvider> dataConnectorCache = null;
private static DataConnectorProviderFactory singleton = null;
private static IHMSHandler hmsHandler = null;
+ private static class CacheRemoveListener implements RemovalListener<String, IDataConnectorProvider> {
+ @Override
+ public void onRemoval(@Nullable String dcName, @Nullable IDataConnectorProvider dataConnectorProvider,
+ @NonNull RemovalCause cause) {
+ try {
+ dataConnectorProvider.close();
+ } catch (Exception e) {
+ LOG.warn("Exception when closing dataconnectorprovider: {} due to: {}" + dcName, e.getMessage());
+ }
+ }
+ }
+
private DataConnectorProviderFactory(IHMSHandler hmsHandler) {
- cache = new HashMap<String, IDataConnectorProvider>();
+ dataConnectorCache = Caffeine.newBuilder()
+ .removalListener(new CacheRemoveListener())
+ .maximumSize(100)
Review Comment:
Should we make this configurable? WDYT
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] saihemanth-cloudera merged pull request #4418: HIVE-27440: Improve data connector cache
Posted by "saihemanth-cloudera (via GitHub)" <gi...@apache.org>.
saihemanth-cloudera merged PR #4418:
URL: https://github.com/apache/hive/pull/4418
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] zhangbutao commented on pull request #4418: HIVE-27440: Improve data connector cache
Posted by "zhangbutao (via GitHub)" <gi...@apache.org>.
zhangbutao commented on PR #4418:
URL: https://github.com/apache/hive/pull/4418#issuecomment-1631949999
@saihemanth-cloudera Kindly ping. Can we merge this change? Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] zhangbutao commented on a diff in pull request #4418: HIVE-27440: Improve data connector cache
Posted by "zhangbutao (via GitHub)" <gi...@apache.org>.
zhangbutao commented on code in PR #4418:
URL: https://github.com/apache/hive/pull/4418#discussion_r1230494656
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/DataConnectorProviderFactory.java:
##########
@@ -89,19 +110,23 @@ public static synchronized IDataConnectorProvider getDataConnectorProvider(Datab
default:
throw new MetaException("Data connector of type " + connector.getType() + " not implemented yet");
}
- cache.put(connector.getName().toLowerCase(), provider);
+ dataConnectorCache.put(connector.getName().toLowerCase(), provider);
return provider;
}
- public void shutdown() {
- for (IDataConnectorProvider provider: cache.values()) {
- try {
- provider.close();
- } catch(Exception e) {
- LOG.warn("Exception invoking close on dataconnectorprovider:" + provider, e);
- } finally {
- cache.clear();
+ /**
+ * After executing Drop or Alter DDL on a dataConnector, we should update cache to clean the dataConnector
+ * to avoid using the invalid dataConnector next time.
+ * @param dcName dataConnector to be cleaned
+ */
+ public static synchronized void updateDataConnectorCache(String dcName) {
Review Comment:
Sure. Renamed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] akshat0395 commented on a diff in pull request #4418: HIVE-27440: Improve data connector cache
Posted by "akshat0395 (via GitHub)" <gi...@apache.org>.
akshat0395 commented on code in PR #4418:
URL: https://github.com/apache/hive/pull/4418#discussion_r1230550519
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/DataConnectorProviderFactory.java:
##########
@@ -18,29 +18,52 @@
package org.apache.hadoop.hive.metastore.dataconnector;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.RemovalCause;
+import com.github.benmanes.caffeine.cache.RemovalListener;
+import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hive.metastore.IHMSHandler;
import org.apache.hadoop.hive.metastore.api.DataConnector;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.DatabaseType;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.*;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.DERBY_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.MSSQL_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.MYSQL_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.ORACLE_TYPE;
+import static org.apache.hadoop.hive.metastore.dataconnector.IDataConnectorProvider.POSTGRES_TYPE;
public class DataConnectorProviderFactory {
- Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
+ static final Logger LOG = LoggerFactory.getLogger(DataConnectorProviderFactory.class);
- private static Map<String, IDataConnectorProvider> cache = null;
+ private static Cache<String, IDataConnectorProvider> dataConnectorCache = null;
private static DataConnectorProviderFactory singleton = null;
private static IHMSHandler hmsHandler = null;
+ private static class CacheRemoveListener implements RemovalListener<String, IDataConnectorProvider> {
+ @Override
+ public void onRemoval(@Nullable String dcName, @Nullable IDataConnectorProvider dataConnectorProvider,
+ @NonNull RemovalCause cause) {
+ try {
+ dataConnectorProvider.close();
+ } catch (Exception e) {
+ LOG.warn("Exception when closing dataconnectorprovider: {} due to: {}" + dcName, e.getMessage());
+ }
+ }
+ }
+
private DataConnectorProviderFactory(IHMSHandler hmsHandler) {
- cache = new HashMap<String, IDataConnectorProvider>();
+ dataConnectorCache = Caffeine.newBuilder()
+ .removalListener(new CacheRemoveListener())
+ .maximumSize(100)
Review Comment:
Makes sense, thanks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] akshat0395 commented on a diff in pull request #4418: HIVE-27440: Improve data connector cache
Posted by "akshat0395 (via GitHub)" <gi...@apache.org>.
akshat0395 commented on code in PR #4418:
URL: https://github.com/apache/hive/pull/4418#discussion_r1229981943
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/DataConnectorProviderFactory.java:
##########
@@ -89,19 +110,23 @@ public static synchronized IDataConnectorProvider getDataConnectorProvider(Datab
default:
throw new MetaException("Data connector of type " + connector.getType() + " not implemented yet");
}
- cache.put(connector.getName().toLowerCase(), provider);
+ dataConnectorCache.put(connector.getName().toLowerCase(), provider);
return provider;
}
- public void shutdown() {
- for (IDataConnectorProvider provider: cache.values()) {
- try {
- provider.close();
- } catch(Exception e) {
- LOG.warn("Exception invoking close on dataconnectorprovider:" + provider, e);
- } finally {
- cache.clear();
+ /**
+ * After executing Drop or Alter DDL on a dataConnector, we should update cache to clean the dataConnector
+ * to avoid using the invalid dataConnector next time.
+ * @param dcName dataConnector to be cleaned
+ */
+ public static synchronized void updateDataConnectorCache(String dcName) {
Review Comment:
As this method is serving specific case of case of invalidation of cache, can this be renamed to invaidateDataConnectorFromCache?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] zhangbutao commented on pull request #4418: HIVE-27440: Improve data connector cache
Posted by "zhangbutao (via GitHub)" <gi...@apache.org>.
zhangbutao commented on PR #4418:
URL: https://github.com/apache/hive/pull/4418#issuecomment-1600433423
> @zhangbutao I have not used caffiene in the past. So I am not sure how much overhead it is. Just thinking out loud and wondering if adding a cache for just the connectors is an overkill. I do agree that we do have to remove the connectors on alter/drop. We could have a sequence of create/access/drop/re-create and I am not sure if this works today.
>
@nrg4878 Thanks for sharing your thoughts. caffiene has been used in HIVE-23949, and i think it is more light-weight and stable than other cache.
Answer your thought `if adding a cache for just the connectors is an overkill`? I think the value of cache is that we can avoid create connection every time when using data connector. Caching a data connector with connection e.g. jdbc connection is usefull when users operate remote data source frequently.
https://github.com/apache/hive/blob/9a8c0f8b7ae7289d1e5eeddf35360806a9faa38a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/AbstractDataConnectorProvider.java#L38
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] akshat0395 commented on pull request #4418: HIVE-27440: Improve data connector cache
Posted by "akshat0395 (via GitHub)" <gi...@apache.org>.
akshat0395 commented on PR #4418:
URL: https://github.com/apache/hive/pull/4418#issuecomment-1592497182
Thanks for the patch @zhangbutao, LGTM +1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] sonarcloud[bot] commented on pull request #4418: HIVE-27440: Improve data connector cache
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #4418:
URL: https://github.com/apache/hive/pull/4418#issuecomment-1592805307
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=4418)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=BUG) [1 Bug](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=4418&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=4418&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=4418&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=CODE_SMELL) [10 Code Smells](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4418&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=4418&metric=coverage&view=list) No Coverage information
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=4418&metric=duplicated_lines_density&view=list) No Duplication information
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] zhangbutao commented on pull request #4418: HIVE-27440: Improve data connector cache
Posted by "zhangbutao (via GitHub)" <gi...@apache.org>.
zhangbutao commented on PR #4418:
URL: https://github.com/apache/hive/pull/4418#issuecomment-1597170910
@nrg4878 @dengzhhu653 @saihemanth-cloudera Would you like to take a look? Thanks in advance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] nrg4878 commented on pull request #4418: HIVE-27440: Improve data connector cache
Posted by "nrg4878 (via GitHub)" <gi...@apache.org>.
nrg4878 commented on PR #4418:
URL: https://github.com/apache/hive/pull/4418#issuecomment-1600132570
@zhangbutao I have not used caffiene in the past. So I am not sure how much overhead it is. Just thinking out loud and wondering if adding a cache for just the connectors is an overkill. I do agree that we do have to remove the connectors on alter/drop. We could have a sequence of create/access/drop/re-create and I am not sure if this works today.
@saihemanth-cloudera Thoughts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org