use of com.netflix.titus.grpc.protogen.KeepAliveRequest in project titus-control-plane by Netflix.
the class RemoteJobManagementClientWithKeepAliveTest method testKeepAlive.
@Test
public void testKeepAlive() throws InterruptedException {
Iterator<JobChangeNotification> it = newClientConnection();
KeepAliveRequest keepAliveRequest = waitForClientKeepAliveRequest();
responseObserver.onNext(JobChangeNotification.newBuilder().setKeepAliveResponse(KeepAliveResponse.newBuilder().setRequest(keepAliveRequest).build()).build());
KeepAliveResponse keepAliveResponse = expectJobChangeNotification(it, JobChangeNotification.NotificationCase.KEEPALIVERESPONSE).getKeepAliveResponse();
assertThat(keepAliveResponse.getRequest()).isEqualTo(keepAliveRequest);
}
use of com.netflix.titus.grpc.protogen.KeepAliveRequest in project titus-control-plane by Netflix.
the class ObserveJobsSubscription method drainInternal.
/**
* Based on: https://akarnokd.blogspot.com/2015/05/operator-concurrency-primitives_9.html
*/
private void drainInternal() {
if (wip.getAndIncrement() == 0) {
do {
if (checkTerminated(jobServiceCompleted, jobServiceEvents.isEmpty())) {
return;
}
wip.lazySet(1);
if (grpcStreamInitiated || tryInitialize()) {
while (true) {
boolean completed = jobServiceCompleted;
JobChangeNotification jobServiceEvent = jobServiceEvents.poll();
// with the client initiated keep alive.
if (jobServiceEvent != null && jobServiceEvent.getNotificationCase() == JobChangeNotification.NotificationCase.KEEPALIVERESPONSE) {
if (grpcSnapshotMarkerSent) {
this.lastCheckpointTimestampNano = jobServiceEvent.getKeepAliveResponse().getTimestamp();
}
} else {
if (checkTerminated(completed, jobServiceEvent == null)) {
return;
} else if (jobServiceEvent != null) {
if (jobServiceEvent.getNotificationCase() == JobChangeNotification.NotificationCase.SNAPSHOTEND) {
this.grpcSnapshotMarkerSent = true;
}
} else if (grpcSnapshotMarkerSent) {
// No more job service events to send. We can drain the GRPC input stream to process
// keep alive requests.
KeepAliveRequest keepAliveRequest = getLastKeepAliveEvent();
if (keepAliveRequest == null) {
break;
}
jobServiceEvent = toGrpcKeepAliveResponse(keepAliveRequest);
}
grpcResponseObserver.onNext(jobServiceEvent);
}
}
}
} while (wip.decrementAndGet() != 0);
}
}
use of com.netflix.titus.grpc.protogen.KeepAliveRequest in project titus-control-plane by Netflix.
the class ObserveJobsSubscription method getLastKeepAliveEvent.
private KeepAliveRequest getLastKeepAliveEvent() {
Pair<Long, ObserveJobsWithKeepAliveRequest> firstKeepAliveRequestPair = null;
KeepAliveRequest lastKeepAliveRequest = null;
int count = 0;
Pair<Long, ObserveJobsWithKeepAliveRequest> eventPair;
while ((eventPair = grpcClientEvents.peek()) != null) {
ObserveJobsWithKeepAliveRequest event = eventPair.getRight();
if (event.getKindCase() == ObserveJobsWithKeepAliveRequest.KindCase.KEEPALIVEREQUEST) {
long requestTimestampNano = eventPair.getLeft();
if (requestTimestampNano > lastCheckpointTimestampNano) {
break;
}
lastKeepAliveRequest = event.getKeepAliveRequest();
count++;
if (firstKeepAliveRequestPair == null) {
firstKeepAliveRequestPair = eventPair;
}
}
grpcClientEvents.poll();
}
if (lastKeepAliveRequest != null && logger.isDebugEnabled()) {
KeepAliveRequest firstKeepAliveRequest = firstKeepAliveRequestPair.getRight().getKeepAliveRequest();
long internalSyncDelayMs = (System.nanoTime() - firstKeepAliveRequestPair.getLeft()) / 1_000_000;
logger.debug("Acknowledging the keep alive request(s): count={}, requestId(first)={}, requestTimestamp={}, internalSyncDelayMs={}", count, firstKeepAliveRequest.getRequestId(), firstKeepAliveRequest.getTimestamp(), internalSyncDelayMs);
}
return lastKeepAliveRequest;
}
Aggregations