Search in sources :

Example 6 with PingTxnStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testPingSuccess.

@Test(timeout = 10000)
public void testPingSuccess() throws InterruptedException {
    UUID txnId = UUID.randomUUID();
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txnId, LEASE, 10 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime(), txData.getScaleGracePeriod());
    Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (0.75 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNull(result);
    TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
    PingTxnStatus pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE);
    Assert.assertEquals(PingTxnStatus.Status.OK, pingStatus.getStatus());
    result = timeoutService.getTaskCompletionQueue().poll((long) (0.5 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNull(result);
    status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
    result = timeoutService.getTaskCompletionQueue().poll((long) (0.8 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNotNull(result);
    status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.ABORTING, status);
}
Also used : PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) UUID(java.util.UUID) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Example 7 with PingTxnStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testPingOwnershipTransfer.

@Test(timeout = 30000)
public void testPingOwnershipTransfer() throws Exception {
    StreamMetadataStore streamStore2 = StreamStoreFactory.createZKStore(client, executor);
    HostControllerStore hostStore = HostStoreFactory.createInMemoryStore(HostMonitorConfigImpl.dummyConfig());
    TaskMetadataStore taskMetadataStore = TaskStoreFactory.createStore(storeClient, executor);
    ConnectionFactoryImpl connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup StreamMetadataTasks streamMetadataTasks2 = new StreamMetadataTasks(streamStore2, hostStore, taskMetadataStore, new SegmentHelper(), executor, "2", connectionFactory, false, "");
    @Cleanup StreamTransactionMetadataTasks streamTransactionMetadataTasks2 = new StreamTransactionMetadataTasks(streamStore2, hostStore, SegmentHelperMock.getSegmentHelperMock(), executor, "2", TimeoutServiceConfig.defaultConfig(), new LinkedBlockingQueue<>(5), connectionFactory, false, "");
    streamTransactionMetadataTasks2.initializeStreamWriters("commitStream", new EventStreamWriterMock<>(), "abortStream", new EventStreamWriterMock<>());
    // Create TimeoutService
    TimerWheelTimeoutService timeoutService2 = (TimerWheelTimeoutService) streamTransactionMetadataTasks2.getTimeoutService();
    ControllerService controllerService2 = new ControllerService(streamStore2, hostStore, streamMetadataTasks2, streamTransactionMetadataTasks2, new SegmentHelper(), executor, null);
    TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE, SCALE_GRACE_PERIOD).thenApply(x -> ModelHelper.decode(x.getKey())).join();
    VersionedTransactionData txnData = streamStore.getTransactionData(SCOPE, STREAM, ModelHelper.encode(txnId), null, executor).join();
    Assert.assertEquals(txnData.getVersion(), 0);
    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());
    // increasing lease -> total effective lease = 3 * LEASE
    PingTxnStatus pingStatus = controllerService2.pingTransaction(SCOPE, STREAM, txnId, 2 * LEASE).join();
    Assert.assertEquals(PingTxnStatus.Status.OK, pingStatus.getStatus());
    txnData = streamStore.getTransactionData(SCOPE, STREAM, ModelHelper.encode(txnId), null, executor).join();
    Assert.assertEquals(txnData.getVersion(), 1);
    // timeoutService1 should believe that LEASE has expired and should get non empty completion tasks
    result = timeoutService.getTaskCompletionQueue().poll((long) (1.3 * LEASE + RETRY_DELAY), TimeUnit.MILLISECONDS);
    Assert.assertNotNull(result);
    // the txn may have been attempted to be aborted by timeoutService1 but would have failed. So txn to remain open
    txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join();
    Assert.assertEquals(TxnState.State.OPEN, txnState.getState());
    // timeoutService2 should continue to wait on lease expiry and should get empty completion tasks
    result = timeoutService2.getTaskCompletionQueue().poll(0L, TimeUnit.MILLISECONDS);
    Assert.assertNull(result);
    result = timeoutService2.getTaskCompletionQueue().poll(2 * LEASE + RETRY_DELAY, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(result);
    // now txn should have moved to aborting because timeoutservice2 has initiated abort
    txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join();
    Assert.assertEquals(TxnState.State.ABORTING, txnState.getState());
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) SegmentHelper(io.pravega.controller.server.SegmentHelper) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StoreClient(io.pravega.controller.store.client.StoreClient) RetryOneTime(org.apache.curator.retry.RetryOneTime) StoreException(io.pravega.controller.store.stream.StoreException) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingServer(org.apache.curator.test.TestingServer) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) ModelHelper(io.pravega.client.stream.impl.ModelHelper) ControllerService(io.pravega.controller.server.ControllerService) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) StoreClientFactory(io.pravega.controller.store.client.StoreClientFactory) Test(org.junit.Test) UUID(java.util.UUID) State(io.pravega.controller.store.stream.tables.State) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) TimeUnit(java.util.concurrent.TimeUnit) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) Slf4j(lombok.extern.slf4j.Slf4j) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) CuratorFramework(org.apache.curator.framework.CuratorFramework) Config(io.pravega.controller.util.Config) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) TxnStatus(io.pravega.controller.store.stream.TxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Optional(java.util.Optional) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Assert(org.junit.Assert) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) ClientConfig(io.pravega.client.ClientConfig) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) SegmentHelper(io.pravega.controller.server.SegmentHelper) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) Cleanup(lombok.Cleanup) ControllerService(io.pravega.controller.server.ControllerService) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) Test(org.junit.Test)

Example 8 with PingTxnStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testControllerPingSuccess.

@Test(timeout = 10000)
public void testControllerPingSuccess() throws InterruptedException {
    TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE, SCALE_GRACE_PERIOD).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());
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) SegmentHelper(io.pravega.controller.server.SegmentHelper) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StoreClient(io.pravega.controller.store.client.StoreClient) RetryOneTime(org.apache.curator.retry.RetryOneTime) StoreException(io.pravega.controller.store.stream.StoreException) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingServer(org.apache.curator.test.TestingServer) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) ModelHelper(io.pravega.client.stream.impl.ModelHelper) ControllerService(io.pravega.controller.server.ControllerService) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) StoreClientFactory(io.pravega.controller.store.client.StoreClientFactory) Test(org.junit.Test) UUID(java.util.UUID) State(io.pravega.controller.store.stream.tables.State) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) TimeUnit(java.util.concurrent.TimeUnit) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) Slf4j(lombok.extern.slf4j.Slf4j) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) CuratorFramework(org.apache.curator.framework.CuratorFramework) Config(io.pravega.controller.util.Config) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) TxnStatus(io.pravega.controller.store.stream.TxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Optional(java.util.Optional) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Assert(org.junit.Assert) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) ClientConfig(io.pravega.client.ClientConfig) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) Test(org.junit.Test)

Example 9 with PingTxnStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testControllerPingFailureDisconnected.

@Test(timeout = 10000)
public void testControllerPingFailureDisconnected() throws InterruptedException {
    TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE, SCALE_GRACE_PERIOD).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());
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) StreamStoreFactory(io.pravega.controller.store.stream.StreamStoreFactory) SegmentHelper(io.pravega.controller.server.SegmentHelper) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StoreClient(io.pravega.controller.store.client.StoreClient) RetryOneTime(org.apache.curator.retry.RetryOneTime) StoreException(io.pravega.controller.store.stream.StoreException) TaskMetadataStore(io.pravega.controller.store.task.TaskMetadataStore) TestingServerStarter(io.pravega.test.common.TestingServerStarter) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TestingServer(org.apache.curator.test.TestingServer) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) ModelHelper(io.pravega.client.stream.impl.ModelHelper) ControllerService(io.pravega.controller.server.ControllerService) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) StoreClientFactory(io.pravega.controller.store.client.StoreClientFactory) Test(org.junit.Test) UUID(java.util.UUID) State(io.pravega.controller.store.stream.tables.State) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) TimeUnit(java.util.concurrent.TimeUnit) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) Slf4j(lombok.extern.slf4j.Slf4j) TaskStoreFactory(io.pravega.controller.store.task.TaskStoreFactory) CuratorFramework(org.apache.curator.framework.CuratorFramework) Config(io.pravega.controller.util.Config) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) TxnStatus(io.pravega.controller.store.stream.TxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) Optional(java.util.Optional) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Assert(org.junit.Assert) EventStreamWriterMock(io.pravega.controller.mocks.EventStreamWriterMock) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) ClientConfig(io.pravega.client.ClientConfig) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) Test(org.junit.Test)

Example 10 with PingTxnStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testPingFailureMaxExecutionTimeExceeded.

@Test(timeout = 10000)
public void testPingFailureMaxExecutionTimeExceeded() throws InterruptedException {
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, UUID.randomUUID(), LEASE, 2 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime(), txData.getScaleGracePeriod());
    TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
    // 3 * LEASE > 2 * LEASE
    PingTxnStatus pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), 3 * LEASE);
    Assert.assertEquals(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED, pingStatus.getStatus());
    status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
}
Also used : PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Aggregations

PingTxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)11 VersionedTransactionData (io.pravega.controller.store.stream.VersionedTransactionData)10 Test (org.junit.Test)10 TxnStatus (io.pravega.controller.store.stream.TxnStatus)9 UUID (java.util.UUID)8 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)7 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)6 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)6 EventStreamWriterMock (io.pravega.controller.mocks.EventStreamWriterMock)6 SegmentHelperMock (io.pravega.controller.mocks.SegmentHelperMock)6 ControllerService (io.pravega.controller.server.ControllerService)6 SegmentHelper (io.pravega.controller.server.SegmentHelper)6 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)6 HostStoreFactory (io.pravega.controller.store.host.HostStoreFactory)6 HostMonitorConfigImpl (io.pravega.controller.store.host.impl.HostMonitorConfigImpl)6 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)6 StreamStoreFactory (io.pravega.controller.store.stream.StreamStoreFactory)6 TaskMetadataStore (io.pravega.controller.store.task.TaskMetadataStore)6 TaskStoreFactory (io.pravega.controller.store.task.TaskStoreFactory)6 TxnState (io.pravega.controller.stream.api.grpc.v1.Controller.TxnState)6