Java Code Examples for io.grpc.Status.Code#DEADLINE_EXCEEDED

The following examples show how to use io.grpc.Status.Code#DEADLINE_EXCEEDED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OtlpGrpcSpanExporterTest.java    From opentelemetry-java with Apache License 2.0 7 votes vote down vote up
@Override
public void export(
    ExportTraceServiceRequest request,
    io.grpc.stub.StreamObserver<ExportTraceServiceResponse> responseObserver) {
  receivedSpans.addAll(request.getResourceSpansList());
  responseObserver.onNext(ExportTraceServiceResponse.newBuilder().build());
  if (!returnedStatus.isOk()) {
    if (returnedStatus.getCode() == Code.DEADLINE_EXCEEDED) {
      // Do not call onCompleted to simulate a deadline exceeded.
      return;
    }
    responseObserver.onError(returnedStatus.asRuntimeException());
    return;
  }
  responseObserver.onCompleted();
}
 
Example 2
Source File: OtlpGrpcMetricExporterTest.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
@Override
public void export(
    ExportMetricsServiceRequest request,
    io.grpc.stub.StreamObserver<ExportMetricsServiceResponse> responseObserver) {
  receivedMetrics.addAll(request.getResourceMetricsList());
  responseObserver.onNext(ExportMetricsServiceResponse.newBuilder().build());
  if (!returnedStatus.isOk()) {
    if (returnedStatus.getCode() == Code.DEADLINE_EXCEEDED) {
      // Do not call onCompleted to simulate a deadline exceeded.
      return;
    }
    responseObserver.onError(returnedStatus.asRuntimeException());
    return;
  }
  responseObserver.onCompleted();
}
 
Example 3
Source File: ShardWorkerInstance.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public QueueEntry dispatchOperation(MatchListener listener)
    throws IOException, InterruptedException {
  while (!backplane.isStopped()) {
    listener.onWaitStart();
    try {

      List<Platform.Property> provisions = new ArrayList<>();
      QueueEntry queueEntry = backplane.dispatchOperation(provisions);
      if (queueEntry != null) {
        return queueEntry;
      }
    } catch (IOException e) {
      Status status = Status.fromThrowable(e);
      if (status.getCode() != Code.UNAVAILABLE && status.getCode() != Code.DEADLINE_EXCEEDED) {
        throw e;
      }
    }
    listener.onWaitEnd();
  }
  throw new IOException(Status.UNAVAILABLE.withDescription("backplane is stopped").asException());
}
 
Example 4
Source File: OkHttpClientTransport.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Override
public void rstStream(int streamId, ErrorCode errorCode) {
  logger.logRstStream(OkHttpFrameLogger.Direction.INBOUND, streamId, errorCode);
  Status status = toGrpcStatus(errorCode).augmentDescription("Rst Stream");
  boolean stopDelivery =
      (status.getCode() == Code.CANCELLED || status.getCode() == Code.DEADLINE_EXCEEDED);
  synchronized (lock) {
    OkHttpClientStream stream = streams.get(streamId);
    if (stream != null) {
      PerfMark.event("OkHttpClientTransport$ClientFrameHandler.rstStream",
          stream.transportState().tag());
      finishStream(
          streamId, status,
          errorCode == ErrorCode.REFUSED_STREAM ? RpcProgress.REFUSED : RpcProgress.PROCESSED,
          stopDelivery, null, null);
    }
  }
}
 
Example 5
Source File: CronetClientTransport.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
void finishStream(CronetClientStream stream, Status status) {
  synchronized (lock) {
    if (streams.remove(stream)) {
      boolean isCancelled = (status.getCode() == Code.CANCELLED
          || status.getCode() == Code.DEADLINE_EXCEEDED);
      stream.transportState().transportReportStatus(status, isCancelled, new Metadata());
    } else {
      return;
    }
  }
  stopIfNecessary();
}
 
Example 6
Source File: OkHttpClientTransport.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
public void rstStream(int streamId, ErrorCode errorCode) {
  Status status = toGrpcStatus(errorCode).augmentDescription("Rst Stream");
  boolean stopDelivery =
      (status.getCode() == Code.CANCELLED || status.getCode() == Code.DEADLINE_EXCEEDED);
  finishStream(
      streamId, status,
      errorCode == ErrorCode.REFUSED_STREAM ? RpcProgress.REFUSED : RpcProgress.PROCESSED,
      stopDelivery, null, null);
}
 
Example 7
Source File: RemoteInputStreamFactory.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private InputStream fetchBlobFromRemoteWorker(
    Digest blobDigest,
    Deque<String> workers,
    long offset,
    long deadlineAfter,
    TimeUnit deadlineAfterUnits,
    RequestMetadata requestMetadata)
    throws IOException, InterruptedException {
  String worker = workers.removeFirst();
  try {
    Instance instance = workerStub(worker);

    InputStream input =
        instance.newBlobInput(
            blobDigest, offset, deadlineAfter, deadlineAfterUnits, requestMetadata);
    // ensure that if the blob cannot be fetched, that we throw here
    input.available();
    if (Thread.interrupted()) {
      throw new InterruptedException();
    }
    return input;
  } catch (StatusRuntimeException e) {
    Status st = Status.fromThrowable(e);
    if (st.getCode() == Code.UNAVAILABLE || st.getCode() == Code.UNIMPLEMENTED) {
      // for now, leave this up to schedulers
      onUnavailable.accept(worker, e, "getBlob(" + DigestUtil.toString(blobDigest) + ")");
    } else if (st.getCode() == Code.NOT_FOUND) {
      // ignore this, the worker will update the backplane eventually
    } else if (st.getCode() != Code.DEADLINE_EXCEEDED && SHARD_IS_RETRIABLE.test(st)) {
      // why not, always
      workers.addLast(worker);
    } else if (st.getCode() == Code.CANCELLED) {
      throw new InterruptedException();
    } else {
      throw e;
    }
  }
  throw new NoSuchFileException(DigestUtil.toString(blobDigest));
}
 
Example 8
Source File: ByteStreamService.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
ServerCallStreamObserver<ReadResponse> onErrorLogReadObserver(
    String name, long offset, ServerCallStreamObserver<ReadResponse> delegate) {
  return new UniformDelegateServerCallStreamObserver<ReadResponse>(delegate) {
    long responseCount = 0;
    long responseBytes = 0;

    @Override
    public void onNext(ReadResponse response) {
      delegate.onNext(response);
      responseCount++;
      responseBytes += response.getData().size();
    }

    @Override
    public void onError(Throwable t) {
      Status status = Status.fromThrowable(t);
      if (status.getCode() != Code.NOT_FOUND) {
        java.util.logging.Level level = Level.SEVERE;
        if (responseCount > 0 && status.getCode() == Code.DEADLINE_EXCEEDED
            || status.getCode() == Code.CANCELLED) {
          level = Level.WARNING;
        }
        String message = format("error reading %s at offset %d", name, offset);
        if (responseCount > 0) {
          message +=
              format(" after %d responses and %d bytes of content", responseCount, responseBytes);
        }
        logger.log(level, message, t);
      }
      delegate.onError(t);
    }

    @Override
    public void onCompleted() {
      delegate.onCompleted();
    }
  };
}
 
Example 9
Source File: Worker.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private void removeWorker(String name) {
  try {
    backplane.removeWorker(name, "removing self prior to initialization");
  } catch (IOException e) {
    Status status = Status.fromThrowable(e);
    if (status.getCode() != Code.UNAVAILABLE && status.getCode() != Code.DEADLINE_EXCEEDED) {
      throw status.asRuntimeException();
    }
    logger.log(INFO, "backplane was unavailable or overloaded, deferring removeWorker");
  }
}
 
Example 10
Source File: Worker.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private void addBlobsLocation(List<Digest> digests, String name) {
  while (!backplane.isStopped()) {
    try {
      backplane.addBlobsLocation(digests, name);
      return;
    } catch (IOException e) {
      Status status = Status.fromThrowable(e);
      if (status.getCode() != Code.UNAVAILABLE && status.getCode() != Code.DEADLINE_EXCEEDED) {
        throw status.asRuntimeException();
      }
    }
  }
  throw Status.UNAVAILABLE.withDescription("backplane was stopped").asRuntimeException();
}
 
Example 11
Source File: Worker.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private void addWorker(ShardWorker worker) {
  while (!backplane.isStopped()) {
    try {
      backplane.addWorker(worker);
      return;
    } catch (IOException e) {
      Status status = Status.fromThrowable(e);
      if (status.getCode() != Code.UNAVAILABLE && status.getCode() != Code.DEADLINE_EXCEEDED) {
        throw status.asRuntimeException();
      }
    }
  }
  throw Status.UNAVAILABLE.withDescription("backplane was stopped").asRuntimeException();
}
 
Example 12
Source File: ShardWorkerInstance.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
@Override
public Operation getOperation(String name) {
  while (!backplane.isStopped()) {
    try {
      return backplane.getOperation(name);
    } catch (IOException e) {
      Status status = Status.fromThrowable(e);
      if (status.getCode() != Code.UNAVAILABLE && status.getCode() != Code.DEADLINE_EXCEEDED) {
        throw status.asRuntimeException();
      }
    }
  }
  throw Status.UNAVAILABLE.withDescription("backplane is stopped").asRuntimeException();
}
 
Example 13
Source File: CronetClientTransport.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
void finishStream(CronetClientStream stream, Status status) {
  synchronized (lock) {
    if (streams.remove(stream)) {
      boolean isCancelled = (status.getCode() == Code.CANCELLED
          || status.getCode() == Code.DEADLINE_EXCEEDED);
      stream.transportState().transportReportStatus(status, isCancelled, new Metadata());
    } else {
      return;
    }
  }
  stopIfNecessary();
}