Search in sources :

Example 1 with MergerStage

use of com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage in project torodb by torodb.

the class WriteInternalTransaction method commit.

public void commit() throws RollbackException, UserException {
    try (MergerStage mergeStage = metainfoRepository.startMerge(metaSnapshot)) {
        backendTransaction.commit();
        mergeStage.commit();
    }
}
Also used : MergerStage(com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage)

Example 2 with MergerStage

use of com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage in project torodb by torodb.

the class SnapshotUpdaterImpl method updateSnapshot.

@Override
public void updateSnapshot(MetainfoRepository metainfoRepository) throws InvalidDatabaseException {
    MutableMetaSnapshot mutableSnapshot;
    try (SnapshotStage stage = metainfoRepository.startSnapshotStage()) {
        mutableSnapshot = stage.createMutableSnapshot();
    }
    if (mutableSnapshot.streamMetaDatabases().anyMatch((o) -> true)) {
        LOGGER.warn("Trying to update a not empty metainfo repository with information from " + "the database");
    }
    try (Connection connection = sqlInterface.getDbBackend().createSystemConnection()) {
        DSLContext dsl = sqlInterface.getDslContextFactory().createDslContext(connection);
        Updater updater = new Updater(dsl, tableRefFactory, sqlInterface);
        updater.loadMetaSnapshot(mutableSnapshot);
        connection.commit();
    } catch (SQLException sqlException) {
        throw sqlInterface.getErrorHandler().handleException(Context.UNKNOWN, sqlException);
    }
    try (MergerStage merge = metainfoRepository.startMerge(mutableSnapshot)) {
        merge.commit();
    }
}
Also used : MutableMetaSnapshot(com.torodb.core.transaction.metainf.MutableMetaSnapshot) SnapshotStage(com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage) SQLException(java.sql.SQLException) SnapshotUpdater(com.torodb.core.backend.SnapshotUpdater) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) MergerStage(com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage)

Example 3 with MergerStage

use of com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage in project torodb by torodb.

the class MvccMetainfoRepository method startMerge.

@Override
@Nonnull
@SuppressFBWarnings(value = { "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "UL_UNRELEASED_LOCK" })
public MergerStage startMerge(MutableMetaSnapshot newSnapshot) throws UnmergeableException {
    LOGGER.trace("Trying to create a {}", MvccMergerStage.class);
    MergerStage mergeStage = null;
    if (newSnapshot.hasChanged()) {
        lock.writeLock().lock();
        try {
            mergeStage = new MvccMergerStage(newSnapshot, lock.writeLock());
            LOGGER.trace("{} created", MvccMergerStage.class);
        } finally {
            if (mergeStage == null) {
                LOGGER.error("Error while trying to create a {}", MvccMergerStage.class);
                lock.writeLock().unlock();
            }
        }
    } else {
        mergeStage = noChangeMergeStage;
    }
    assert mergeStage != null;
    return mergeStage;
}
Also used : MergerStage(com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage) Nonnull(javax.annotation.Nonnull) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with MergerStage

use of com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage 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)

Aggregations

MergerStage (com.torodb.core.transaction.metainf.MetainfoRepository.MergerStage)4 SnapshotStage (com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage)2 MutableMetaSnapshot (com.torodb.core.transaction.metainf.MutableMetaSnapshot)2 SnapshotUpdater (com.torodb.core.backend.SnapshotUpdater)1 ImmutableMetaSnapshot (com.torodb.core.transaction.metainf.ImmutableMetaSnapshot)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Nonnull (javax.annotation.Nonnull)1 DSLContext (org.jooq.DSLContext)1 Test (org.junit.Test)1