Search in sources :

Example 1 with PravegaTablesStoreHelper

use of io.pravega.controller.store.PravegaTablesStoreHelper in project pravega by pravega.

the class ControllerEventProcessorPravegaTablesStreamTest method testTxnPartialCommitRetry.

@Test(timeout = 10000)
public void testTxnPartialCommitRetry() {
    PravegaTablesStoreHelper storeHelper = spy(new PravegaTablesStoreHelper(SegmentHelperMock.getSegmentHelperMockForTables(executor), GrpcAuthHelper.getDisabledAuthHelper(), executor));
    this.streamStore = new PravegaTablesStreamMetadataStore(PRAVEGA_ZK_CURATOR_RESOURCE.client, executor, Duration.ofHours(Config.COMPLETED_TRANSACTION_TTL_IN_HOURS), storeHelper);
    SegmentHelper segmentHelperMock = SegmentHelperMock.getSegmentHelperMock();
    EventHelper eventHelperMock = EventHelperMock.getEventHelperMock(executor, "1", ((AbstractStreamMetadataStore) this.streamStore).getHostTaskIndex());
    StreamMetadataTasks streamMetadataTasks = new StreamMetadataTasks(streamStore, this.bucketStore, TaskStoreFactory.createInMemoryStore(executor), segmentHelperMock, executor, "1", GrpcAuthHelper.getDisabledAuthHelper(), eventHelperMock);
    StreamTransactionMetadataTasks streamTransactionMetadataTasks = new StreamTransactionMetadataTasks(this.streamStore, segmentHelperMock, executor, "host", GrpcAuthHelper.getDisabledAuthHelper());
    streamTransactionMetadataTasks.initializeStreamWriters(new EventStreamWriterMock<>(), new EventStreamWriterMock<>());
    String scope = "scope";
    String stream = "stream";
    // region createStream
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scalingPolicy(policy1).build();
    streamStore.createScope(scope, null, executor).join();
    long start = System.currentTimeMillis();
    streamStore.createStream(scope, stream, configuration1, start, null, executor).join();
    streamStore.setState(scope, stream, State.ACTIVE, null, executor).join();
    StreamMetadataTasks spyStreamMetadataTasks = spy(streamMetadataTasks);
    List<VersionedTransactionData> txnDataList = createAndCommitTransactions(3);
    int epoch = txnDataList.get(0).getEpoch();
    spyStreamMetadataTasks.setRequestEventWriter(new EventStreamWriterMock<>());
    CommitRequestHandler commitEventProcessor = new CommitRequestHandler(streamStore, spyStreamMetadataTasks, streamTransactionMetadataTasks, bucketStore, executor);
    final String committingTxnsRecordKey = "committingTxns";
    long failingClientRequestId = 123L;
    doReturn(failingClientRequestId).when(spyStreamMetadataTasks).getRequestId(any());
    OperationContext context = this.streamStore.createStreamContext(scope, stream, failingClientRequestId);
    streamStore.startCommitTransactions(scope, stream, 100, context, executor).join();
    doReturn(Futures.failedFuture(new RuntimeException())).when(storeHelper).updateEntry(anyString(), eq(committingTxnsRecordKey), any(), ArgumentMatchers.<Function<String, byte[]>>any(), any(), eq(failingClientRequestId));
    AssertExtensions.assertFutureThrows("Updating CommittingTxnRecord fails", commitEventProcessor.processEvent(new CommitEvent(scope, stream, epoch)), e -> Exceptions.unwrap(e) instanceof RuntimeException);
    verify(storeHelper, times(1)).removeEntries(anyString(), any(), eq(failingClientRequestId));
    VersionedMetadata<CommittingTransactionsRecord> versionedCommitRecord = this.streamStore.getVersionedCommittingTransactionsRecord(scope, stream, context, executor).join();
    CommittingTransactionsRecord commitRecord = versionedCommitRecord.getObject();
    assertFalse(CommittingTransactionsRecord.EMPTY.equals(commitRecord));
    for (VersionedTransactionData txnData : txnDataList) {
        checkTransactionState(scope, stream, txnData.getId(), TxnStatus.COMMITTED);
    }
    long goodClientRequestId = 4567L;
    doReturn(goodClientRequestId).when(spyStreamMetadataTasks).getRequestId(any());
    commitEventProcessor.processEvent(new CommitEvent(scope, stream, epoch)).join();
    versionedCommitRecord = this.streamStore.getVersionedCommittingTransactionsRecord(scope, stream, context, executor).join();
    commitRecord = versionedCommitRecord.getObject();
    assertTrue(CommittingTransactionsRecord.EMPTY.equals(commitRecord));
    for (VersionedTransactionData txnData : txnDataList) {
        checkTransactionState(scope, stream, txnData.getId(), TxnStatus.COMMITTED);
    }
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) PravegaTablesStreamMetadataStore(io.pravega.controller.store.stream.PravegaTablesStreamMetadataStore) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SegmentHelper(io.pravega.controller.server.SegmentHelper) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) CommitRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.CommitRequestHandler) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) EventHelper(io.pravega.controller.task.EventHelper) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) CommitEvent(io.pravega.shared.controller.event.CommitEvent) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Test(org.junit.Test)

Example 2 with PravegaTablesStoreHelper

use of io.pravega.controller.store.PravegaTablesStoreHelper in project pravega by pravega.

the class PravegaTablesStreamMetadataStoreTest method testPartiallyCreatedScope.

@Test
public void testPartiallyCreatedScope() {
    PravegaTablesStreamMetadataStore store = (PravegaTablesStreamMetadataStore) this.store;
    PravegaTablesStoreHelper storeHelper = store.getStoreHelper();
    String newScope = "newScope";
    Controller.CreateScopeStatus status = store.createScope(newScope, null, executor).join();
    assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, status.getStatus());
    status = store.createScope(newScope, null, executor).join();
    assertEquals(Controller.CreateScopeStatus.Status.SCOPE_EXISTS, status.getStatus());
    // now partially create a scope
    String scopeName = "partial";
    byte[] idBytes = new byte[2 * Long.BYTES];
    UUID id = UUID.randomUUID();
    BitConverter.writeUUID(new ByteArraySegment(idBytes), id);
    // add entry for a scope in scopes table
    storeHelper.addNewEntry(PravegaTablesStreamMetadataStore.SCOPES_TABLE, scopeName, idBytes, x -> x, 0L).join();
    // verify that streams in scope table does not exist
    OperationContext context = store.createScopeContext(scopeName, 0L);
    PravegaTablesScope scope = (PravegaTablesScope) store.getScope(scopeName, context);
    ByteBuf token = Unpooled.wrappedBuffer(Base64.getDecoder().decode(""));
    Supplier<CompletableFuture<Map.Entry<ByteBuf, List<String>>>> tableCheckSupplier = () -> scope.getStreamsInScopeTableName(context).thenCompose(tableName -> storeHelper.getKeysPaginated(tableName, token, 10, 0L));
    AssertExtensions.assertFutureThrows("Table should not exist", tableCheckSupplier.get(), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
    Supplier<CompletableFuture<Map.Entry<ByteBuf, List<String>>>> kvttableCheckSupplier = () -> scope.getKVTablesInScopeTableName(context).thenCompose(tableName -> storeHelper.getKeysPaginated(tableName, token, 10, 0L));
    AssertExtensions.assertFutureThrows("Table should not exist", kvttableCheckSupplier.get(), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
    Supplier<CompletableFuture<?>> rgTableCheckSupplier = () -> scope.getReaderGroupsInScopeTableName(context).thenCompose(tableName -> storeHelper.getKeysPaginated(tableName, token, 10, 0L));
    AssertExtensions.assertFutureThrows("RG Table should not exist", rgTableCheckSupplier.get(), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
    assertEquals(Collections.emptyList(), scope.listStreamsInScope(context).join());
    Pair<List<String>, String> listStreams = scope.listStreams(10, "", executor, context).join();
    assertEquals(Collections.emptyList(), listStreams.getKey());
    assertTrue(Strings.isNullOrEmpty(listStreams.getValue()));
    Pair<List<String>, String> listKvts = scope.listKeyValueTables(10, "", executor, context).join();
    assertEquals(Collections.emptyList(), listKvts.getKey());
    assertTrue(Strings.isNullOrEmpty(listKvts.getValue()));
    scope.addStreamToScope("stream", context).join();
    assertEquals("stream", scope.listStreamsInScope(context).join().get(0));
    assertTrue(Futures.await(tableCheckSupplier.get()));
    UUID rgId = UUID.randomUUID();
    String rgName = "rg1";
    scope.addReaderGroupToScope(rgName, rgId, context).join();
    assertEquals(rgId, scope.getReaderGroupId(rgName, context).join());
    assertTrue(Futures.await(rgTableCheckSupplier.get()));
    scope.addKVTableToScope("kvt", UUID.randomUUID(), context).join();
    assertEquals("kvt", scope.listKeyValueTables(10, "", executor, context).join().getKey().get(0));
    assertTrue(Futures.await(kvttableCheckSupplier.get()));
    // create scope idempotent
    status = store.createScope(scopeName, null, executor).join();
    assertEquals(Controller.CreateScopeStatus.Status.SCOPE_EXISTS, status.getStatus());
    PravegaTablesStoreHelper spy = spy(storeHelper);
    PravegaTablesScope scopeObj = new PravegaTablesScope("thirdScope", spy);
    StoreException unknown = StoreException.create(StoreException.Type.UNKNOWN, "unknown");
    doReturn(Futures.failedFuture(unknown)).when(spy).addNewEntry(anyString(), anyString(), any(), any(), anyLong());
    AssertExtensions.assertFutureThrows("Create scope should have thrown exception", scopeObj.createScope(context), e -> Exceptions.unwrap(e).equals(unknown));
}
Also used : Arrays(java.util.Arrays) AssertExtensions(io.pravega.test.common.AssertExtensions) COMPLETED_TRANSACTIONS_BATCHES_TABLE(io.pravega.shared.NameUtils.COMPLETED_TRANSACTIONS_BATCHES_TABLE) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Unpooled(io.netty.buffer.Unpooled) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) Pair(org.apache.commons.lang3.tuple.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) Synchronized(lombok.Synchronized) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PravegaZkCuratorResource(io.pravega.controller.PravegaZkCuratorResource) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) Base64(java.util.Base64) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) ByteArraySegment(io.pravega.common.util.ByteArraySegment) RetryPolicy(org.apache.curator.RetryPolicy) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Mockito.any(org.mockito.Mockito.any) Futures(io.pravega.common.concurrent.Futures) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) Mockito.mock(org.mockito.Mockito.mock) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) SegmentHelper(io.pravega.controller.server.SegmentHelper) Exceptions(io.pravega.common.Exceptions) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) BitConverter(io.pravega.common.util.BitConverter) Supplier(java.util.function.Supplier) Strings(com.google.common.base.Strings) RetryOneTime(org.apache.curator.retry.RetryOneTime) ByteBuf(io.netty.buffer.ByteBuf) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SimpleEntry(java.util.AbstractMap.SimpleEntry) Mockito.anyString(org.mockito.Mockito.anyString) NameUtils(io.pravega.shared.NameUtils) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ByteArraySegment(io.pravega.common.util.ByteArraySegment) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) Mockito.anyString(org.mockito.Mockito.anyString) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ByteBuf(io.netty.buffer.ByteBuf) CompletableFuture(java.util.concurrent.CompletableFuture) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) List(java.util.List) UUID(java.util.UUID) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with PravegaTablesStoreHelper

use of io.pravega.controller.store.PravegaTablesStoreHelper in project pravega by pravega.

the class StreamTest method testPravegaTablesCreateStream.

@Test(timeout = 10000)
public void testPravegaTablesCreateStream() throws ExecutionException, InterruptedException {
    PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(SegmentHelperMock.getSegmentHelperMockForTables(executorService()), GrpcAuthHelper.getDisabledAuthHelper(), executorService());
    PravegaTablesScope scope = new PravegaTablesScope("test", storeHelper);
    OperationContext context = getContext();
    scope.createScope(context).join();
    scope.addStreamToScope("test", context).join();
    PravegaTablesStream stream = new PravegaTablesStream("test", "test", storeHelper, orderer, () -> 0, scope::getStreamsInScopeTableName, executorService());
    testStream(stream);
}
Also used : TestOperationContext(io.pravega.controller.store.TestOperationContext) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) Test(org.junit.Test)

Example 4 with PravegaTablesStoreHelper

use of io.pravega.controller.store.PravegaTablesStoreHelper in project pravega by pravega.

the class StreamTest method testConcurrentGetSuccessorScalePravegaTables.

@Test(timeout = 10000)
public void testConcurrentGetSuccessorScalePravegaTables() throws Exception {
    @Cleanup SegmentHelper segmentHelper = SegmentHelperMock.getSegmentHelperMockForTables(executorService());
    GrpcAuthHelper authHelper = GrpcAuthHelper.getDisabledAuthHelper();
    try (final StreamMetadataStore store = new PravegaTablesStreamMetadataStore(segmentHelper, PRAVEGA_ZK_CURATOR_RESOURCE.client, executorService(), authHelper)) {
        testConcurrentGetSuccessorScale(store, (x, y) -> {
            PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executorService());
            PravegaTablesScope scope = new PravegaTablesScope(x, storeHelper);
            OperationContext context = getContext();
            Futures.exceptionallyExpecting(scope.createScope(context), e -> Exceptions.unwrap(e) instanceof StoreException.DataExistsException, null).join();
            scope.addStreamToScope(y, context).join();
            return new PravegaTablesStream(x, y, storeHelper, orderer, () -> 0, scope::getStreamsInScopeTableName, executorService());
        });
    }
}
Also used : TestOperationContext(io.pravega.controller.store.TestOperationContext) Arrays(java.util.Arrays) SegmentHelper(io.pravega.controller.server.SegmentHelper) BiFunction(java.util.function.BiFunction) Exceptions(io.pravega.common.Exceptions) Cleanup(lombok.Cleanup) Mockito.spy(org.mockito.Mockito.spy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) RetryOneTime(org.apache.curator.retry.RetryOneTime) Lists(com.google.common.collect.Lists) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) StateRecord(io.pravega.controller.store.stream.records.StateRecord) Map(java.util.Map) After(org.junit.After) ClassRule(org.junit.ClassRule) Before(org.junit.Before) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) NameUtils(io.pravega.shared.NameUtils) SegmentHelperMock(io.pravega.controller.mocks.SegmentHelperMock) Assert.assertTrue(org.junit.Assert.assertTrue) PravegaZkCuratorResource(io.pravega.controller.PravegaZkCuratorResource) Test(org.junit.Test) Collectors(java.util.stream.Collectors) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) ExecutionException(java.util.concurrent.ExecutionException) ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) AbstractMap(java.util.AbstractMap) List(java.util.List) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) TestOperationContext(io.pravega.controller.store.TestOperationContext) RetryPolicy(org.apache.curator.RetryPolicy) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Futures(io.pravega.common.concurrent.Futures) Assert.assertEquals(org.junit.Assert.assertEquals) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) PravegaTablesScope(io.pravega.controller.store.PravegaTablesScope) SegmentHelper(io.pravega.controller.server.SegmentHelper) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 5 with PravegaTablesStoreHelper

use of io.pravega.controller.store.PravegaTablesStoreHelper in project pravega by pravega.

the class PravegaTablesStreamTest method setup.

@Override
public void setup() throws Exception {
    SegmentHelper segmentHelper = SegmentHelperMock.getSegmentHelperMockForTables(executor);
    GrpcAuthHelper authHelper = GrpcAuthHelper.getDisabledAuthHelper();
    storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executor);
    orderer = new ZkOrderedStore("txnOrderer", new ZKStoreHelper(PRAVEGA_ZK_CURATOR_RESOURCE.client, executor), executor);
    store = new PravegaTablesStreamMetadataStore(segmentHelper, PRAVEGA_ZK_CURATOR_RESOURCE.client, executor, Duration.ofSeconds(1), authHelper);
}
Also used : ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) SegmentHelper(io.pravega.controller.server.SegmentHelper)

Aggregations

PravegaTablesStoreHelper (io.pravega.controller.store.PravegaTablesStoreHelper)6 Test (org.junit.Test)5 SegmentHelper (io.pravega.controller.server.SegmentHelper)4 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)3 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)3 GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)3 PravegaTablesScope (io.pravega.controller.store.PravegaTablesScope)3 List (java.util.List)3 Exceptions (io.pravega.common.Exceptions)2 Futures (io.pravega.common.concurrent.Futures)2 PravegaZkCuratorResource (io.pravega.controller.PravegaZkCuratorResource)2 SegmentHelperMock (io.pravega.controller.mocks.SegmentHelperMock)2 TestOperationContext (io.pravega.controller.store.TestOperationContext)2 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)2 ZKStoreHelper (io.pravega.controller.store.ZKStoreHelper)2 OperationContext (io.pravega.controller.store.stream.OperationContext)2 CommittingTransactionsRecord (io.pravega.controller.store.stream.records.CommittingTransactionsRecord)2 EpochTransitionRecord (io.pravega.controller.store.stream.records.EpochTransitionRecord)2 StreamConfigurationRecord (io.pravega.controller.store.stream.records.StreamConfigurationRecord)2 NameUtils (io.pravega.shared.NameUtils)2