Source:
<code>public ListenableFuture<SegmentsAndMetadata> registerHandoff(SegmentsAndMetadata segmentsAndMetadata) throws InterruptedException { if (segmentsAndMetadata == null) { return Futures.immediateFuture(null); } else { final Object waitForHandoffMonitorStart = new Object(); final ListenableFuture<SegmentsAndMetadata> future = handoffExecutor.submit( () -> { final List<SegmentIdentifier> waitingSegmentIdList = segmentsAndMetadata.getSegments().stream() .map(SegmentIdentifier::fromDataSegment) .collect(Collectors.toList()); log.info("Awaiting handoff of segments: [%s]", waitingSegmentIdList); <START> synchronized (waitForHandoffMonitorStart) { <END> waitForHandoffMonitorStart.notify(); } synchronized (handoffMonitor) { while (waitingSegmentIdList.stream().anyMatch(appenderator::containsSegment)) { handoffMonitor.wait(); } } log.info("All segments handed off."); return new SegmentsAndMetadata( segmentsAndMetadata.getSegments(), ((FiniteAppenderatorDriverMetadata) segmentsAndMetadata.getCommitMetadata()).getCallerMetadata() ); } ); log.info("Waiting handoff monitor starts"); synchronized (waitForHandoffMonitorStart) { waitForHandoffMonitorStart.wait(handoffConditionTimeout); } for (final DataSegment dataSegment : segmentsAndMetadata.getSegments()) { handoffNotifier.registerSegmentHandoffCallback( new SegmentDescriptor( dataSegment.getInterval(), dataSegment.getVersion(), dataSegment.getShardSpec().getPartitionNum() ), MoreExecutors.sameThreadExecutor(), () -> { final SegmentIdentifier identifier = SegmentIdentifier.fromDataSegment(dataSegment); log.info("Segment[%s] successfully handed off, dropping.", identifier); metrics.incrementHandOffCount(); final ListenableFuture<?> dropFuture = appenderator.drop(identifier); Futures.addCallback( dropFuture, new FutureCallback<Object>() { @Override public void onSuccess(Object result) { synchronized (handoffMonitor) { handoffMonitor.notifyAll(); } } @Override public void onFailure(Throwable e) { log.warn(e, "Failed to drop segment[%s]?!", identifier); synchronized (handoffMonitor) { handoffMonitor.notifyAll(); } } } ); } ); } return future; } }</code><technical_language>purpose of notifying waiting below</technical_language>

Target:
public ListenableFuture<SegmentsAndMetadata> registerHandoff(SegmentsAndMetadata segmentsAndMetadata) { if (segmentsAndMetadata == null) { return Futures.immediateFuture(null); } else { final List<SegmentIdentifier> waitingSegmentIdList = segmentsAndMetadata.getSegments().stream() .map(SegmentIdentifier::fromDataSegment) .collect(Collectors.toList()); if (waitingSegmentIdList.isEmpty()) { return Futures.immediateFuture( new SegmentsAndMetadata( segmentsAndMetadata.getSegments(), ((FiniteAppenderatorDriverMetadata) segmentsAndMetadata.getCommitMetadata()) .getCallerMetadata() ) ); } log.info("Register handoff of segments: [%s]", waitingSegmentIdList); final SettableFuture<SegmentsAndMetadata> resultFuture = SettableFuture.create(); final AtomicInteger numRemainingHandoffSegments = new AtomicInteger(waitingSegmentIdList.size()); for (final SegmentIdentifier segmentIdentifier : waitingSegmentIdList) { handoffNotifier.registerSegmentHandoffCallback( new SegmentDescriptor( segmentIdentifier.getInterval(), segmentIdentifier.getVersion(), segmentIdentifier.getShardSpec().getPartitionNum() ), MoreExecutors.sameThreadExecutor(), () -> { log.info("Segment[%s] successfully handed off, dropping.", segmentIdentifier); metrics.incrementHandOffCount(); final ListenableFuture<?> dropFuture = appenderator.drop(segmentIdentifier); Futures.addCallback( dropFuture, new FutureCallback<Object>() { @Override public void onSuccess(Object result) { if (numRemainingHandoffSegments.decrementAndGet() == 0) { log.info("All segments handed off."); resultFuture.set( new SegmentsAndMetadata( segmentsAndMetadata.getSegments(), ((FiniteAppenderatorDriverMetadata) segmentsAndMetadata.getCommitMetadata()) .getCallerMetadata() ) ); } } @Override public void onFailure(Throwable e) { log.warn(e, "Failed to drop segment[%s]?!", segmentIdentifier); numRemainingHandoffSegments.decrementAndGet(); resultFuture.setException(e); } } ); } ); } return resultFuture; } }