use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method doNotChangeVersion.
@Test
public void doNotChangeVersion() {
// Check if a naive removal of the index without updating the version is checked
RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
assertInvalid("new meta-data does not have newer version", metaData1, metaData1);
RecordMetaDataBuilder metaData2Builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
metaData2Builder.removeIndex("MySimpleRecord$str_value_indexed");
validator.validate(metaData1, metaData2Builder.getRecordMetaData());
metaData2Builder.setVersion(metaData1.getVersion());
assertInvalid("new meta-data does not have newer version", metaData1, metaData2Builder.build(false));
// If the validator allows not changing the version, it should make sure all of the changes are compatible
MetaDataEvolutionValidator validatorAcceptingSameVersion = MetaDataEvolutionValidator.newBuilder().setAllowNoVersionChange(true).build();
validatorAcceptingSameVersion.validate(metaData1, metaData1);
// Confirm with the laxer validator that the removed index is noticed
metaData2Builder.setVersion(metaData1.getVersion() + 1);
RecordMetaDataBuilder metaData3Builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
metaData3Builder.setVersion(metaData1.getVersion() + 1);
RecordMetaData metaData3 = metaData3Builder.getRecordMetaData();
RecordMetaData metaData4 = metaData2Builder.getRecordMetaData();
assertInvalid("new meta-data does not have newer version", metaData3, metaData4);
assertInvalid("new former index has removed version that is not newer than the old meta-data version", validatorAcceptingSameVersion, metaData3, metaData4);
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method indexUsedWhereFormerIndexWas.
@Test
public void indexUsedWhereFormerIndexWas() {
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
metaDataBuilder.removeIndex("MySimpleRecord$str_value_indexed");
RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
RecordMetaDataBuilder metaData2Builder = RecordMetaData.newBuilder().setRecords(metaData1.toProto().toBuilder().clearFormerIndexes().build());
Index newIndex = new Index("newIndex", "str_value_indexed");
newIndex.setSubspaceKey("MySimpleRecord$str_value_indexed");
metaData2Builder.addIndex("MySimpleRecord", newIndex);
RecordMetaData metaData2 = metaData2Builder.getRecordMetaData();
assertInvalid("former index key used for new index in meta-data", metaData1, metaData2);
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method indexPrimaryKeyComponentsChanged.
@Test
public void indexPrimaryKeyComponentsChanged() {
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
metaDataBuilder.addIndex("MySimpleRecord", "rec_no", "rec_no");
RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
assertThat(metaData1.getIndex("rec_no").hasPrimaryKeyComponentPositions(), is(true));
RecordMetaData tempMetaData = addNewRecordType(metaData1);
RecordMetaData metaData2 = replaceIndex(tempMetaData, "rec_no", indexProto -> indexProto.toBuilder().addRecordType("NewRecord").build());
assertInvalid("new index drops primary key component positions", metaData1, metaData2);
// This is essentially the behavior change outlined by: https://github.com/FoundationDB/fdb-record-layer/issues/93
metaData2.getIndex("rec_no").setPrimaryKeyComponentPositions(new int[] { 0 });
validator.validate(metaData1, metaData2);
metaData1.getIndex("rec_no").setPrimaryKeyComponentPositions(null);
assertInvalid("new index adds primary key component positions", metaData1, metaData2);
metaData1.getIndex("rec_no").setPrimaryKeyComponentPositions(new int[] { 0 });
metaData2.getIndex("rec_no").setPrimaryKeyComponentPositions(new int[] { 1 });
assertInvalid("new index changes primary key component positions", metaData1, metaData2);
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method removeIndexAndDropAddedVersion.
@Test
public void removeIndexAndDropAddedVersion() {
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
RecordMetaData metaData1 = RecordMetaData.build(metaDataBuilder.getRecordMetaData().toProto());
metaDataBuilder.removeIndex("MySimpleRecord$str_value_indexed");
RecordMetaDataProto.MetaData metaData2Proto = metaDataBuilder.getRecordMetaData().toProto();
RecordMetaData metaData2 = RecordMetaData.build(metaData2Proto.toBuilder().removeFormerIndexes(0).addFormerIndexes(metaData2Proto.getFormerIndexes(0).toBuilder().clearAddedVersion()).build());
assertInvalid("former index reports added version older than replacing index", metaData1, metaData2);
// With the option set, it should validate
MetaDataEvolutionValidator laxerValidator = MetaDataEvolutionValidator.newBuilder().setAllowOlderFormerIndexAddedVerions(true).build();
laxerValidator.validate(metaData1, metaData2);
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method changeFormerIndexVersion.
@Test
public void changeFormerIndexVersion() {
RecordMetaDataBuilder metaData1Builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
metaData1Builder.removeIndex("MySimpleRecord$str_value_indexed");
RecordMetaData metaData1 = metaData1Builder.getRecordMetaData();
RecordMetaDataProto.MetaData.Builder metaData2ProtoBuilder = metaData1.toProto().toBuilder().setVersion(metaData1.getVersion() + 1);
metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).setRemovedVersion(metaData1.getVersion() + 1));
RecordMetaData metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
assertInvalid("removed version of former index differs from prior version", metaData1, metaData2);
metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).setRemovedVersion(metaData1.getVersion()).setAddedVersion(metaData1.getVersion() - 2));
metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
assertInvalid("added version of former index differs from prior version", metaData1, metaData2);
metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).clearAddedVersion());
metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
assertInvalid("added version of former index differs from prior version", metaData1, metaData2);
}
Aggregations