Search in sources :

Example 26 with ImmutableMetaSnapshot

use of com.torodb.core.transaction.metainf.ImmutableMetaSnapshot in project torodb by torodb.

the class SnapshotMergerForIndexTest method testIndexWithMultiFieldsWithNewOrphanDocPartIndexConflict.

/**
   * Test that an exception is thrown on new doc part index with missing index with multiple fields
   * conflicts Case 3&2.KO1.2
   *
   * @throws Exception
   */
@Test
public void testIndexWithMultiFieldsWithNewOrphanDocPartIndexConflict() throws Exception {
    MutableMetaSnapshot currentModifiedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName2", "fieldId12", FieldType.STRING);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName3", "fieldId13", FieldType.STRING);
    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);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaDocPartIndex(false).addMetaDocPartIndexColumn("fieldId12", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).getAddedMutableMetaDocPartIndexes().iterator().next().addMetaDocPartIndexColumn("fieldId13", 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").removeMetaIndexByName("idxName2");
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).removeMetaDocPartIndexByIdentifier("idxId2");
    MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName2", "fieldId2", FieldType.BINARY);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName3", "fieldId3", FieldType.BINARY);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaDocPartIndex(false).addMetaDocPartIndexColumn("fieldId2", FieldIndexOrdering.ASC);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).getAddedMutableMetaDocPartIndexes().iterator().next().addMetaDocPartIndexColumn("fieldId3", FieldIndexOrdering.ASC);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).getAddedMutableMetaDocPartIndexes().iterator().next().immutableCopy("idxId3");
    try {
        new SnapshotMerger(currentModifiedSnapshot.immutableCopy(), changedSnapshot).merge();
        Assert.fail("A " + UnmergeableException.class.getSimpleName() + " was expected to be thrown");
    } catch (UnmergeableException ex) {
    }
}
Also used : WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) UnmergeableException(com.torodb.core.transaction.metainf.UnmergeableException) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot) WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) Test(org.junit.Test)

Example 27 with ImmutableMetaSnapshot

use of com.torodb.core.transaction.metainf.ImmutableMetaSnapshot in project torodb by torodb.

the class SnapshotMergerForIndexTest method testRemoveIndexWithMultiFieldsWithDocPartIndexIncludedByOtherIndex.

/**
   * Test remove an index with multiple fields that relates to a doc part index that also relate to
   * another index Case 2&1.OK1.2
   *
   * @throws Exception
   */
@Test
public void testRemoveIndexWithMultiFieldsWithDocPartIndexIncludedByOtherIndex() 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);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName2").addMetaIndexField(tableRefFactory.createRoot(), "fieldName4", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName2").addMetaIndexField(tableRefFactory.createRoot(), "fieldName5", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName2", "fieldId2", FieldType.STRING);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName3", "fieldId3", FieldType.STRING);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName4", "fieldId4", FieldType.STRING);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).addMetaField("fieldName5", "fieldId5", FieldType.STRING);
    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().addMetaDocPartIndexColumn("fieldId3", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).getAddedMutableMetaDocPartIndexes().iterator().next().addMetaDocPartIndexColumn("fieldId4", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).getAddedMutableMetaDocPartIndexes().iterator().next().addMetaDocPartIndexColumn("fieldId5", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaDocPartByTableRef(tableRefFactory.createRoot()).getAddedMutableMetaDocPartIndexes().iterator().next().immutableCopy("idxId2");
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaIndex("idxName3", false).addMetaIndexField(tableRefFactory.createRoot(), "fieldName2", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName3").addMetaIndexField(tableRefFactory.createRoot(), "fieldName3", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName3").addMetaIndexField(tableRefFactory.createRoot(), "fieldName4", FieldIndexOrdering.ASC);
    currentModifiedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").getMetaIndexByName("idxName3").addMetaIndexField(tableRefFactory.createRoot(), "fieldName5", FieldIndexOrdering.ASC);
    ImmutableMetaSnapshot currentSnapshot = currentModifiedSnapshot.immutableCopy();
    MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").removeMetaIndexByName("idxName2");
    new SnapshotMerger(currentSnapshot, changedSnapshot).merge();
}
Also used : WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot) WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) Test(org.junit.Test)

Example 28 with ImmutableMetaSnapshot

use of com.torodb.core.transaction.metainf.ImmutableMetaSnapshot in project torodb by torodb.

the class SnapshotMergerForIndexTest method testNewIndex.

/**
   * Test a new index Case [1&1.OK1|1&2.OK1].1
   *
   * @throws Exception
   */
@Test
public void testNewIndex() throws Exception {
    MutableMetaSnapshot currentModifiedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
    ImmutableMetaSnapshot currentSnapshot = currentModifiedSnapshot.immutableCopy();
    MutableMetaSnapshot changedSnapshot = new WrapperMutableMetaSnapshot(currentSnapshot);
    changedSnapshot.getMetaDatabaseByName("dbName1").getMetaCollectionByName("colName1").addMetaIndex("idxName2", false).addMetaIndexField(tableRefFactory.createRoot(), "fieldName2", FieldIndexOrdering.ASC);
    new SnapshotMerger(currentSnapshot, changedSnapshot).merge();
}
Also used : WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot) WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) Test(org.junit.Test)

Example 29 with ImmutableMetaSnapshot

use of com.torodb.core.transaction.metainf.ImmutableMetaSnapshot 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));
}
Also used : MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) SnapshotStage(com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot) MergerStage(com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage) Test(org.junit.Test)

Example 30 with ImmutableMetaSnapshot

use of com.torodb.core.transaction.metainf.ImmutableMetaSnapshot 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) {
    }
}
Also used : WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) UnmergeableException(com.torodb.core.transaction.metainf.UnmergeableException) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot) WrapperMutableMetaSnapshot(com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot) Test(org.junit.Test)

Aggregations

ImmutableMetaSnapshot (com.torodb.core.transaction.metainf.ImmutableMetaSnapshot)65 Test (org.junit.Test)62 MutableMetaSnapshot (com.torodb.core.transaction.metainf.MutableMetaSnapshot)56 WrapperMutableMetaSnapshot (com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot)55 UnmergeableException (com.torodb.core.transaction.metainf.UnmergeableException)22 SnapshotStage (com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage)2 MergerStage (com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage)1 MutableMetaDocPart (com.torodb.core.transaction.metainf.MutableMetaDocPart)1 Connection (java.sql.Connection)1 DSLContext (org.jooq.DSLContext)1