Search in sources :

Example 1 with KVTSegmentRecord

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));
}
Also used : KVTEpochRecord(io.pravega.controller.store.kvtable.records.KVTEpochRecord) ImmutableList(com.google.common.collect.ImmutableList) KVTSegmentRecord(io.pravega.controller.store.kvtable.records.KVTSegmentRecord)

Example 2 with KVTSegmentRecord

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
}
Also used : KVTSegmentRecord(io.pravega.controller.store.kvtable.records.KVTSegmentRecord) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with KVTSegmentRecord

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);
}
Also used : CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) DeleteKVTableStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteKVTableStatus) CreateKeyValueTableStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateKeyValueTableStatus) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) EventHelper(io.pravega.controller.task.EventHelper) KVTSegmentRecord(io.pravega.controller.store.kvtable.records.KVTSegmentRecord) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Example 4 with KVTSegmentRecord

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));
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) ControllerService(io.pravega.controller.server.ControllerService) OperationContext(io.pravega.controller.store.stream.OperationContext) LoadingCache(com.google.common.cache.LoadingCache) Getter(lombok.Getter) Executor(java.util.concurrent.Executor) Predicate(java.util.function.Predicate) Exceptions(io.pravega.common.Exceptions) Set(java.util.Set) Scope(io.pravega.controller.store.Scope) CompletableFuture(java.util.concurrent.CompletableFuture) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) HostIndex(io.pravega.controller.store.index.HostIndex) CacheLoader(com.google.common.cache.CacheLoader) KVTSegmentRecord(io.pravega.controller.store.kvtable.records.KVTSegmentRecord) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) StoreException(io.pravega.controller.store.stream.StoreException) Pair(org.apache.commons.lang3.tuple.Pair) CacheBuilder(com.google.common.cache.CacheBuilder) Futures(io.pravega.common.concurrent.Futures) KVTSegmentRecord(io.pravega.controller.store.kvtable.records.KVTSegmentRecord)

Aggregations

KVTSegmentRecord (io.pravega.controller.store.kvtable.records.KVTSegmentRecord)4 KeyValueTableConfiguration (io.pravega.client.tables.KeyValueTableConfiguration)2 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)2 Test (org.junit.Test)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 ImmutableList (com.google.common.collect.ImmutableList)1 Exceptions (io.pravega.common.Exceptions)1 Futures (io.pravega.common.concurrent.Futures)1 ControllerService (io.pravega.controller.server.ControllerService)1 Scope (io.pravega.controller.store.Scope)1 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)1 HostIndex (io.pravega.controller.store.index.HostIndex)1 KVTEpochRecord (io.pravega.controller.store.kvtable.records.KVTEpochRecord)1 OperationContext (io.pravega.controller.store.stream.OperationContext)1 StoreException (io.pravega.controller.store.stream.StoreException)1 CreateKeyValueTableStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateKeyValueTableStatus)1 CreateScopeStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus)1 DeleteKVTableStatus (io.pravega.controller.stream.api.grpc.v1.Controller.DeleteKVTableStatus)1