use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class LuceneQueryIntegrationTest method openRecordStore.
protected void openRecordStore(FDBRecordContext context, RecordMetaDataHook hook) {
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecordsTextProto.getDescriptor());
metaDataBuilder.getRecordType(TextIndexTestUtils.COMPLEX_DOC).setPrimaryKey(concatenateFields("group", "doc_id"));
metaDataBuilder.removeIndex("SimpleDocument$text");
hook.apply(metaDataBuilder);
recordStore = getStoreBuilder(context, metaDataBuilder.getRecordMetaData()).setSerializer(TextIndexTestUtils.COMPRESSING_SERIALIZER).uncheckedOpen();
setupPlanner(null);
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method withToProto.
@Test
public void withToProto() {
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecordsParentChildRelationshipProto.getDescriptor());
metaDataBuilder.addIndex("MyChildRecord", "MyChildRecord$str_value", Key.Expressions.field("str_value"));
metaDataBuilder.removeIndex("MyChildRecord$parent_rec_no");
metaDataBuilder.addIndex("MyChildRecord", new Index("MyChildRecord$parent&str", Key.Expressions.concatenateFields("parent_rec_no", "str_value"), Index.EMPTY_VALUE, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
metaDataBuilder.removeIndex("MyParentRecord$str_value_indexed");
metaDataBuilder.addIndex("MyParentRecord", "MyParentRecord$str&child", Key.Expressions.concat(Key.Expressions.field("str_value_indexed"), Key.Expressions.field("child_rec_nos", KeyExpression.FanType.FanOut)));
metaDataBuilder.addMultiTypeIndex(Arrays.asList(metaDataBuilder.getRecordType("MyChildRecord"), metaDataBuilder.getRecordType("MyParentRecord")), new Index("all$rec_nos", Key.Expressions.field("rec_no")));
RecordMetaData metaData = metaDataBuilder.getRecordMetaData();
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
metaDataStore.saveRecordMetaData(metaData);
context.commit();
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData retrievedMetaData = metaDataStore.getRecordMetaData();
MetaDataProtoTest.verifyEquals(metaData, retrievedMetaData);
}
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreSplitRecordsTest method clearOmitUnsplitRecordSuffixTyped.
@Test
public void clearOmitUnsplitRecordSuffixTyped() {
final RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
final KeyExpression pkey = concat(Key.Expressions.recordType(), field("rec_no"));
metaData.getRecordType("MySimpleRecord").setPrimaryKey(pkey);
metaData.getRecordType("MyOtherRecord").setPrimaryKey(pkey);
FDBRecordStore.Builder builder = FDBRecordStore.newBuilder().setKeySpacePath(path).setMetaDataProvider(metaData).setFormatVersion(FDBRecordStore.FORMAT_CONTROL_FORMAT_VERSION);
final FDBStoredRecord<Message> saved;
try (FDBRecordContext context = openContext()) {
recordStore = builder.setContext(context).create();
TestRecords1Proto.MyOtherRecord record = TestRecords1Proto.MyOtherRecord.newBuilder().setRecNo(1L).build();
saved = recordStore.saveRecord(record);
commit(context);
}
metaData.addIndex("MySimpleRecord", "num_value_2");
builder.setFormatVersion(FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION);
try (FDBRecordContext context = openContext()) {
recordStore = builder.setContext(context).open();
FDBStoredRecord<Message> loaded = recordStore.loadRecord(saved.getPrimaryKey());
assertNotNull(loaded);
assertEquals(saved.getRecord(), loaded.getRecord());
assertTrue(recordStore.getRecordStoreState().getStoreHeader().getOmitUnsplitRecordSuffix());
}
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreSplitRecordsTest method clearOmitUnsplitRecordSuffix.
@EnumSource(ClearOmitUnsplitRecordSuffixMode.class)
@ParameterizedTest(name = "clearOmitUnsplitRecordSuffix [mode = {0}]")
public void clearOmitUnsplitRecordSuffix(ClearOmitUnsplitRecordSuffixMode mode) {
final RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
FDBRecordStore.Builder builder = FDBRecordStore.newBuilder().setKeySpacePath(path).setMetaDataProvider(metaData).setFormatVersion(FDBRecordStore.FORMAT_CONTROL_FORMAT_VERSION);
try (FDBRecordContext context = openContext()) {
recordStore = builder.setContext(context).create();
if (mode != ClearOmitUnsplitRecordSuffixMode.EMPTY) {
TestRecords1Proto.MySimpleRecord record = TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1L).setStrValueIndexed("abc").build();
recordStore.saveRecord(record);
}
commit(context);
}
if (mode == ClearOmitUnsplitRecordSuffixMode.DELETE) {
try (FDBRecordContext context = openContext()) {
recordStore = builder.setContext(context).open();
recordStore.deleteRecord(Tuple.from(1L));
commit(context);
}
}
metaData.addIndex("MySimpleRecord", "num_value_2");
builder.setFormatVersion(FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION);
try (FDBRecordContext context = openContext()) {
recordStore = builder.setContext(context).open();
assertEquals(mode == ClearOmitUnsplitRecordSuffixMode.SAVE, recordStore.getRecordStoreState().getStoreHeader().getOmitUnsplitRecordSuffix());
}
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreTest method testUserVersionDeterminesMetaData.
@Test
public void testUserVersionDeterminesMetaData() {
final RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
builder.setVersion(101);
final RecordMetaData metaData1 = builder.getRecordMetaData();
builder.setVersion(102);
final RecordMetaData metaData2 = builder.getRecordMetaData();
final SwitchingProvider oldProvider = new SwitchingProvider(101, metaData1, metaData1);
final SwitchingProvider newProvider = new SwitchingProvider(102, metaData1, metaData2);
try (FDBRecordContext context = openContext()) {
recordStore = FDBRecordStore.newBuilder().setContext(context).setKeySpacePath(path).setMetaDataProvider(oldProvider).setUserVersionChecker(oldProvider).create();
assertEquals(101, recordStore.getUserVersion());
assertEquals(metaData1, recordStore.getRecordMetaData());
assertEquals(metaData1.getVersion(), recordStore.getRecordStoreState().getStoreHeader().getMetaDataversion());
context.commit();
}
try (FDBRecordContext context = openContext()) {
recordStore = FDBRecordStore.newBuilder().setContext(context).setKeySpacePath(path).setMetaDataProvider(newProvider).setUserVersionChecker(newProvider).open();
assertEquals(101, recordStore.getUserVersion());
assertEquals(metaData1, recordStore.getRecordMetaData());
assertEquals(metaData1.getVersion(), recordStore.getRecordStoreState().getStoreHeader().getMetaDataversion());
context.commit();
}
final SwitchingProvider newProvider2 = new SwitchingProvider(102, metaData1, metaData2);
try (FDBRecordContext context = openContext()) {
FDBRecordStore.deleteStore(context, path);
recordStore = FDBRecordStore.newBuilder().setContext(context).setKeySpacePath(path).setMetaDataProvider(newProvider2).setUserVersionChecker(newProvider2).create();
assertEquals(102, recordStore.getUserVersion());
assertEquals(metaData2, recordStore.getRecordMetaData());
assertEquals(metaData2.getVersion(), recordStore.getRecordStoreState().getStoreHeader().getMetaDataversion());
context.commit();
}
}
Aggregations