tanishq-chugh commented on code in PR #6687: URL: https://github.com/apache/hive/pull/6687#discussion_r3862374880
########## service-session-store/src/main/java/org/apache/hive/service/cli/session/store/ZooKeeperSessionStateStore.java: ########## @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hive.service.cli.session.store; + +import java.util.concurrent.TimeUnit; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.ExponentialBackoffRetry; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.conf.HiveConf.ConfVars; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ZooKeeperSessionStateStore implements SessionStateStore { + + private static final Logger LOG = LoggerFactory.getLogger(ZooKeeperSessionStateStore.class); + + public static final String CONF_ZK_PATH = "hive.server2.session.state.store.zk.path"; + public static final String CONF_ZK_PATH_DEFAULT = "/hive_sessions"; + + private CuratorFramework zkClient; + private String zkBasePath; + private long ttlMillis; + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + @Override + public void init(HiveConf conf) { + String quorum = conf.getVar(ConfVars.HIVE_ZOOKEEPER_QUORUM); + int sessionTimeout = (int) conf.getTimeVar( + ConfVars.HIVE_ZOOKEEPER_SESSION_TIMEOUT, TimeUnit.MILLISECONDS); + int connectionTimeout = (int) conf.getTimeVar( + ConfVars.HIVE_ZOOKEEPER_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); + int baseSleepTime = (int) conf.getTimeVar( + ConfVars.HIVE_ZOOKEEPER_CONNECTION_BASESLEEPTIME, TimeUnit.MILLISECONDS); + int maxRetries = conf.getIntVar(ConfVars.HIVE_ZOOKEEPER_CONNECTION_MAX_RETRIES); + + this.zkBasePath = conf.get(CONF_ZK_PATH, CONF_ZK_PATH_DEFAULT); + this.ttlMillis = conf.getTimeVar( + ConfVars.HIVE_SERVER2_SESSION_STATE_STORE_TTL, TimeUnit.MILLISECONDS); + + zkClient = CuratorFrameworkFactory.builder() + .connectString(quorum) + .sessionTimeoutMs(sessionTimeout) + .connectionTimeoutMs(connectionTimeout) + .retryPolicy(new ExponentialBackoffRetry(baseSleepTime, maxRetries)) + .build(); + zkClient.start(); + + try { + if (zkClient.checkExists().forPath(zkBasePath) == null) { + zkClient.create().creatingParentsIfNeeded().forPath(zkBasePath); Review Comment: We should catch the NodeExists Exception here, as in case of multiple HS2 parallel fresh start-up, there can be a race condition causing latter HS2's start-up crash. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
