Search in sources :

Example 1 with KeepAliveRequest

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);
}
Also used : KeepAliveResponse(com.netflix.titus.grpc.protogen.KeepAliveResponse) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) KeepAliveRequest(com.netflix.titus.grpc.protogen.KeepAliveRequest) ObserveJobsWithKeepAliveRequest(com.netflix.titus.grpc.protogen.ObserveJobsWithKeepAliveRequest) Test(org.junit.Test)

Example 2 with 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);
    }
}
Also used : JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) KeepAliveRequest(com.netflix.titus.grpc.protogen.KeepAliveRequest) ObserveJobsWithKeepAliveRequest(com.netflix.titus.grpc.protogen.ObserveJobsWithKeepAliveRequest)

Example 3 with KeepAliveRequest

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;
}
Also used : ObserveJobsWithKeepAliveRequest(com.netflix.titus.grpc.protogen.ObserveJobsWithKeepAliveRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) KeepAliveRequest(com.netflix.titus.grpc.protogen.KeepAliveRequest) ObserveJobsWithKeepAliveRequest(com.netflix.titus.grpc.protogen.ObserveJobsWithKeepAliveRequest)

Aggregations

KeepAliveRequest (com.netflix.titus.grpc.protogen.KeepAliveRequest)3 ObserveJobsWithKeepAliveRequest (com.netflix.titus.grpc.protogen.ObserveJobsWithKeepAliveRequest)3 JobChangeNotification (com.netflix.titus.grpc.protogen.JobChangeNotification)2 KeepAliveResponse (com.netflix.titus.grpc.protogen.KeepAliveResponse)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1