Search in sources :

Example 1 with OClusterPositionMapException

use of com.orientechnologies.orient.core.exception.OClusterPositionMapException in project orientdb by orientechnologies.

the class OClusterPositionMap method resurrect.

public void resurrect(final long clusterPosition, final OClusterPositionMapBucket.PositionEntry entry) throws IOException {
    startOperation();
    try {
        OAtomicOperation atomicOperation = startAtomicOperation(true);
        acquireExclusiveLock();
        try {
            final long pageIndex = clusterPosition / OClusterPositionMapBucket.MAX_ENTRIES;
            final int index = (int) (clusterPosition % OClusterPositionMapBucket.MAX_ENTRIES);
            if (pageIndex >= getFilledUpTo(atomicOperation, fileId))
                throw new OClusterPositionMapException("Passed in cluster position " + clusterPosition + " is outside of range of cluster-position map", this);
            final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false, 1);
            cacheEntry.acquireExclusiveLock();
            try {
                final OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
                bucket.resurrect(index, entry);
            } finally {
                cacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, cacheEntry);
            }
            endAtomicOperation(false, null);
        } catch (IOException e) {
            endAtomicOperation(true, e);
            throw OException.wrapException(new OClusterPositionMapException("Error of resurrecting mapping between logical and physical record position", this), e);
        } catch (RuntimeException e) {
            endAtomicOperation(true, e);
            throw OException.wrapException(new OClusterPositionMapException("Error of resurrecting mapping between logical and physical record position", this), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OClusterPositionMapException(com.orientechnologies.orient.core.exception.OClusterPositionMapException) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) IOException(java.io.IOException)

Example 2 with OClusterPositionMapException

use of com.orientechnologies.orient.core.exception.OClusterPositionMapException in project orientdb by orientechnologies.

the class OClusterPositionMap method allocate.

public long allocate() throws IOException {
    startOperation();
    try {
        OAtomicOperation atomicOperation = startAtomicOperation(true);
        acquireExclusiveLock();
        try {
            long lastPage = getFilledUpTo(atomicOperation, fileId) - 1;
            OCacheEntry cacheEntry;
            if (lastPage < 0)
                cacheEntry = addPage(atomicOperation, fileId);
            else
                cacheEntry = loadPage(atomicOperation, fileId, lastPage, false, 1);
            Exception exception = null;
            cacheEntry.acquireExclusiveLock();
            try {
                OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
                if (bucket.isFull()) {
                    cacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, cacheEntry);
                    cacheEntry = addPage(atomicOperation, fileId);
                    cacheEntry.acquireExclusiveLock();
                    bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
                }
                final long index = bucket.allocate();
                return index + cacheEntry.getPageIndex() * OClusterPositionMapBucket.MAX_ENTRIES;
            } catch (Exception e) {
                exception = e;
                throw OException.wrapException(new OClusterPositionMapException("Error during creation of mapping between logical and physical record position", this), e);
            } finally {
                try {
                    cacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, cacheEntry);
                } finally {
                    endAtomicOperation(exception != null, exception);
                }
            }
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OClusterPositionMapException(com.orientechnologies.orient.core.exception.OClusterPositionMapException) OException(com.orientechnologies.common.exception.OException) OClusterPositionMapException(com.orientechnologies.orient.core.exception.OClusterPositionMapException) IOException(java.io.IOException)

Example 3 with OClusterPositionMapException

use of com.orientechnologies.orient.core.exception.OClusterPositionMapException in project orientdb by orientechnologies.

the class OClusterPositionMap method delete.

public void delete() throws IOException {
    startOperation();
    try {
        final OAtomicOperation atomicOperation = startAtomicOperation(false);
        acquireExclusiveLock();
        try {
            deleteFile(atomicOperation, fileId);
            endAtomicOperation(false, null);
        } catch (IOException ioe) {
            endAtomicOperation(true, ioe);
            throw ioe;
        } catch (Exception e) {
            endAtomicOperation(true, e);
            throw OException.wrapException(new OClusterPositionMapException("Error during deletion of cluster position - physical position map", this), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OClusterPositionMapException(com.orientechnologies.orient.core.exception.OClusterPositionMapException) IOException(java.io.IOException) OException(com.orientechnologies.common.exception.OException) OClusterPositionMapException(com.orientechnologies.orient.core.exception.OClusterPositionMapException) IOException(java.io.IOException)

Example 4 with OClusterPositionMapException

use of com.orientechnologies.orient.core.exception.OClusterPositionMapException in project orientdb by orientechnologies.

the class OClusterPositionMap method remove.

public OClusterPositionMapBucket.PositionEntry remove(final long clusterPosition) throws IOException {
    startOperation();
    try {
        OAtomicOperation atomicOperation = startAtomicOperation(true);
        acquireExclusiveLock();
        try {
            long pageIndex = clusterPosition / OClusterPositionMapBucket.MAX_ENTRIES;
            int index = (int) (clusterPosition % OClusterPositionMapBucket.MAX_ENTRIES);
            Exception exception = null;
            final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false, 1);
            cacheEntry.acquireExclusiveLock();
            try {
                final OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
                return bucket.remove(index);
            } catch (Exception e) {
                exception = e;
                throw OException.wrapException(new OClusterPositionMapException("Error during removal of mapping between logical and physical record position", this), e);
            } finally {
                try {
                    cacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, cacheEntry);
                } finally {
                    endAtomicOperation(exception != null, exception);
                }
            }
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OClusterPositionMapException(com.orientechnologies.orient.core.exception.OClusterPositionMapException) OException(com.orientechnologies.common.exception.OException) OClusterPositionMapException(com.orientechnologies.orient.core.exception.OClusterPositionMapException) IOException(java.io.IOException)

Example 5 with OClusterPositionMapException

use of com.orientechnologies.orient.core.exception.OClusterPositionMapException in project orientdb by orientechnologies.

the class OClusterPositionMap method update.

public void update(final long clusterPosition, final OClusterPositionMapBucket.PositionEntry entry) throws IOException {
    startOperation();
    try {
        OAtomicOperation atomicOperation = startAtomicOperation(true);
        acquireExclusiveLock();
        try {
            final long pageIndex = clusterPosition / OClusterPositionMapBucket.MAX_ENTRIES;
            final int index = (int) (clusterPosition % OClusterPositionMapBucket.MAX_ENTRIES);
            if (pageIndex >= getFilledUpTo(atomicOperation, fileId))
                throw new OClusterPositionMapException("Passed in cluster position " + clusterPosition + " is outside of range of cluster-position map", this);
            final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false, 1);
            cacheEntry.acquireExclusiveLock();
            try {
                final OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
                bucket.set(index, entry);
            } finally {
                cacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, cacheEntry);
            }
            endAtomicOperation(false, null);
        } catch (IOException e) {
            endAtomicOperation(true, e);
            throw OException.wrapException(new OClusterPositionMapException("Error of update of mapping between logical and physical record position", this), e);
        } catch (RuntimeException e) {
            endAtomicOperation(true, e);
            throw OException.wrapException(new OClusterPositionMapException("Error of update of mapping between logical and physical record position", this), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OClusterPositionMapException(com.orientechnologies.orient.core.exception.OClusterPositionMapException) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) IOException(java.io.IOException)

Aggregations

OClusterPositionMapException (com.orientechnologies.orient.core.exception.OClusterPositionMapException)8 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)8 IOException (java.io.IOException)8 OException (com.orientechnologies.common.exception.OException)6 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)5