use of io.pravega.controller.store.kvtable.records.KVTSegmentRecord in project pravega by pravega.
the class AbstractKVTableBase method createHistoryRecords.
private CompletionStage<Void> createHistoryRecords(int startingSegmentNumber, CreateKVTableResponse createKvtResponse, OperationContext context) {
Preconditions.checkNotNull(context, "context cannot be null");
final int numSegments = createKvtResponse.getConfiguration().getPartitionCount();
// create epoch 0 record
final double keyRangeChunk = 1.0 / numSegments;
long creationTime = createKvtResponse.getTimestamp();
final ImmutableList.Builder<KVTSegmentRecord> builder = ImmutableList.builder();
IntStream.range(0, numSegments).boxed().forEach(x -> builder.add(newSegmentRecord(0, startingSegmentNumber + x, creationTime, x * keyRangeChunk, (x + 1) * keyRangeChunk)));
KVTEpochRecord epoch0 = new KVTEpochRecord(0, builder.build(), creationTime);
return createEpochRecord(epoch0, context).thenCompose(r -> createCurrentEpochRecordDataIfAbsent(epoch0, context));
}
use of io.pravega.controller.store.kvtable.records.KVTSegmentRecord in project pravega by pravega.
the class KVTableMetadataStoreTest method testKVTableMetadataStore.
@Test(timeout = 30000)
public void testKVTableMetadataStore() throws Exception {
Controller.CreateScopeStatus scopeCreateStatus = createScope(scope);
assertTrue(scopeCreateStatus.getStatus().equals(Controller.CreateScopeStatus.Status.SUCCESS) || scopeCreateStatus.getStatus().equals(Controller.CreateScopeStatus.Status.SCOPE_EXISTS));
UUID id = store.newScope(scope).newId();
store.createEntryForKVTable(scope, kvtable1, id, null, executor).get();
long start = System.currentTimeMillis();
store.createKeyValueTable(scope, kvtable1, configuration1, start, null, executor).get();
store.setState(scope, kvtable1, KVTableState.ACTIVE, null, executor).get();
id = store.newScope(scope).newId();
store.createEntryForKVTable(scope, kvtable2, id, null, executor).get();
store.createKeyValueTable(scope, kvtable2, configuration2, start, null, executor).get();
store.setState(scope, kvtable2, KVTableState.ACTIVE, null, executor).get();
assertEquals(configuration1, store.getConfiguration(scope, kvtable1, null, executor).get());
// endregion
// region checkSegments
List<KVTSegmentRecord> segments = store.getActiveSegments(scope, kvtable1, null, executor).get();
assertEquals(2, segments.size());
segments = store.getActiveSegments(scope, kvtable2, null, executor).get();
assertEquals(3, segments.size());
// endregion
}
use of io.pravega.controller.store.kvtable.records.KVTSegmentRecord in project pravega by pravega.
the class TableMetadataTasksTest method testCreateKeyValueTable.
@Test(timeout = 30000)
public void testCreateKeyValueTable() throws ExecutionException, InterruptedException {
Assert.assertTrue(isScopeCreated);
long creationTime = System.currentTimeMillis();
KeyValueTableConfiguration kvtConfig = KeyValueTableConfiguration.builder().partitionCount(2).primaryKeyLength(4).secondaryKeyLength(4).build();
CompletableFuture<Controller.CreateKeyValueTableStatus.Status> createOperationFuture = kvtMetadataTasks.createKeyValueTable(SCOPE, kvtable1, kvtConfig, creationTime, 0L);
assertTrue(Futures.await(processEvent((TableMetadataTasksTest.WriterMock) requestEventWriter)));
assertEquals(CreateKeyValueTableStatus.Status.SUCCESS, createOperationFuture.join());
List<KVTSegmentRecord> segmentsList = kvtStore.getActiveSegments(SCOPE, kvtable1, null, executor).get();
assertEquals(segmentsList.size(), kvtConfig.getPartitionCount());
long storedCreationTime = kvtStore.getCreationTime(SCOPE, kvtable1, null, executor).get();
assertEquals(storedCreationTime, creationTime);
KeyValueTableConfiguration storedConfig = kvtStore.getConfiguration(SCOPE, kvtable1, null, executor).get();
assertEquals(storedConfig.getPartitionCount(), kvtConfig.getPartitionCount());
// check retry failures...
EventHelper mockHelper = EventHelperMock.getFailingEventHelperMock();
TableMetadataTasks kvtFailingMetaTasks = spy(new TableMetadataTasks(kvtStore, segmentHelperMock, executor, executor, "host", GrpcAuthHelper.getDisabledAuthHelper(), mockHelper));
AssertExtensions.assertFutureThrows("addIndexAndSubmitTask throws exception", kvtFailingMetaTasks.createKeyValueTable(SCOPE, kvtable1, kvtConfig, creationTime, 0L), e -> Exceptions.unwrap(e) instanceof RuntimeException);
}
use of io.pravega.controller.store.kvtable.records.KVTSegmentRecord in project pravega by pravega.
the class AbstractKVTableMetadataStore method deleteKeyValueTable.
@Override
public CompletableFuture<Void> deleteKeyValueTable(final String scope, final String name, final OperationContext ctx, final Executor executor) {
OperationContext kvtContext = getOperationContext(ctx);
KeyValueTable kvTable = getKVTable(scope, name, kvtContext);
return Futures.completeOn(Futures.exceptionallyExpecting(kvTable.getActiveEpochRecord(true, kvtContext).thenApply(epoch -> epoch.getSegments().stream().map(KVTSegmentRecord::getSegmentNumber).reduce(Integer::max).get()).thenCompose(lastActiveSegment -> recordLastKVTableSegment(scope, name, lastActiveSegment, kvtContext, executor)), DATA_NOT_FOUND_PREDICATE, null).thenCompose(v -> kvTable.delete(kvtContext)), executor).thenCompose(v -> deleteFromScope(scope, name, kvtContext, executor));
}
Aggregations