@Override public CompletableFuture<Transaction.Status> checkTransactionStatus(final Stream stream, final UUID txId) { Exceptions.checkNotClosed(closed.get(), this); Preconditions.checkNotNull(stream, "stream"); Preconditions.checkNotNull(txId, "txId"); long traceId = LoggerHelpers.traceEnter(log, "checkTransactionStatus", stream, txId); final CompletableFuture<TxnState> result = this.retryConfig.runAsync(() -> { RPCAsyncCallback<TxnState> callback = new RPCAsyncCallback<>(traceId, "checkTransactionStatus"); client.checkTransactionState(TxnRequest.newBuilder() .setStreamInfo(ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())) .setTxnId(ModelHelper.decode(txId)) .build(), callback); return callback.getFuture(); }, this.executor); return result.thenApply(status -> ModelHelper.encode(status.getState(), stream + " " + txId)) .whenComplete((x, e) -> { if (e != null) { log.warn("checkTransactionStatus failed: ", e); } LoggerHelpers.traceLeave(log, "checkTransactionStatus", traceId); }); }
public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { return io.pravega.controller.stream.api.grpc.v1.Controller.TxnState.getDescriptor().getEnumTypes().get(0); }
break; default: { if (!parseUnknownFieldProto3( input, unknownFields, extensionRegistry, tag)) { done = true; } finally { this.unknownFields = unknownFields.build(); makeExtensionsImmutable();
@io.grpc.stub.annotations.RpcMethod( fullMethodName = SERVICE_NAME + '/' + "checkTransactionState", requestType = io.pravega.controller.stream.api.grpc.v1.Controller.TxnRequest.class, responseType = io.pravega.controller.stream.api.grpc.v1.Controller.TxnState.class, methodType = io.grpc.MethodDescriptor.MethodType.UNARY) public static io.grpc.MethodDescriptor<io.pravega.controller.stream.api.grpc.v1.Controller.TxnRequest, io.pravega.controller.stream.api.grpc.v1.Controller.TxnState> getCheckTransactionStateMethod() { io.grpc.MethodDescriptor<io.pravega.controller.stream.api.grpc.v1.Controller.TxnRequest, io.pravega.controller.stream.api.grpc.v1.Controller.TxnState> getCheckTransactionStateMethod; if ((getCheckTransactionStateMethod = ControllerServiceGrpc.getCheckTransactionStateMethod) == null) { synchronized (ControllerServiceGrpc.class) { if ((getCheckTransactionStateMethod = ControllerServiceGrpc.getCheckTransactionStateMethod) == null) { ControllerServiceGrpc.getCheckTransactionStateMethod = getCheckTransactionStateMethod = io.grpc.MethodDescriptor.<io.pravega.controller.stream.api.grpc.v1.Controller.TxnRequest, io.pravega.controller.stream.api.grpc.v1.Controller.TxnState>newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "io.pravega.controller.stream.api.grpc.v1.ControllerService", "checkTransactionState")) .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.pravega.controller.stream.api.grpc.v1.Controller.TxnRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.pravega.controller.stream.api.grpc.v1.Controller.TxnState.getDefaultInstance())) .setSchemaDescriptor(new ControllerServiceMethodDescriptorSupplier("checkTransactionState")) .build(); } } } return getCheckTransactionStateMethod; }
@Override public void checkTransactionState(TxnRequest request, StreamObserver<TxnState> responseObserver) { if (request.getStreamInfo().getStream().equals("stream1")) { responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.OPEN).build()); responseObserver.onCompleted(); } else if (request.getStreamInfo().getStream().equals("stream2")) { responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.UNKNOWN).build()); responseObserver.onCompleted(); } else if (request.getStreamInfo().getStream().equals("stream3")) { responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.COMMITTING).build()); responseObserver.onCompleted(); } else if (request.getStreamInfo().getStream().equals("stream4")) { responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.COMMITTED).build()); responseObserver.onCompleted(); } else if (request.getStreamInfo().getStream().equals("stream5")) { responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.ABORTING).build()); responseObserver.onCompleted(); } else if (request.getStreamInfo().getStream().equals("stream6")) { responseObserver.onNext(TxnState.newBuilder().setState(TxnState.State.ABORTED).build()); responseObserver.onCompleted(); } else { responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException()); } }
@Test(timeout = 10000) public void testControllerPingFailureDisconnected() throws InterruptedException { TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE) .thenApply(x -> ModelHelper.decode(x.getKey())) .join(); Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (0.75 * LEASE), TimeUnit.MILLISECONDS); Assert.assertNull(result); TxnState status = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, status.getState()); // Stop timeoutService, and then try pinging the transaction. timeoutService.stopAsync(); PingTxnStatus pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, LEASE).join(); Assert.assertEquals(PingTxnStatus.Status.DISCONNECTED, pingStatus.getStatus()); result = timeoutService.getTaskCompletionQueue().poll((long) (0.5 * LEASE), TimeUnit.MILLISECONDS); Assert.assertNull(result); // Check that the transaction status is still open, since timeoutService has been stopped. status = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, status.getState()); }
@Test(timeout = 10000) public void testControllerPingSuccess() throws InterruptedException { TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE) .thenApply(x -> ModelHelper.decode(x.getKey())) .join(); Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (0.75 * LEASE), TimeUnit.MILLISECONDS); Assert.assertNull(result); TxnState txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, txnState.getState()); PingTxnStatus pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, LEASE).join(); Assert.assertEquals(PingTxnStatus.Status.OK, pingStatus.getStatus()); result = timeoutService.getTaskCompletionQueue().poll((long) (0.5 * LEASE), TimeUnit.MILLISECONDS); Assert.assertNull(result); txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, txnState.getState()); result = timeoutService.getTaskCompletionQueue().poll((long) (0.8 * LEASE), TimeUnit.MILLISECONDS); Assert.assertNotNull(result); txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.ABORTING, txnState.getState()); }
public io.pravega.controller.stream.api.grpc.v1.Controller.TxnState getDefaultInstanceForType() { return io.pravega.controller.stream.api.grpc.v1.Controller.TxnState.getDefaultInstance(); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
@Test(timeout = 10000) public void testControllerTimeout() throws InterruptedException { long begin = System.currentTimeMillis(); TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE) .thenApply(x -> ModelHelper.decode(x.getKey())) .join(); Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (1.3 * LEASE), TimeUnit.MILLISECONDS); long end = System.currentTimeMillis(); Assert.assertNotNull(result); log.info("Delay until timeout = " + (end - begin)); Assert.assertTrue((end - begin) >= LEASE); TxnState txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.ABORTING, txnState.getState()); }
@Test(timeout = 10000) public void testControllerPingFailureMaxExecutionTimeExceeded() throws InterruptedException { int lease = 10; TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, lease) .thenApply(x -> ModelHelper.decode(x.getKey())) .join(); TxnState txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, txnState.getState()); PingTxnStatus pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, 1000 * lease).join(); Assert.assertEquals(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED, pingStatus.getStatus()); txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, txnState.getState()); }
public io.pravega.controller.stream.api.grpc.v1.Controller.TxnState buildPartial() { io.pravega.controller.stream.api.grpc.v1.Controller.TxnState result = new io.pravega.controller.stream.api.grpc.v1.Controller.TxnState(this); result.state_ = state_; onBuilt(); return result; }
@Override public CompletableFuture<Transaction.Status> checkTransactionStatus(Stream stream, UUID txnId) { return controller.checkTransactionStatus(stream.getScope(), stream.getStreamName(), ModelHelper.decode(txnId)) .thenApply(status -> ModelHelper.encode(status.getState(), stream + " " + txnId)); }
public io.pravega.controller.stream.api.grpc.v1.Controller.TxnState build() { io.pravega.controller.stream.api.grpc.v1.Controller.TxnState result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + STATE_FIELD_NUMBER; hash = (53 * hash) + state_; hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
public Builder mergeFrom(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState other) { if (other == io.pravega.controller.stream.api.grpc.v1.Controller.TxnState.getDefaultInstance()) return this; if (other.state_ != 0) { setStateValue(other.getStateValue()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@Test(timeout = 5000) public void testCloseUnknownTxn() { UUID txId = streamStore.generateTransactionId(SCOPE, STREAM, null, executor).join(); VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txId, LEASE, 10 * LEASE, null, executor).join(); TxnId txnId = convert(txData.getId()); Controller.TxnState state = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, state.getState()); Controller.TxnStatus.Status status = controllerService.abortTransaction(SCOPE, STREAM, txnId).join().getStatus(); Assert.assertEquals(Controller.TxnStatus.Status.SUCCESS, status); }
public CompletableFuture<TxnState> checkTransactionStatus(final String scope, final String stream, final TxnId txnId) { Exceptions.checkNotNullOrEmpty(scope, "scope"); Exceptions.checkNotNullOrEmpty(stream, "stream"); Preconditions.checkNotNull(txnId, "txnId"); return streamStore.transactionStatus(scope, stream, ModelHelper.encode(txnId), null, executor) .thenApplyAsync(res -> TxnState.newBuilder().setState(TxnState.State.valueOf(res.name())).build(), executor); }