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();
}
}
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();
}
}
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;
}
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));
}
Aggregations