use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.
the class SqlWriteTorodTransaction method createMetaDatabase.
private MutableMetaDatabase createMetaDatabase(String dbName) {
Preconditions.checkState(!isClosed());
MutableMetaSnapshot metaSnapshot = getInternalTransaction().getMetaSnapshot();
MutableMetaDatabase metaDb = metaSnapshot.addMetaDatabase(dbName, getConnection().getServer().getIdentifierFactory().toDatabaseIdentifier(metaSnapshot, dbName));
getInternalTransaction().getBackendTransaction().addDatabase(metaDb);
return metaDb;
}
use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.
the class MvccMetainfoRepositoryTest method testSingleThread.
@Test
public void testSingleThread() throws UnmergeableException {
MutableMetaSnapshot mutableSnapshot;
try (SnapshotStage snapshotStage = repository.startSnapshotStage()) {
mutableSnapshot = snapshotStage.createMutableSnapshot();
}
mutableSnapshot.addMetaDatabase(dbName, dbId).addMetaCollection(colName, colId);
Assert.assertNotNull(mutableSnapshot.getMetaDatabaseByName(dbName));
Assert.assertNotNull(mutableSnapshot.getMetaDatabaseByName(dbName).getMetaCollectionByIdentifier(colId));
try (MergerStage mergeStage = repository.startMerge(mutableSnapshot)) {
mergeStage.commit();
}
ImmutableMetaSnapshot immutableSnapshot;
try (SnapshotStage snapshotStage = repository.startSnapshotStage()) {
immutableSnapshot = snapshotStage.createImmutableSnapshot();
}
assertThat(immutableSnapshot.getMetaDatabaseByName(dbName)).named("the database by name").isNotNull();
Assert.assertNotNull(immutableSnapshot.getMetaDatabaseByName(dbName));
Assert.assertNotNull(immutableSnapshot.getMetaDatabaseByName(dbName).getMetaCollectionByIdentifier(colId));
}
use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.
the class SnapshotMergerForIndexTest method testRemoveIndexWithOldIndexWithSameDocPartIndexAddedConflict.
/**
* Test an exception is thrown when an index is removed and has same doc part index as an old
* added index Case 2&1.KO1.1
*
* @throws Exception
*/
@Test
public void testRemoveIndexWithOldIndexWithSameDocPartIndexAddedConflict() throws Exception {
MutableMetaSnapshot currentModifiedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName2", "fieldId2", FieldType.STRING);
currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaIndex("idxName2", true).addMetaIndexField(tableRefFactory.createRoot(), "fieldName2", FieldIndexOrdering.ASC);
currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName2").addMetaIndexField(tableRefFactory.createChild(tableRefFactory.createRoot(), "docPartName2"), "fieldName3", FieldIndexOrdering.ASC);
currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaDocPartIndex(false).addMetaDocPartIndexColumn("fieldId2", FieldIndexOrdering.ASC);
currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).getAddedMutableMetaDocPartIndexes().iterator().next().immutableCopy("idxId2");
ImmutableMetaSnapshot currentSnapshot = currentModifiedSnapshot.immutableCopy();
currentModifiedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaIndex("idxName3", false).addMetaIndexField(tableRefFactory.createRoot(), "fieldName2", FieldIndexOrdering.ASC);
MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").removeMetaIndexByName("idxName2");
changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).removeMetaDocPartIndexByIdentifier("idxId2");
try {
new SnapshotMerger(currentModifiedSnapshot.immutableCopy(), changedSnapshot).merge();
Assert.fail("A " + UnmergeableException.class.getSimpleName() + " was expected to be thrown");
} catch (UnmergeableException ex) {
}
}
use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.
the class SnapshotMergerForIndexTest method testIndexWithMissingDocPartIndexConflict.
/**
* Test that an exception is thrown on new field with missing doc part index conflicts Case
* 3&1.KO1.1
*
* @throws Exception
*/
@Test
public void testIndexWithMissingDocPartIndexConflict() throws Exception {
MutableMetaSnapshot currentModifiedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaIndex("idxName2", false).addMetaIndexField(tableRefFactory.createRoot(), "fieldName2", FieldIndexOrdering.ASC);
MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName2", "fieldId2", FieldType.STRING);
try {
new SnapshotMerger(currentModifiedSnapshot.immutableCopy(), changedSnapshot).merge();
Assert.fail("A " + UnmergeableException.class.getSimpleName() + " was expected to be thrown");
} catch (UnmergeableException ex) {
}
}
use of com.torodb.core.transaction.metainf.MutableMetaSnapshot in project torodb by torodb.
the class SnapshotMergerForIndexTest method testIndexWithMultiFieldsWithNewFieldAndMissingDocPartIndexConflict.
/**
* Test that an exception is thrown on new field with missing doc part index for existing index
* with multiple fields conflicts Case 3&3.KO1.2
*
* @throws Exception
*/
@Test
public void testIndexWithMultiFieldsWithNewFieldAndMissingDocPartIndexConflict() throws Exception {
MutableMetaSnapshot currentModifiedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaIndex("idxName2", false).addMetaIndexField(tableRefFactory.createRoot(), "fieldName2", FieldIndexOrdering.ASC);
currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName2").addMetaIndexField(tableRefFactory.createRoot(), "fieldName3", FieldIndexOrdering.ASC);
ImmutableMetaSnapshot currentSnapshot = currentModifiedSnapshot.immutableCopy();
currentModifiedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName2", "fieldId2", FieldType.STRING);
MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName3", "fieldId3", FieldType.STRING);
try {
new SnapshotMerger(currentModifiedSnapshot.immutableCopy(), changedSnapshot).merge();
Assert.fail("A " + UnmergeableException.class.getSimpleName() + " was expected to be thrown");
} catch (UnmergeableException ex) {
}
}
Aggregations