use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method updateRecordsWithLocalFileDescriptor.
@Test
public void updateRecordsWithLocalFileDescriptor() {
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
metaDataStore.saveRecordMetaData(metaData);
context.commit();
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
// Local file descriptor is not as evolved as the to-be updating records descriptor. It will fail.
metaDataStore.setLocalFileDescriptor(TestRecords1Proto.getDescriptor());
MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.updateRecords(TestRecords1EvolvedProto.getDescriptor()));
assertEquals(e.getMessage(), "record type removed from union");
metaDataStore.setLocalFileDescriptor(TestRecords1EvolvedAgainProto.getDescriptor());
metaDataStore.updateRecords(TestRecords1EvolvedProto.getDescriptor());
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MyOtherRecord"));
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("AnotherRecord"));
e = assertThrows(MetaDataException.class, () -> metaDataStore.getRecordMetaData().getRecordType("OneMoreRecord"));
assertEquals(e.getMessage(), "Unknown record type OneMoreRecord");
context.commit();
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MyOtherRecord"));
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("AnotherRecord"));
MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.getRecordMetaData().getRecordType("OneMoreRecord"));
assertEquals(e.getMessage(), "Unknown record type OneMoreRecord");
context.commit();
}
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method dontRenameRecordTypeInIndexesWhenClashingWithImported.
/**
* Validate that if a {@code NESTED} record with the same name as an imported record type
* has its name changed, then the indexes do not change their record type.
*/
@Test
public void dontRenameRecordTypeInIndexesWhenClashingWithImported() {
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData metaData = RecordMetaData.build(TestRecordsImportedAndNewProto.getDescriptor());
assertEquals(ImmutableSet.of("MySimpleRecord", "MyOtherRecord"), metaData.getRecordTypes().keySet());
assertSame(metaData.getRecordType("MySimpleRecord").getDescriptor(), TestRecords1Proto.MySimpleRecord.getDescriptor());
assertNotSame(metaData.getRecordType("MySimpleRecord").getDescriptor(), TestRecordsImportedAndNewProto.MySimpleRecord.getDescriptor());
assertSame(metaData.getRecordType("MyOtherRecord").getDescriptor(), TestRecordsImportedAndNewProto.MyOtherRecord.getDescriptor());
assertNotSame(metaData.getRecordType("MyOtherRecord").getDescriptor(), TestRecords1Proto.MyOtherRecord.getDescriptor());
metaDataStore.saveRecordMetaData(metaData);
context.commit();
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
metaDataStore.mutateMetaData(metaDataProtoBuilder -> {
MetaDataProtoEditor.renameRecordType(metaDataProtoBuilder, "MySimpleRecord", "MyNewSimpleRecord");
assertThat(metaDataProtoBuilder.getRecordTypesList().stream().map(RecordMetaDataProto.RecordType::getName).collect(Collectors.toList()), hasItem("MySimpleRecord"));
for (RecordMetaDataProto.Index index : metaDataProtoBuilder.getIndexesList()) {
assertThat(index.getRecordTypeList(), not(hasItem("MyNewSimpleRecord")));
}
});
RecordMetaData metaData = metaDataStore.getRecordMetaData();
assertEquals(ImmutableSet.of("MySimpleRecord", "MyOtherRecord"), metaData.getRecordTypes().keySet());
assertEquals("MyNewSimpleRecord", metaData.getRecordsDescriptor().findMessageTypeByName("MyOtherRecord").findFieldByName("simple").getMessageType().getName());
context.commit();
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData metaData = metaDataStore.getRecordMetaData();
assertEquals(ImmutableSet.of("MySimpleRecord", "MyOtherRecord"), metaData.getRecordTypes().keySet());
assertEquals("MyNewSimpleRecord", metaData.getRecordsDescriptor().findMessageTypeByName("MyOtherRecord").findFieldByName("simple").getMessageType().getName());
}
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method changeSplitLongRecords.
@Test
public void changeSplitLongRecords() {
RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
assertThat(metaData1.isSplitLongRecords(), is(false));
RecordMetaData metaData2 = RecordMetaData.build(metaData1.toProto().toBuilder().setVersion(metaData1.getVersion() + 1).setSplitLongRecords(true).build());
assertInvalid("new meta-data splits long records", metaData1, metaData2);
MetaDataEvolutionValidator laxerValidator = MetaDataEvolutionValidator.newBuilder().setAllowUnsplitToSplit(true).build();
laxerValidator.validate(metaData1, metaData2);
RecordMetaData metaData3 = RecordMetaData.build(metaData2.toProto().toBuilder().setVersion(metaData2.getVersion() + 1).setSplitLongRecords(false).build());
assertInvalid("new meta-data no longer splits long records", metaData2, metaData3);
assertInvalid("new meta-data no longer splits long records", laxerValidator, metaData2, metaData3);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method formerIndexWithoutExistingIndex.
@Test
public void formerIndexWithoutExistingIndex() {
RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
RecordMetaData metaData2 = RecordMetaData.build(metaData1.toProto().toBuilder().setVersion(metaData1.getVersion() + 2).addFormerIndexes(RecordMetaDataProto.FormerIndex.newBuilder().setSubspaceKey(ByteString.copyFrom(Tuple.from("dummy_key").pack())).setRemovedVersion(metaData1.getVersion() + 2).setAddedVersion(metaData1.getVersion() + 1).build()).build());
validator.validate(metaData1, metaData2);
metaData2 = RecordMetaData.build(metaData2.toProto().toBuilder().setFormerIndexes(0, metaData2.getFormerIndexes().get(0).toProto().toBuilder().setAddedVersion(metaData1.getVersion()).build()).build());
assertInvalid("former index without existing index has added version prior to old meta-data version", metaData1, metaData2);
MetaDataEvolutionValidator laxerValidator = MetaDataEvolutionValidator.newBuilder().setAllowOlderFormerIndexAddedVerions(true).build();
laxerValidator.validate(metaData1, metaData2);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method dropField.
@Test
public void dropField() {
FileDescriptor updatedFile = mutateFile(fileBuilder -> fileBuilder.getMessageTypeBuilderList().forEach(message -> {
if (message.getName().equals("MySimpleRecord")) {
int fieldNumValue2Index = 0;
while (!message.getField(fieldNumValue2Index).getName().equals("num_value_2")) {
fieldNumValue2Index++;
}
message.removeField(fieldNumValue2Index);
}
}));
assertInvalid("field removed from message descriptor", TestRecords1Proto.getDescriptor(), updatedFile);
RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
RecordMetaData metaData2 = replaceRecordsDescriptor(metaData1, updatedFile);
assertInvalid("field removed from message descriptor", metaData1, metaData2);
}
Aggregations