private void setupHeartBeatThread() { // start heartbeat thread ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("HiveStreamingConnection-Heartbeat-Thread") .build(); this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(threadFactory); long heartBeatInterval; long initialDelay; try { // if HIVE_TXN_TIMEOUT is defined, heartbeat interval will be HIVE_TXN_TIMEOUT/2 heartBeatInterval = DbTxnManager.getHeartbeatInterval(conn.getConf()); } catch (LockException e) { heartBeatInterval = DEFAULT_HEARTBEAT_INTERVAL; } // to introduce some randomness and to avoid hammering the metastore at the same time (same logic as DbTxnManager) initialDelay = (long) (heartBeatInterval * 0.75 * Math.random()); LOG.info("Starting heartbeat thread with interval: {} ms initialDelay: {} ms for agentInfo: {}", heartBeatInterval, initialDelay, conn.getAgentInfo()); Runnable runnable = new HeartbeatRunnable(conn, minTxnId, maxTxnId, transactionLock, isTxnClosed); this.scheduledExecutorService.scheduleWithFixedDelay(runnable, initialDelay, heartBeatInterval, TimeUnit .MILLISECONDS); }
/** * Start the heartbeater threadpool and return the task. * @param initialDelay time to delay before first execution, in milliseconds * @return heartbeater */ private Heartbeater startHeartbeat(long initialDelay) throws LockException { long heartbeatInterval = getHeartbeatInterval(conf); assert heartbeatInterval > 0; UserGroupInformation currentUser; try { currentUser = UserGroupInformation.getCurrentUser(); } catch (IOException e) { throw new LockException("error while getting current user,", e); } Heartbeater heartbeater = new Heartbeater(this, conf, queryId, currentUser); heartbeatTask = startHeartbeat(initialDelay, heartbeatInterval, heartbeater); LOG.debug("Started heartbeat with delay/interval = " + initialDelay + "/" + heartbeatInterval + " " + TimeUnit.MILLISECONDS + " for query: " + queryId); return heartbeater; }
/** * Start the heartbeater threadpool and return the task. * @param initialDelay time to delay before first execution, in milliseconds * @return heartbeater */ private Heartbeater startHeartbeat(long initialDelay) throws LockException { long heartbeatInterval = getHeartbeatInterval(conf); assert heartbeatInterval > 0; Heartbeater heartbeater = new Heartbeater(this, conf, queryId); // For negative testing purpose.. if(conf.getBoolVar(HiveConf.ConfVars.HIVE_IN_TEST) && conf.getBoolVar(HiveConf.ConfVars.HIVETESTMODEFAILHEARTBEATER)) { initialDelay = 0; } else if (initialDelay == 0) { initialDelay = heartbeatInterval; } heartbeatTask = heartbeatExecutorService.scheduleAtFixedRate( heartbeater, initialDelay, heartbeatInterval, TimeUnit.MILLISECONDS); LOG.info("Started heartbeat with delay/interval = " + initialDelay + "/" + heartbeatInterval + " " + TimeUnit.MILLISECONDS + " for query: " + queryId); return heartbeater; }
@Override public LockResponse acquireMaterializationRebuildLock(String dbName, String tableName, long txnId) throws LockException { // Acquire lock LockResponse lockResponse; try { lockResponse = getMS().lockMaterializationRebuild(dbName, tableName, txnId); } catch (TException e) { throw new LockException(ErrorMsg.METASTORE_COMMUNICATION_FAILED.getMsg(), e); } if (lockResponse.getState() == LockState.ACQUIRED) { // If lock response is ACQUIRED, we can create the heartbeater long initialDelay = 0L; long heartbeatInterval = getHeartbeatInterval(conf); assert heartbeatInterval > 0; MaterializationRebuildLockHeartbeater heartbeater = new MaterializationRebuildLockHeartbeater( this, dbName, tableName, queryId, txnId); ScheduledFuture<?> task = startHeartbeat(initialDelay, heartbeatInterval, heartbeater); heartbeater.task.set(task); LOG.debug("Started heartbeat for materialization rebuild lock for {} with delay/interval = {}/{} {} for query: {}", AcidUtils.getFullTableName(dbName, tableName), initialDelay, heartbeatInterval, TimeUnit.MILLISECONDS, queryId); } return lockResponse; }
private void setupHeartBeatThread() { // start heartbeat thread ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("HiveStreamingConnection-Heartbeat-Thread") .build(); this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(threadFactory); long heartBeatInterval; long initialDelay; try { // if HIVE_TXN_TIMEOUT is defined, heartbeat interval will be HIVE_TXN_TIMEOUT/2 heartBeatInterval = DbTxnManager.getHeartbeatInterval(conn.conf); } catch (LockException e) { heartBeatInterval = DEFAULT_HEARTBEAT_INTERVAL; } // to introduce some randomness and to avoid hammering the metastore at the same time (same logic as DbTxnManager) initialDelay = (long) (heartBeatInterval * 0.75 * Math.random()); LOG.info("Starting heartbeat thread with interval: {} ms initialDelay: {} ms for agentInfo: {}", heartBeatInterval, initialDelay, conn.agentInfo); Runnable runnable = new HeartbeatRunnable(conn, minTxnId, maxTxnId, transactionLock, isTxnClosed); this.scheduledExecutorService.scheduleWithFixedDelay(runnable, initialDelay, heartBeatInterval, TimeUnit .MILLISECONDS); }