use of com.apple.foundationdb.record.metadata.MetaDataException in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method updateSchemaOptions.
@Test
public void updateSchemaOptions() {
int version;
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
metaDataStore.saveRecordMetaData(metaData);
version = metaDataStore.getRecordMetaData().getVersion();
context.commit();
}
// Unset store record versions.
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertTrue(metaDataStore.getRecordMetaData().isStoreRecordVersions());
metaDataStore.updateStoreRecordVersions(false);
context.commit();
assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
assertFalse(metaDataStore.getRecordMetaData().isStoreRecordVersions());
}
// Set store record versions.
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertFalse(metaDataStore.getRecordMetaData().isStoreRecordVersions());
metaDataStore.updateStoreRecordVersions(true);
context.commit();
assertEquals(version + 2, metaDataStore.getRecordMetaData().getVersion());
assertTrue(metaDataStore.getRecordMetaData().isStoreRecordVersions());
}
// Enable split long records with default validator. It should fail.
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertFalse(metaDataStore.getRecordMetaData().isSplitLongRecords());
MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.enableSplitLongRecords());
assertEquals(e.getMessage(), "new meta-data splits long records");
context.commit();
assertEquals(version + 2, metaDataStore.getRecordMetaData().getVersion());
assertTrue(metaDataStore.getRecordMetaData().isStoreRecordVersions());
}
// Enable split long records
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
metaDataStore.setEvolutionValidator(MetaDataEvolutionValidator.newBuilder().setAllowUnsplitToSplit(true).build());
assertFalse(metaDataStore.getRecordMetaData().isSplitLongRecords());
metaDataStore.enableSplitLongRecords();
context.commit();
assertEquals(version + 3, metaDataStore.getRecordMetaData().getVersion());
assertTrue(metaDataStore.getRecordMetaData().isStoreRecordVersions());
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertTrue(metaDataStore.getRecordMetaData().isStoreRecordVersions());
assertEquals(version + 3, metaDataStore.getRecordMetaData().getVersion());
context.commit();
}
}
use of com.apple.foundationdb.record.metadata.MetaDataException in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method indexes.
@ParameterizedTest(name = "indexes [indexCounterBasedSubspaceKey = {0}]")
@BooleanSource
public void indexes(final boolean indexCounterBasedSubspaceKey) {
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaDataBuilder builder = RecordMetaData.newBuilder();
if (indexCounterBasedSubspaceKey) {
builder.enableCounterBasedSubspaceKeys();
}
metaDataStore.saveRecordMetaData(builder.setRecords(TestRecords1Proto.getDescriptor()).getRecordMetaData());
context.commit();
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
metaDataStore.addIndex("MySimpleRecord", "testIndex", "rec_no");
assertNotNull(metaDataStore.getRecordMetaData().getIndex("testIndex"));
context.commit();
assertNotNull(metaDataStore.getRecordMetaData().getIndex("testIndex"));
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertNotNull(metaDataStore.getRecordMetaData().getIndex("testIndex"));
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.addIndex("MySimpleRecord", "testIndex", "rec_no"));
assertEquals("Index testIndex already defined", e.getMessage());
metaDataStore.dropIndex("testIndex");
context.commit();
e = assertThrows(MetaDataException.class, () -> metaDataStore.getRecordMetaData().getIndex("testIndex"));
assertEquals("Index testIndex not defined", e.getMessage());
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.getRecordMetaData().getIndex("testIndex"));
assertEquals("Index testIndex not defined", e.getMessage());
e = assertThrows(MetaDataException.class, () -> metaDataStore.dropIndex("testIndex"));
assertEquals("No index named testIndex defined", e.getMessage());
context.commit();
}
}
use of com.apple.foundationdb.record.metadata.MetaDataException in project fdb-record-layer by FoundationDB.
the class OnlineIndexerBuildSumIndexTest method sumRebuild.
private void sumRebuild(@Nonnull List<TestRecords1Proto.MySimpleRecord> records, @Nullable List<TestRecords1Proto.MySimpleRecord> recordsWhileBuilding, int agents, boolean overlap) {
Index index = new Index("newSumIndex", field("num_value_2").ungrouped(), IndexTypes.SUM);
IndexAggregateFunction aggregateFunction = new IndexAggregateFunction(FunctionNames.SUM, index.getRootExpression(), index.getName());
Runnable beforeBuild = new Runnable() {
@SuppressWarnings("try")
@Override
public void run() {
try (FDBRecordContext context = openContext()) {
metaData.getIndex(index.getName());
} catch (MetaDataException e) {
assertEquals("Index newSumIndex not defined", e.getMessage());
}
}
};
Runnable afterBuild = new Runnable() {
@SuppressWarnings("try")
@Override
public void run() {
metaData.getIndex(index.getName());
try (FDBRecordContext context = openContext()) {
FDBRestrictedIndexQueryTest.assertThrowsAggregateFunctionNotSupported(() -> recordStore.evaluateAggregateFunction(Collections.singletonList("MySimpleRecord"), aggregateFunction, TupleRange.ALL, IsolationLevel.SNAPSHOT), "newSumIndex.sum(Field { 'num_value_2' None} group 1)");
} catch (Exception e) {
fail();
}
}
};
List<TestRecords1Proto.MySimpleRecord> updatedRecords;
if (recordsWhileBuilding == null || recordsWhileBuilding.size() == 0) {
updatedRecords = records;
} else {
updatedRecords = updated(records, recordsWhileBuilding);
}
Runnable afterReadable = new Runnable() {
@SuppressWarnings("try")
@Override
public void run() {
try (FDBRecordContext context = openContext()) {
long sum = recordStore.evaluateAggregateFunction(Collections.singletonList("MySimpleRecord"), aggregateFunction, TupleRange.ALL, IsolationLevel.SNAPSHOT).join().getLong(0);
long expected = updatedRecords.stream().mapToInt(msg -> msg.hasNumValue2() ? msg.getNumValue2() : 0).sum();
assertEquals(expected, sum);
}
}
};
singleRebuild(records, recordsWhileBuilding, agents, overlap, false, index, beforeBuild, afterBuild, afterReadable);
}
use of com.apple.foundationdb.record.metadata.MetaDataException in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilder method updateUnionFieldsAndRecordTypes.
private void updateUnionFieldsAndRecordTypes(@Nonnull Descriptors.Descriptor union, boolean processExtensionOptions) {
final Map<String, RecordTypeBuilder> oldRecordTypes = ImmutableMap.copyOf(recordTypes);
recordTypes.clear();
unionFields.clear();
for (Descriptors.FieldDescriptor unionField : union.getFields()) {
Descriptors.Descriptor newDescriptor = unionField.getMessageType();
Descriptors.Descriptor oldDescriptor = findOldDescriptor(unionField, union);
if (unionFields.containsKey(newDescriptor)) {
if (!recordTypes.containsKey(newDescriptor.getName())) {
// Union field was seen before but the record type is unknown? This must not happen.
throw new MetaDataException("Unknown record type for union field " + unionField.getName());
}
// For existing record types, the preferred field is the last one, except if there is one whose name matches.
remapUnionField(newDescriptor, unionField);
} else if (oldDescriptor == null) {
// New field and record type.
RecordTypeBuilder recordType = processRecordType(unionField, processExtensionOptions);
if (recordType.getSinceVersion() != null && recordType.getSinceVersion() != version) {
throw new MetaDataException(String.format("Record type version (%d) does not match meta-data version (%d)", recordType.getSinceVersion(), version));
} else {
recordType.setSinceVersion(version);
}
unionFields.put(newDescriptor, unionField);
} else {
updateRecordType(oldRecordTypes, oldDescriptor, newDescriptor);
unionFields.put(newDescriptor, unionField);
}
}
}
use of com.apple.foundationdb.record.metadata.MetaDataException in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilder method addJoinedRecordType.
/**
* Add a new joined record type.
* @param name the name of the new record type
* @return a new uninitialized joined record type
*/
@Nonnull
@API(API.Status.EXPERIMENTAL)
public JoinedRecordTypeBuilder addJoinedRecordType(@Nonnull String name) {
if (recordTypes.containsKey(name)) {
throw new MetaDataException("There is already a record type named " + name);
}
if (syntheticRecordTypes.containsKey(name)) {
throw new MetaDataException("There is already a synthetic record type named " + name);
}
JoinedRecordTypeBuilder recordType = new JoinedRecordTypeBuilder(name, getNextRecordTypeKey(), this);
syntheticRecordTypes.put(name, recordType);
return recordType;
}
Aggregations