use of org.sirix.page.UberPage in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method rollback.
@Override
public XdmNodeWriteTrx rollback() {
acquireLock();
try {
mNodeReader.assertNotClosed();
// Reset modification counter.
mModificationCount = 0L;
// Close current page transaction.
final long trxID = getId();
final int revision = getRevisionNumber();
final int revNumber = getPageTransaction().getUberPage().isBootstrap() ? 0 : revision - 1;
final UberPage uberPage = getPageTransaction().rollback();
// Remember succesfully committed uber page in resource manager.
mNodeReader.mResourceManager.setLastCommittedUberPage(uberPage);
mNodeReader.getPageTransaction().clearCaches();
mNodeReader.getPageTransaction().closeCaches();
mNodeReader.mResourceManager.closeNodePageWriteTransaction(getId());
mNodeReader.setPageReadTransaction(null);
removeCommitFile();
final PageWriteTrx<Long, Record, UnorderedKeyValuePage> trx = mNodeReader.mResourceManager.createPageWriteTransaction(trxID, revNumber, revNumber, Abort.YES);
mNodeReader.setPageReadTransaction(trx);
mNodeReader.mResourceManager.setNodePageWriteTransaction(getId(), trx);
mNodeFactory = null;
mNodeFactory = new NodeFactoryImpl(trx);
reInstantiateIndexes();
return this;
} finally {
unLock();
}
}
use of org.sirix.page.UberPage in project sirix by sirixdb.
the class PageWriteTrxImpl method rollback.
@Override
public UberPage rollback() {
mPageRtx.assertNotClosed();
mLog.clear();
mLog.close();
mLog = createTrxIntentLog(mPageRtx.mResourceManager);
final UberPage lastUberPage = (UberPage) mPageWriter.read(mPageWriter.readUberPageReference(), mPageRtx);
return lastUberPage;
}
use of org.sirix.page.UberPage in project sirix by sirixdb.
the class PageWriteTrxImpl method commit.
@Override
public UberPage commit() {
mPageRtx.assertNotClosed();
mPageRtx.mResourceManager.getCommitLock().lock();
final Path commitFile = mPageRtx.mResourceManager.commitFile();
commitFile.toFile().deleteOnExit();
// Issues with windows that it's not created in the first time?
while (!Files.exists(commitFile)) {
try {
Files.createFile(commitFile);
} catch (final IOException e) {
throw new SirixIOException(e);
}
}
// Forcefully flush write-ahead transaction logs to persistent storage.
if (mPageRtx.mResourceManager.getResourceManagerConfig().dumpLogs()) {
mLog.toSecondCache();
}
final PageReference uberPageReference = new PageReference();
final UberPage uberPage = getUberPage();
uberPageReference.setPage(uberPage);
final int revision = uberPage.getRevisionNumber();
// Recursively write indirectly referenced pages.
uberPage.commit(this);
uberPageReference.setPage(uberPage);
mPageWriter.writeUberPageReference(uberPageReference);
uberPageReference.setPage(null);
final Path indexes = mPageRtx.mResourceConfig.mPath.resolve(ResourceConfiguration.ResourcePaths.INDEXES.getFile() + String.valueOf(revision) + ".xml");
if (!Files.exists(indexes)) {
try {
Files.createFile(indexes);
} catch (final IOException e) {
throw new SirixIOException(e);
}
}
try (final OutputStream out = new FileOutputStream(indexes.toFile())) {
mIndexController.serialize(out);
} catch (final IOException e) {
throw new SirixIOException("Index definitions couldn't be serialized!", e);
}
mLog.clear();
mLog.close();
mLog = createTrxIntentLog(mPageRtx.mResourceManager);
try {
Files.delete(commitFile);
} catch (final IOException e) {
throw new SirixIOException("Commit file couldn't be deleted!");
}
final UberPage commitedUberPage = (UberPage) mPageWriter.read(mPageWriter.readUberPageReference(), mPageRtx);
mPageRtx.mResourceManager.getCommitLock().unlock();
return commitedUberPage;
}
use of org.sirix.page.UberPage in project sirix by sirixdb.
the class PageWriteTrxImpl method close.
@Override
public void close() {
if (!mIsClosed) {
mPageRtx.assertNotClosed();
final UberPage lastUberPage = (UberPage) mPageWriter.read(mPageWriter.readUberPageReference(), mPageRtx);
mPageRtx.mResourceManager.setLastCommittedUberPage(lastUberPage);
mPageRtx.clearCaches();
mPageRtx.closeCaches();
closeCaches();
mPageWriter.close();
mIsClosed = true;
final long trxId = mPageRtx.getTrxId();
if (!mPageRtx.mResourceManager.getXdmNodeReadTrx(trxId).isPresent())
mPageRtx.mResourceManager.closeWriteTransaction(trxId);
}
}
use of org.sirix.page.UberPage in project sirix by sirixdb.
the class ResourceStore method openResource.
/**
* Open a resource, that is get an instance of a {@link ResourceManager} in order to read/write
* from the resource.
*
* @param database The database.
* @param resourceConfig The resource configuration.
* @param resourceManagerConfig The resource manager configuration.
* @param bufferManager The buffer manager.
* @param resourceFile The resource to open.
* @return A resource manager.
*/
public ResourceManager openResource(@Nonnull final DatabaseImpl database, @Nonnull final ResourceConfiguration resourceConfig, @Nonnull final ResourceManagerConfiguration resourceManagerConfig, @Nonnull final BufferManager bufferManager, @Nonnull final Path resourceFile) {
checkNotNull(database);
checkNotNull(resourceConfig);
return mResourceManagers.computeIfAbsent(resourceFile, k -> {
final Storage storage = StorageType.getStorage(resourceConfig);
final UberPage uberPage;
if (storage.exists()) {
try (final Reader reader = storage.createReader()) {
final PageReference firstRef = reader.readUberPageReference();
if (firstRef.getPage() == null) {
uberPage = (UberPage) reader.read(firstRef, null);
} else {
uberPage = (UberPage) firstRef.getPage();
}
}
} else {
// Bootstrap uber page and make sure there already is a root node.
uberPage = new UberPage();
}
final ResourceManager resourceManager = new XdmResourceManager(database, this, resourceConfig, resourceManagerConfig, bufferManager, StorageType.getStorage(resourceConfig), uberPage, mReadSemaphore, mWriteSempahore);
Databases.putResourceManager(resourceFile, resourceManager);
return resourceManager;
});
}
Aggregations