Search in sources :

Example 1 with SnapshotStage

use of com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage 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 2 with SnapshotStage

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

the class MvccMetainfoRepository method startSnapshotStage.

@Override
@Nonnull
@SuppressFBWarnings(value = { "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "UL_UNRELEASED_LOCK" })
public SnapshotStage startSnapshotStage() {
    ReadLock readLock = lock.readLock();
    LOGGER.trace("Trying to create a {}", MvccSnapshotStage.class);
    readLock.lock();
    SnapshotStage snapshotStage = null;
    try {
        snapshotStage = new MvccSnapshotStage(readLock);
        LOGGER.trace("{} created", MvccSnapshotStage.class);
    } finally {
        if (snapshotStage == null) {
            LOGGER.error("Error while trying to create a {}", MvccMergerStage.class);
            readLock.unlock();
        }
    }
    assert snapshotStage != null;
    return snapshotStage;
}
Also used : ReadLock(java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock) SnapshotStage(com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage) Nonnull(javax.annotation.Nonnull) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with SnapshotStage

use of com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage 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 4 with SnapshotStage

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

the class ReservedIdInfoFactoryImpl method startUp.

@Override
protected void startUp() throws Exception {
    ImmutableMetaSnapshot snapshot;
    try (SnapshotStage snapshotStage = metainfoRepository.startSnapshotStage()) {
        snapshot = snapshotStage.createImmutableSnapshot();
    }
    try (Connection connection = sqlInterface.getDbBackend().createSystemConnection()) {
        DSLContext dsl = sqlInterface.getDslContextFactory().createDslContext(connection);
        megaMap = loadRowIds(dsl, snapshot);
    }
}
Also used : SnapshotStage(com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot)

Aggregations

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