Source:
<code>public void heartbeat() { <START> LOG.debug("start Active Syncer heartbeat"); <END> while (mSyncTasks.peek() != null && !mSyncTasks.peek().isDone()) { Future<?> ignored = mSyncTasks.poll(); } List<AlluxioURI> filterList = mSyncManager.getFilterList(mMountId); if (filterList == null || filterList.isEmpty()) { return; } try { UfsManager.UfsClient ufsclient = Objects.requireNonNull(mMountTable.getUfsClient(mMountId)); try (CloseableResource<UnderFileSystem> ufsResource = ufsclient.acquireUfsResource()) { UnderFileSystem ufs = ufsResource.get(); if (ufs.supportsActiveSync()) { SyncInfo syncInfo = ufs.getActiveSyncInfo(); Set<AlluxioURI> ufsSyncPoints = syncInfo.getSyncPoints(); List<CompletableFuture<Long>> tasksPerSync = new ArrayList<>(); for (AlluxioURI ufsUri : ufsSyncPoints) { tasksPerSync.add(CompletableFuture.supplyAsync(() -> { processSyncPoint(ufsUri, syncInfo); return syncInfo.getTxId(); }, mSyncManager.getExecutor())); } CompletableFuture<Void> syncTask = CompletableFuture.allOf(tasksPerSync.toArray(new CompletableFuture<?>[0])) .thenRunAsync(() -> mFileSystemMaster .recordActiveSyncTxid(syncInfo.getTxId(), mMountId), mSyncManager.getExecutor()); while (!mSyncTasks.offer(syncTask)) { try { CompletableFuture<?> task = mSyncTasks.poll(); if (task == null) { syncTask.cancel(true); throw new IllegalStateException("Failed to add sync task to queue, but queue head " + "returned null"); } else { task.get(); } } catch (InterruptedException | ExecutionException e) { LogUtils.warnWithException(LOG, "Failed while waiting on task to add new task to " + "head of queue", e); if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } } } } } } catch (IOException e) { LOG.warn("IOException " + Throwables.getStackTraceAsString(e)); } }</code><technical_language>NIT: add mount id, mount path in this message</technical_language>

Target:
public void heartbeat() { LOG.debug("start sync heartbeat for with mount id {}", mMountUri, mMountId); mSyncTasks.removeIf(Future::isDone); List<AlluxioURI> filterList = mSyncManager.getFilterList(mMountId); if (filterList == null || filterList.isEmpty()) { return; } try { UfsManager.UfsClient ufsclient = Objects.requireNonNull(mMountTable.getUfsClient(mMountId)); try (CloseableResource<UnderFileSystem> ufsResource = ufsclient.acquireUfsResource()) { UnderFileSystem ufs = ufsResource.get(); if (!ufs.supportsActiveSync()) { return; } SyncInfo syncInfo = ufs.getActiveSyncInfo(); Set<AlluxioURI> ufsSyncPoints = syncInfo.getSyncPoints(); List<CompletableFuture<Long>> tasksPerSync = new ArrayList<>(); for (AlluxioURI ufsUri : ufsSyncPoints) { tasksPerSync.add(CompletableFuture.supplyAsync(() -> { processSyncPoint(ufsUri, syncInfo); return syncInfo.getTxId(); }, mSyncManager.getExecutor())); } CompletableFuture<Void> syncTask = CompletableFuture.allOf(tasksPerSync.toArray(new CompletableFuture<?>[0])) .thenRunAsync(() -> mFileSystemMaster .recordActiveSyncTxid(syncInfo.getTxId(), mMountId), mSyncManager.getExecutor()); int attempts = 0; while (!mSyncTasks.offer(syncTask)) { if (Thread.currentThread().isInterrupted()) { break; } for (CompletableFuture<?> f : mSyncTasks) { try { long waitTime = ServerConfiguration.getMs(PropertyKey.MASTER_UFS_ACTIVE_SYNC_INTERVAL) / mSyncTasks.size(); f.get(waitTime, TimeUnit.MILLISECONDS); mSyncTasks.remove(f); break; } catch (TimeoutException e) { LOG.trace("sync task did not complete during heartbeat. Attempt: {}", attempts); } catch (InterruptedException | ExecutionException e) { LogUtils.warnWithException(LOG, "Failed while waiting on task to add new task to " + "head of queue", e); if (Thread.currentThread().isInterrupted()) { Thread.currentThread().interrupt(); } } attempts++; } } } } catch (IOException e) { LOG.warn("IOException " + Throwables.getStackTraceAsString(e)); } }