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