You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@livy.apache.org by GitBox <gi...@apache.org> on 2019/12/23 07:51:32 UTC

[GitHub] [incubator-livy] jerryshao commented on a change in pull request #267: [LIVY-732][SERVER] A common zookeeper wrapper utility

jerryshao commented on a change in pull request #267: [LIVY-732][SERVER] A common zookeeper wrapper utility
URL: https://github.com/apache/incubator-livy/pull/267#discussion_r360795968
 
 

 ##########
 File path: server/src/main/scala/org/apache/livy/server/recovery/ZooKeeperManager.scala
 ##########
 @@ -0,0 +1,137 @@
+/*
+ * 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.livy.server.recovery
+
+import scala.collection.JavaConverters._
+import scala.reflect.ClassTag
+
+import org.apache.curator.framework.api.UnhandledErrorListener
+import org.apache.curator.framework.CuratorFramework
+import org.apache.curator.framework.CuratorFrameworkFactory
+import org.apache.curator.retry.RetryNTimes
+import org.apache.zookeeper.KeeperException.NoNodeException
+
+import org.apache.livy.LivyConf
+import org.apache.livy.LivyConf.Entry
+import org.apache.livy.Logging
+
+object ZooKeeperManager {
+  val ZK_KEY_PREFIX_CONF = Entry("livy.server.recovery.zk-state-store.key-prefix", "livy")
+  val ZK_RETRY_CONF = Entry("livy.server.recovery.zk-state-store.retry-policy", "5,100")
+  val DUPLICATE_CREATE_EXCEPTION = "ZooKeeperManager single instance has already been created"
+
+  @volatile private var zkManager: ZooKeeperManager = _
+
+  def apply(livyConf: LivyConf,
+    mockCuratorClient: Option[CuratorFramework] = None):
+  ZooKeeperManager = synchronized {
+    if (zkManager == null) {
+      zkManager = new ZooKeeperManager(livyConf, mockCuratorClient)
+    } else {
+      throw new IllegalAccessException(DUPLICATE_CREATE_EXCEPTION)
+    }
+
+    zkManager
+  }
+
+  def get(): ZooKeeperManager = zkManager
+
+  // for test
+  private[recovery] def reset(): Unit = {
+    zkManager = null
 
 Review comment:
   I personally don't like singleton here, it is hard for testing, and that's why you need to add this method here. Why don't we change to a normal class object?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services