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