@Override public PingTxnStatus pingTxn(final String scope, final String stream, final UUID txnId, Version version, long lease) { if (!this.isRunning()) { return PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.DISCONNECTED).build(); } final String key = getKey(scope, stream, txnId); Preconditions.checkState(map.containsKey(key), "Stream not found in the map"); final TxnData txnData = map.get(key); if (txnData == null) { throw new IllegalStateException(String.format("Transaction %s not added to timerWheelTimeoutService", txnId)); } if (lease > maxLeaseValue) { return PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.LEASE_TOO_LARGE).build(); } if (lease + System.currentTimeMillis() > txnData.getMaxExecutionTimeExpiry()) { return PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED).build(); } else { Timeout timeout = txnData.getTimeout(); boolean cancelSucceeded = timeout.cancel(); if (cancelSucceeded) { TxnData newTxnData = txnData.updateLease(scope, stream, txnId, version, lease); map.replace(key, txnData, newTxnData); return PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.OK).build(); } else { // Cancellation may fail because timeout task (1) may be scheduled for execution, or (2) is executing. throw new IllegalStateException(String.format("Failed updating timeout for transaction %s", txnId)); } } }
public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; }
@Override public CompletableFuture<Void> pingTransaction(Stream stream, UUID txId, long lease) { Exceptions.checkNotClosed(closed.get(), this); long traceId = LoggerHelpers.traceEnter(log, "pingTransaction", stream, txId, lease); final CompletableFuture<PingTxnStatus> result = this.retryConfig.runAsync(() -> { RPCAsyncCallback<PingTxnStatus> callback = new RPCAsyncCallback<>(traceId, "pingTransaction"); client.pingTransaction(PingTxnRequest.newBuilder().setStreamInfo( ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())) .setTxnId(ModelHelper.decode(txId)) .setLease(lease).build(), callback); return callback.getFuture(); }, this.executor); return Futures.toVoidExpecting(result, PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.OK).build(), PingFailedException::new) .whenComplete((x, e) -> { if (e != null) { log.warn("pingTransaction failed: ", e); } LoggerHelpers.traceLeave(log, "pingTransaction", traceId); }); }
public static Builder newBuilder(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } public Builder toBuilder() {
@Override @Synchronized public CompletableFuture<PingTxnStatus> pingTxn(final String scope, final String stream, final UUID txId, final long lease, final OperationContext contextOpt) { final OperationContext context = contextOpt == null ? streamMetadataStore.createContext(scope, stream) : contextOpt; return streamMetadataStore.getTransactionData(scope, stream, txId, context, executor).thenComposeAsync(data -> streamMetadataStore.pingTransaction(scope, stream, data, lease, context, executor) .thenApply(txData -> { log.info("Pinged transaction {} with version {}", txId, txData.getVersion()); return PingTxnStatus.newBuilder().setStatus(Status.OK).build(); })); }
private Builder() { maybeForceBuilderInitialization(); }
@java.lang.Override protected Builder newBuilderForType( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**
public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) { return mergeFrom((io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)other); } else { super.mergeFrom(other); return this; } }
private Builder( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() {
public Builder mergeFrom(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus other) { if (other == io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus.getDefaultInstance()) return this; if (other.status_ != 0) { setStatusValue(other.getStatusValue()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@Override public CompletableFuture<Void> pingTransaction(Stream stream, UUID txId, long lease) { return Futures.toVoidExpecting( controller.pingTransaction(stream.getScope(), stream.getStreamName(), ModelHelper.decode(txId), lease), PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.OK).build(), PingFailedException::new); }
@Override public void pingTransaction(PingTxnRequest request, StreamObserver<PingTxnStatus> responseObserver) { if (request.getStreamInfo().getStream().equals("stream1")) { responseObserver.onNext(PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.OK).build()); responseObserver.onCompleted(); } else { responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException()); } }
public io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus build() { io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }