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);
}
}
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));
}
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);
}
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());
});
}
}
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);
}
Aggregations