deemoliu commented on code in PR #14686:
URL: https://github.com/apache/pinot/pull/14686#discussion_r1980098956


##########
pinot-server/src/main/java/org/apache/pinot/server/predownload/PredownloadZKClient.java:
##########
@@ -0,0 +1,187 @@
+/**
+ * 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.pinot.server.predownload;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixException;
+import org.apache.helix.PropertyPathBuilder;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.store.zk.AutoFallbackPropertyStore;
+import org.apache.helix.store.zk.ZkHelixPropertyStore;
+import org.apache.helix.zookeeper.api.client.HelixZkClient;
+import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+import org.apache.helix.zookeeper.datamodel.serializer.ZNRecordSerializer;
+import org.apache.helix.zookeeper.impl.factory.SharedZkClientFactory;
+import org.apache.pinot.common.metadata.ZKMetadataProvider;
+import org.apache.pinot.common.metadata.segment.SegmentZKMetadata;
+import org.apache.pinot.spi.config.instance.InstanceDataManagerConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class is to manage the ZK connection and operations. It will be used 
to fetch the segment
+ * metadata from ZK and prepare for the downloading.
+ */
+public class PredownloadZKClient implements AutoCloseable {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PredownloadZKClient.class);
+  private static final long ZK_CONNECTION_TIMEOUT_MS = 30000L;
+  private final String _clusterName;
+  private final String _instanceName;
+  private final String _zkAddress;
+
+  private RealmAwareZkClient _zkClient;
+
+  private boolean _running;
+
+  public PredownloadZKClient(String zkAddress, String clusterName, String 
instanceName) {
+    _clusterName = clusterName;
+    _instanceName = instanceName;
+    _zkAddress = zkAddress;
+    _running = false;
+  }
+
+  public void start() {
+    RealmAwareZkClient.RealmAwareZkClientConfig config = new 
RealmAwareZkClient.RealmAwareZkClientConfig();
+    config.setConnectInitTimeout(ZK_CONNECTION_TIMEOUT_MS);
+    config.setZkSerializer(new ZNRecordSerializer());
+    _zkClient = SharedZkClientFactory.getInstance()
+        .buildZkClient(new HelixZkClient.ZkConnectionConfig(_zkAddress), 
config.createHelixZkClientConfig());
+    _zkClient.waitUntilConnected(ZK_CONNECTION_TIMEOUT_MS, 
TimeUnit.MILLISECONDS);
+    _running = true;
+  }
+
+  @Override
+  public void close() {
+    if (_zkClient != null) {
+      _zkClient.close();
+      _running = false;
+    }
+  }
+
+  public boolean isStarted() {
+    return _running;
+  }
+
+  public HelixDataAccessor getDataAccessor() {
+    HelixDataAccessor accessor = new ZKHelixDataAccessor(_clusterName, new 
ZkBaseDataAccessor(_zkClient));

Review Comment:
   sounds good, 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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to