Search in sources :

Example 46 with RecordMetaDataBuilder

use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.

the class TextIndexTest method indexArguments.

@Nonnull
public static Stream<Arguments> indexArguments() {
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecordsTextProto.getDescriptor());
    Index simpleIndex = metaDataBuilder.getIndex(TextIndexTestUtils.SIMPLE_DEFAULT_NAME);
    simpleIndex.setSubspaceKey(TextIndexTestUtils.SIMPLE_DEFAULT_NAME + "-2");
    return Stream.of(simpleIndex, SIMPLE_TEXT_FILTERING, SIMPLE_TEXT_PREFIX, SIMPLE_TEXT_SUFFIXES).map(Arguments::of);
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Arguments(org.junit.jupiter.params.provider.Arguments) Index(com.apple.foundationdb.record.metadata.Index) Nonnull(javax.annotation.Nonnull)

Example 47 with RecordMetaDataBuilder

use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreIndexTest method formerIndexes.

@Test
public void formerIndexes() throws Exception {
    RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    try (FDBRecordContext context = openContext()) {
        uncheckedOpenRecordStore(context, metaData.getRecordMetaData());
        recordStore.checkVersion(null, FDBRecordStoreBase.StoreExistenceCheck.ERROR_IF_EXISTS).join();
        context.commit();
    }
    metaData.addIndex("MySimpleRecord", "num_value_2");
    try (FDBRecordContext context = openContext()) {
        uncheckedOpenRecordStore(context, metaData.getRecordMetaData());
        timer.reset();
        recordStore.checkVersion(null, FDBRecordStoreBase.StoreExistenceCheck.ERROR_IF_NOT_EXISTS).join();
        assertEquals(1, timer.getCount(FDBStoreTimer.Events.REBUILD_INDEX));
        assertEquals(0, timer.getCount(FDBStoreTimer.Events.REMOVE_FORMER_INDEX));
        context.commit();
    }
    metaData.removeIndex("MySimpleRecord$num_value_2");
    try (FDBRecordContext context = openContext()) {
        uncheckedOpenRecordStore(context, metaData.getRecordMetaData());
        timer.reset();
        recordStore.checkVersion(null, FDBRecordStoreBase.StoreExistenceCheck.ERROR_IF_NOT_EXISTS).join();
        assertEquals(0, timer.getCount(FDBStoreTimer.Events.REBUILD_INDEX));
        assertEquals(1, timer.getCount(FDBStoreTimer.Events.REMOVE_FORMER_INDEX));
        context.commit();
    }
    metaData.addIndex("MySimpleRecord", "num_value_2");
    metaData.getIndex("MySimpleRecord$num_value_2").setSubspaceKey("MySimpleRecord$num_value_2_prime");
    metaData.removeIndex("MySimpleRecord$num_value_2");
    try (FDBRecordContext context = openContext()) {
        uncheckedOpenRecordStore(context, metaData.getRecordMetaData());
        timer.reset();
        recordStore.checkVersion(null, FDBRecordStoreBase.StoreExistenceCheck.ERROR_IF_NOT_EXISTS).join();
        assertEquals(0, timer.getCount(FDBStoreTimer.Events.REBUILD_INDEX));
        assertEquals(0, timer.getCount(FDBStoreTimer.Events.REMOVE_FORMER_INDEX));
        context.commit();
    }
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 48 with RecordMetaDataBuilder

use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreOpeningTest method storeExistenceChecks.

@Test
public void storeExistenceChecks() {
    try (FDBRecordContext context = openContext()) {
        RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
        FDBRecordStore.Builder storeBuilder = storeBuilder(context, metaData);
        assertThrows(RecordStoreDoesNotExistException.class, storeBuilder::open);
        recordStore = storeBuilder.uncheckedOpen();
        TestRecords1Proto.MySimpleRecord.Builder simple = TestRecords1Proto.MySimpleRecord.newBuilder();
        simple.setRecNo(1);
        recordStore.insertRecord(simple.build());
        commit(context);
    }
    try (FDBRecordContext context = openContext()) {
        FDBRecordStore.Builder storeBuilder = recordStore.asBuilder().setContext(context);
        assertThrows(RecordStoreNoInfoAndNotEmptyException.class, storeBuilder::createOrOpen);
        recordStore = storeBuilder.createOrOpen(FDBRecordStoreBase.StoreExistenceCheck.NONE);
        commit(context);
    }
    try (FDBRecordContext context = openContext()) {
        FDBRecordStore.Builder storeBuilder = recordStore.asBuilder().setContext(context);
        assertThrows(RecordStoreAlreadyExistsException.class, storeBuilder::create);
        recordStore = storeBuilder.open();
        assertNotNull(recordStore.loadRecord(Tuple.from(1)));
        commit(context);
    }
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Example 49 with RecordMetaDataBuilder

use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreOpeningTest method conflictWithHeaderChange.

/**
 * Validate that if the store header changes then an open record store in another transaction is failed with
 * a conflict.
 */
@Test
public void conflictWithHeaderChange() {
    RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaDataBuilder.addIndex("MySimpleRecord", "num_value_2");
    RecordMetaData metaData2 = metaDataBuilder.getRecordMetaData();
    assertThat(metaData1.getVersion(), lessThan(metaData2.getVersion()));
    try (FDBRecordContext context = openContext()) {
        FDBRecordStore recordStore = storeBuilder(context, metaData1).create();
        assertEquals(metaData1.getVersion(), recordStore.getRecordStoreState().getStoreHeader().getMetaDataversion());
        commit(context);
    }
    try (FDBRecordContext context1 = openContext();
        FDBRecordContext context2 = openContext()) {
        FDBRecordStore recordStore1 = storeBuilder(context1, metaData1).open();
        assertEquals(metaData1.getVersion(), recordStore1.getRecordStoreState().getStoreHeader().getMetaDataversion());
        FDBRecordStore recordStore2 = storeBuilder(context2, metaData2).open();
        assertEquals(metaData2.getVersion(), recordStore2.getRecordStoreState().getStoreHeader().getMetaDataversion());
        commit(context2);
        // Add a write to the first record store to make sure that the conflict are actually checked.
        recordStore1.saveRecord(TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1066L).setNumValue2(1415).build());
        assertThrows(FDBExceptions.FDBStoreTransactionConflictException.class, context1::commit);
    }
    try (FDBRecordContext context = openContext()) {
        assertThrows(RecordStoreStaleMetaDataVersionException.class, () -> storeBuilder(context, metaData1).open());
        FDBRecordStore recordStore = storeBuilder(context, metaData2).open();
        assertEquals(metaData2.getVersion(), recordStore.getRecordStoreState().getStoreHeader().getMetaDataversion());
        commit(context);
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Example 50 with RecordMetaDataBuilder

use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreOpeningTest method metaDataVersionZero.

@Test
public void metaDataVersionZero() {
    final RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestNoIndexesProto.getDescriptor());
    metaData.setVersion(0);
    final FDBRecordStoreBase.UserVersionChecker newStore = (oldUserVersion, oldMetaDataVersion, metaData1) -> {
        assertEquals(-1, oldUserVersion);
        assertEquals(-1, oldMetaDataVersion);
        return CompletableFuture.completedFuture(0);
    };
    try (FDBRecordContext context = openContext()) {
        recordStore = storeBuilder(context, metaData).setUserVersionChecker(newStore).create();
        assertTrue(recordStore.getRecordStoreState().getStoreHeader().hasMetaDataversion());
        assertTrue(recordStore.getRecordStoreState().getStoreHeader().hasUserVersion());
        commit(context);
    }
    final FDBRecordStoreBase.UserVersionChecker oldStore = (oldUserVersion, oldMetaDataVersion, metaData12) -> {
        assertEquals(0, oldUserVersion);
        assertEquals(0, oldMetaDataVersion);
        return CompletableFuture.completedFuture(0);
    };
    try (FDBRecordContext context = openContext()) {
        recordStore = storeBuilder(context, metaData).setUserVersionChecker(oldStore).open();
        commit(context);
    }
}
Also used : LogMessageKeys(com.apple.foundationdb.record.logging.LogMessageKeys) LoggerFactory(org.slf4j.LoggerFactory) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Matchers.hasKey(org.hamcrest.Matchers.hasKey) Subspace(com.apple.foundationdb.subspace.Subspace) Tuple(com.apple.foundationdb.tuple.Tuple) Range(com.apple.foundationdb.Range) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) TestHelpers(com.apple.foundationdb.record.TestHelpers) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Expressions.concatenateFields(com.apple.foundationdb.record.metadata.Key.Expressions.concatenateFields) RecordMetaDataOptionsProto(com.apple.foundationdb.record.RecordMetaDataOptionsProto) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) Tag(org.junit.jupiter.api.Tag) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) ImmutableSet(com.google.common.collect.ImmutableSet) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) CompletionException(java.util.concurrent.CompletionException) StandardCharsets(java.nio.charset.StandardCharsets) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) KeySpacePath(com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpacePath) RecordMetaDataProvider(com.apple.foundationdb.record.RecordMetaDataProvider) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IndexTypes(com.apple.foundationdb.record.metadata.IndexTypes) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TestNoIndexesProto(com.apple.foundationdb.record.TestNoIndexesProto) TestRecords1EvolvedAgainProto(com.apple.foundationdb.record.TestRecords1EvolvedAgainProto) Descriptors(com.google.protobuf.Descriptors) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CompletableFuture(java.util.concurrent.CompletableFuture) RangeSet(com.apple.foundationdb.async.RangeSet) Supplier(java.util.function.Supplier) Matchers.lessThan(org.hamcrest.Matchers.lessThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) EmptyKeyExpression(com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Tags(com.apple.test.Tags) IndexState(com.apple.foundationdb.record.IndexState) TestRecords1EvolvedProto(com.apple.foundationdb.record.TestRecords1EvolvedProto) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) AtomicLong(java.util.concurrent.atomic.AtomicLong) Index(com.apple.foundationdb.record.metadata.Index) Collections(java.util.Collections) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

RecordMetaDataBuilder (com.apple.foundationdb.record.RecordMetaDataBuilder)150 Test (org.junit.jupiter.api.Test)91 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)69 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 Nonnull (javax.annotation.Nonnull)22 Index (com.apple.foundationdb.record.metadata.Index)21 Descriptors (com.google.protobuf.Descriptors)15 TestRecords1Proto (com.apple.foundationdb.record.TestRecords1Proto)14 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)14 RecordMetaDataProto (com.apple.foundationdb.record.RecordMetaDataProto)13 ByteString (com.google.protobuf.ByteString)13 Tuple (com.apple.foundationdb.tuple.Tuple)12 Collections (java.util.Collections)12 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)11 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)11 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)11 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)11 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)10 BooleanSource (com.apple.test.BooleanSource)10