public void start(ControllerMetrics controllerMetrics) { _controllerMetrics = controllerMetrics; LOGGER.info("Starting realtime segments manager, adding a listener on the property store table configs path."); String zkUrl = _pinotHelixResourceManager.getHelixZkURL(); _zkClient = new ZkClient(zkUrl, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT); _zkClient.setZkSerializer(new ZNRecordSerializer()); _zkClient.waitUntilConnected(CommonConstants.Helix.ZkClient.DEFAULT_CONNECT_TIMEOUT_SEC, TimeUnit.SECONDS); // Subscribe to any data/child changes to property _zkClient.subscribeChildChanges(_tableConfigPath, this); _zkClient.subscribeDataChanges(_tableConfigPath, this); // Subscribe to leadership changes ControllerLeadershipManager.getInstance().subscribe(PinotLLCRealtimeSegmentManager.class.getName(), this); // Setup change listeners for already existing tables, if any. processPropertyStoreChange(_tableConfigPath); }
PinotHelixSegmentOnlineOfflineStateModelGenerator.generatePinotStateModelDefinition(); ZkClient zkClient = new ZkClient(zkPath); zkClient.waitUntilConnected(CommonConstants.Helix.ZkClient.DEFAULT_CONNECT_TIMEOUT_SEC, TimeUnit.SECONDS); zkClient.setZkSerializer(new ZNRecordSerializer()); HelixDataAccessor accessor =
zkClient.setZkSerializer(new ZNRecordStreamingSerializer()); LOGGER.info("Connecting to Zookeeper at: {}", _zkAddress); zkClient.waitUntilConnected(CommonConstants.Helix.ZkClient.DEFAULT_CONNECT_TIMEOUT_SEC, TimeUnit.SECONDS); ZkBaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<>(zkClient); ZKHelixDataAccessor zkHelixDataAccessor = new ZKHelixDataAccessor(_clusterName, baseDataAccessor);
@Override public boolean isConnected() { if (_zkclient == null || _zkclient.isClosed()) { return false; } // Don't check ZkConnection state, which is different from ZkClient's watcher state. // ZkConnection state is the internal state of the connection, which can be different from the // ZkClient state due to internal thread/retry logic. try { return _zkclient.waitUntilConnected(0, TimeUnit.MILLISECONDS); } catch (ZkInterruptedException ex) { return false; } }
public ZKHelixAdmin(String zkAddress) { int timeOutInSec = Integer.parseInt(System.getProperty(CONNECTION_TIMEOUT, "30")); _zkClient = new ZkClient(zkAddress, timeOutInSec * 1000); _zkClient.setZkSerializer(new ZNRecordSerializer()); _zkClient.waitUntilConnected(timeOutInSec, TimeUnit.SECONDS); _configAccessor = new ConfigAccessor(_zkClient); }
/** * Check if HelixManager is connected, if it is not connected, * wait for the specified timeout and check again before return. * * @param timeout */ void checkConnected(long timeout) { if (_zkclient == null || _zkclient.isClosed()) { throw new HelixException( "HelixManager (ZkClient) is not connected. Call HelixManager#connect()"); } boolean isConnected = isConnected(); if (!isConnected && timeout > 0) { LOG.warn( "zkClient to " + _zkAddress + " is not connected, wait for " + _waitForConnectedTimeout + "ms."); isConnected = _zkclient.waitUntilConnected(_waitForConnectedTimeout, TimeUnit.MILLISECONDS); } if (!isConnected) { LOG.error("zkClient is not connected after waiting " + timeout + "ms." + ", clusterName: " + _clusterName + ", zkAddress: " + _zkAddress); throw new HelixException( "HelixManager is not connected within retry timeout for cluster " + _clusterName); } }
/** * wait until we get a non-zero session-id. note that we might lose zkconnection * right after we read session-id. but it's ok to get stale session-id and we will have * another handle-new-session callback to correct this. */ void waitUntilConnected() { boolean isConnected; do { isConnected = _zkclient.waitUntilConnected(ZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); if (!isConnected) { LOG.error("fail to connect zkserver: " + _zkAddress + " in " + ZkClient.DEFAULT_CONNECTION_TIMEOUT + "ms. expiredSessionId: " + _sessionId + ", clusterName: " + _clusterName); continue; } ZkConnection zkConnection = ((ZkConnection) _zkclient.getConnection()); _sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId()); /** * at the time we read session-id, zkconnection might be lost again * wait until we get a non-zero session-id */ } while (!isConnected || "0".equals(_sessionId)); LOG.info("Handling new session, session id: " + _sessionId + ", instance: " + _instanceName + ", instanceTye: " + _instanceType + ", cluster: " + _clusterName + ", zkconnection: " + ((ZkConnection) _zkclient.getConnection()).getZookeeper()); }
@Override public void handleNewSession() throws Exception { // make sure zkclient is connected again zkClient.waitUntilConnected(HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.SECONDS); ZkConnection connection = ((ZkConnection) zkClient.getConnection()); ZooKeeper curZookeeper = connection.getZookeeper(); LOG.info("handleNewSession. sessionId: " + Long.toHexString(curZookeeper.getSessionId())); waitNewSession.countDown(); }
@Override public void handleNewSession() throws Exception { // make sure zkclient is connected again zkClient.waitUntilConnected(HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.SECONDS); ZkConnection connection = ((ZkConnection) zkClient.getConnection()); ZooKeeper curZookeeper = connection.getZookeeper(); LOG.info("handleNewSession. sessionId: " + Long.toHexString(curZookeeper.getSessionId())); }
public ZkCacheBaseDataAccessor(String zkAddress, ZkSerializer serializer, String chrootPath, List<String> wtCachePaths, List<String> zkCachePaths, String monitorType, String monitorkey) { ZkClient.Builder zkClientBuilder = new ZkClient.Builder(); zkClientBuilder.setZkServer(zkAddress).setSessionTimeout(ZkClient.DEFAULT_SESSION_TIMEOUT) .setConnectionTimeout(ZkClient.DEFAULT_CONNECTION_TIMEOUT).setZkSerializer(serializer) .setMonitorType(monitorType).setMonitorKey(monitorkey); _zkclient = zkClientBuilder.build(); _zkclient.waitUntilConnected(ZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); _baseAccessor = new ZkBaseDataAccessor<>(_zkclient); if (chrootPath == null || chrootPath.equals("/")) { _chrootPath = null; } else { PathUtils.validatePath(chrootPath); _chrootPath = chrootPath; } _wtCachePaths = wtCachePaths; _zkCachePaths = zkCachePaths; // TODO: need to make sure no overlap between wtCachePaths and zkCachePaths // TreeMap key is ordered by key string length, so more general (i.e. short) prefix // comes first _cacheMap = new TreeMap<>(new Comparator<String>() { @Override public int compare(String o1, String o2) { int len1 = o1.split("/").length; int len2 = o2.split("/").length; return len1 - len2; } }); start(); }
Assert.assertFalse(zkClient.waitUntilConnected(0, TimeUnit.MILLISECONDS)); Assert.assertTrue(zkClient.waitUntilConnected(5000, TimeUnit.MILLISECONDS)); Assert.assertTrue(TestHelper.verify(new TestHelper.Verifier() { @Override
while (retryCount < 3) { try { _zkclient.waitUntilConnected(_connectionInitTimeout, TimeUnit.MILLISECONDS); handleStateChanged(KeeperState.SyncConnected); handleNewSession();