Search in sources :

Example 91 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OHashTableDirectory method setMaxLeftChildDepth.

public void setMaxLeftChildDepth(int nodeIndex, byte maxLeftChildDepth) throws IOException {
    startOperation();
    try {
        OAtomicOperation atomicOperation = startAtomicOperation(true);
        acquireExclusiveLock();
        try {
            final ODirectoryPage page = loadPage(nodeIndex, true, atomicOperation);
            try {
                page.setMaxLeftChildDepth(getLocalNodeIndex(nodeIndex), maxLeftChildDepth);
            } finally {
                releasePage(page, true, atomicOperation);
            }
            endAtomicOperation(false, null);
        } catch (IOException e) {
            endAtomicOperation(true, e);
            throw e;
        } catch (Exception e) {
            endAtomicOperation(true, e);
            throw OException.wrapException(new OHashTableDirectoryException("Error during setting of max left child depth", this), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OHashTableDirectoryException(com.orientechnologies.orient.core.exception.OHashTableDirectoryException) IOException(java.io.IOException) OHashTableDirectoryException(com.orientechnologies.orient.core.exception.OHashTableDirectoryException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException)

Example 92 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OHashTableDirectory method getMaxLeftChildDepth.

public byte getMaxLeftChildDepth(int nodeIndex) throws IOException {
    startOperation();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                final OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                final ODirectoryPage page = loadPage(nodeIndex, false, atomicOperation);
                try {
                    return page.getMaxLeftChildDepth(getLocalNodeIndex(nodeIndex));
                } finally {
                    releasePage(page, false, atomicOperation);
                }
            } finally {
                releaseSharedLock();
            }
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)

Example 93 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OHashTableDirectory method addNewNode.

public int addNewNode(byte maxLeftChildDepth, byte maxRightChildDepth, byte nodeLocalDepth, long[] newNode) throws IOException {
    startOperation();
    try {
        int nodeIndex;
        OAtomicOperation atomicOperation = startAtomicOperation(true);
        acquireExclusiveLock();
        try {
            OCacheEntry firstEntry = loadPage(atomicOperation, fileId, firstEntryIndex, true);
            firstEntry.acquireExclusiveLock();
            try {
                ODirectoryFirstPage firstPage = new ODirectoryFirstPage(firstEntry, getChanges(atomicOperation, firstEntry), firstEntry);
                final int tombstone = firstPage.getTombstone();
                if (tombstone >= 0)
                    nodeIndex = tombstone;
                else {
                    nodeIndex = firstPage.getTreeSize();
                    firstPage.setTreeSize(nodeIndex + 1);
                }
                if (nodeIndex < ODirectoryFirstPage.NODES_PER_PAGE) {
                    final int localNodeIndex = nodeIndex;
                    firstPage.setMaxLeftChildDepth(localNodeIndex, maxLeftChildDepth);
                    firstPage.setMaxRightChildDepth(localNodeIndex, maxRightChildDepth);
                    firstPage.setNodeLocalDepth(localNodeIndex, nodeLocalDepth);
                    if (tombstone >= 0)
                        firstPage.setTombstone((int) firstPage.getPointer(nodeIndex, 0));
                    for (int i = 0; i < newNode.length; i++) firstPage.setPointer(localNodeIndex, i, newNode[i]);
                } else {
                    final int pageIndex = nodeIndex / ODirectoryPage.NODES_PER_PAGE;
                    final int localLevel = nodeIndex % ODirectoryPage.NODES_PER_PAGE;
                    OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, true);
                    while (cacheEntry == null || cacheEntry.getPageIndex() < pageIndex) {
                        if (cacheEntry != null)
                            releasePage(atomicOperation, cacheEntry);
                        cacheEntry = addPage(atomicOperation, fileId);
                    }
                    cacheEntry.acquireExclusiveLock();
                    try {
                        ODirectoryPage page = new ODirectoryPage(cacheEntry, getChanges(atomicOperation, cacheEntry), cacheEntry);
                        page.setMaxLeftChildDepth(localLevel, maxLeftChildDepth);
                        page.setMaxRightChildDepth(localLevel, maxRightChildDepth);
                        page.setNodeLocalDepth(localLevel, nodeLocalDepth);
                        if (tombstone >= 0)
                            firstPage.setTombstone((int) page.getPointer(localLevel, 0));
                        for (int i = 0; i < newNode.length; i++) page.setPointer(localLevel, i, newNode[i]);
                    } finally {
                        cacheEntry.releaseExclusiveLock();
                        releasePage(atomicOperation, cacheEntry);
                    }
                }
            } finally {
                firstEntry.releaseExclusiveLock();
                releasePage(atomicOperation, firstEntry);
            }
            endAtomicOperation(false, null);
        } catch (IOException e) {
            endAtomicOperation(true, e);
            throw e;
        } catch (RuntimeException e) {
            endAtomicOperation(true, e);
            throw e;
        } finally {
            releaseExclusiveLock();
        }
        return nodeIndex;
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) IOException(java.io.IOException)

Example 94 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OHashTableDirectory method setNodePointer.

public void setNodePointer(int nodeIndex, int index, long pointer) throws IOException {
    startOperation();
    try {
        OAtomicOperation atomicOperation = startAtomicOperation(true);
        acquireExclusiveLock();
        try {
            final ODirectoryPage page = loadPage(nodeIndex, true, atomicOperation);
            try {
                page.setPointer(getLocalNodeIndex(nodeIndex), index, pointer);
            } finally {
                releasePage(page, true, atomicOperation);
            }
            endAtomicOperation(false, null);
        } catch (IOException e) {
            endAtomicOperation(true, e);
            throw e;
        } catch (Exception e) {
            endAtomicOperation(true, e);
            throw OException.wrapException(new OHashTableDirectoryException("Error during setting of node pointer", this), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OHashTableDirectoryException(com.orientechnologies.orient.core.exception.OHashTableDirectoryException) IOException(java.io.IOException) OHashTableDirectoryException(com.orientechnologies.orient.core.exception.OHashTableDirectoryException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException)

Example 95 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OHashTableDirectory method open.

public void open() throws IOException {
    startOperation();
    try {
        acquireExclusiveLock();
        try {
            OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
            fileId = openFile(atomicOperation, getFullName());
            final int filledUpTo = (int) getFilledUpTo(atomicOperation, fileId);
            for (int i = 0; i < filledUpTo; i++) {
                final OCacheEntry entry = loadPage(atomicOperation, fileId, i, true);
                assert entry != null;
                pinPage(atomicOperation, entry);
                releasePage(atomicOperation, entry);
            }
        } 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)

Aggregations

OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)118 IOException (java.io.IOException)94 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)76 OException (com.orientechnologies.common.exception.OException)42 OIndexException (com.orientechnologies.orient.core.index.OIndexException)28 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)25 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)16 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)16 OSBTreeBonsaiLocalException (com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException)13 Lock (java.util.concurrent.locks.Lock)13 OHashTableDirectoryException (com.orientechnologies.orient.core.exception.OHashTableDirectoryException)11 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)11 OPaginatedClusterException (com.orientechnologies.orient.core.exception.OPaginatedClusterException)9 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)9 OClusterPositionMapException (com.orientechnologies.orient.core.exception.OClusterPositionMapException)8 ORecordId (com.orientechnologies.orient.core.id.ORecordId)7 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)6 OReadCache (com.orientechnologies.orient.core.storage.cache.OReadCache)2 OWriteCache (com.orientechnologies.orient.core.storage.cache.OWriteCache)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1