Search in sources :

Example 1 with OAbstractPaginatedStorage

use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.

the class OIndexRIDContainer method resolveFileIdByName.

private long resolveFileIdByName(String fileName) {
    final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getUnderlying();
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = storage.getAtomicOperationsManager().startAtomicOperation(fileName, true);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexEngineException("Error creation of sbtree with name " + fileName, fileName), e);
    }
    try {
        final OReadCache readCache = storage.getReadCache();
        final OWriteCache writeCache = storage.getWriteCache();
        if (atomicOperation == null) {
            if (writeCache.exists(fileName))
                return writeCache.fileIdByName(fileName);
            return readCache.addFile(fileName, writeCache);
        } else {
            long fileId;
            if (atomicOperation.isFileExists(fileName))
                fileId = atomicOperation.loadFile(fileName);
            else
                fileId = atomicOperation.addFile(fileName);
            storage.getAtomicOperationsManager().endAtomicOperation(false, null, fileName);
            return fileId;
        }
    } catch (IOException e) {
        try {
            storage.getAtomicOperationsManager().endAtomicOperation(true, e, fileName);
        } catch (IOException ioe) {
            throw OException.wrapException(new OIndexEngineException("Error of rollback of atomic operation", fileName), ioe);
        }
        throw OException.wrapException(new OIndexEngineException("Error creation of sbtree with name " + fileName, fileName), e);
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OReadCache(com.orientechnologies.orient.core.storage.cache.OReadCache) IOException(java.io.IOException) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) OIndexEngineException(com.orientechnologies.orient.core.index.OIndexEngineException)

Example 2 with OAbstractPaginatedStorage

use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.

the class OIndexManagerShared method autoRecreateIndexesAfterCrash.

public boolean autoRecreateIndexesAfterCrash() {
    if (rebuildCompleted)
        return false;
    final ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.INSTANCE.get();
    final OStorage storage = database.getStorage().getUnderlying();
    if (storage instanceof OAbstractPaginatedStorage) {
        OAbstractPaginatedStorage paginatedStorage = (OAbstractPaginatedStorage) storage;
        return paginatedStorage.wereDataRestoredAfterOpen() && paginatedStorage.wereNonTxOperationsPerformedInPreviousOpen();
    }
    return false;
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 3 with OAbstractPaginatedStorage

use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.

the class OHashIndexFactory method createIndexEngine.

@Override
public OIndexEngine createIndexEngine(final String algoritm, final String name, final Boolean durableInNonTxMode, final OStorage storage, final int version, final Map<String, String> engineProperties) {
    OIndexEngine indexEngine;
    final String storageType = storage.getType();
    if (storageType.equals("memory") || storageType.equals("plocal"))
        indexEngine = new OHashTableIndexEngine(name, durableInNonTxMode, (OAbstractPaginatedStorage) storage, version);
    else if (storageType.equals("distributed"))
        // DISTRIBUTED CASE: HANDLE IT AS FOR LOCAL
        indexEngine = new OHashTableIndexEngine(name, durableInNonTxMode, (OAbstractPaginatedStorage) storage.getUnderlying(), version);
    else if (storageType.equals("remote"))
        indexEngine = new ORemoteIndexEngine(name);
    else
        throw new OIndexException("Unsupported storage type: " + storageType);
    return indexEngine;
}
Also used : OIndexException(com.orientechnologies.orient.core.index.OIndexException) OHashTableIndexEngine(com.orientechnologies.orient.core.index.engine.OHashTableIndexEngine) OIndexEngine(com.orientechnologies.orient.core.index.OIndexEngine) ORemoteIndexEngine(com.orientechnologies.orient.core.index.engine.ORemoteIndexEngine) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)

Example 4 with OAbstractPaginatedStorage

use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.

the class OLogManager method log.

public void log(final Object iRequester, final Level iLevel, String iMessage, final Throwable iException, final Object... iAdditionalArgs) {
    if (iMessage != null) {
        try {
            final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE != null ? ODatabaseRecordThreadLocal.INSTANCE.getIfDefined() : null;
            if (db != null && db.getStorage() != null && db.getStorage() instanceof OAbstractPaginatedStorage) {
                final String dbName = db.getStorage().getName();
                if (dbName != null)
                    iMessage = "$ANSI{green {db=" + dbName + "}} " + iMessage;
            }
        } catch (Throwable e) {
        }
        final String requesterName;
        if (iRequester instanceof Class<?>) {
            requesterName = ((Class<?>) iRequester).getName();
        } else if (iRequester != null) {
            requesterName = iRequester.getClass().getName();
        } else {
            requesterName = DEFAULT_LOG;
        }
        Logger log = loggersCache.get(requesterName);
        if (log == null) {
            log = Logger.getLogger(requesterName);
            if (log != null) {
                Logger oldLogger = loggersCache.putIfAbsent(requesterName, log);
                if (oldLogger != null)
                    log = oldLogger;
            }
        }
        if (log == null) {
            // USE SYSERR
            try {
                System.err.println(String.format(iMessage, iAdditionalArgs));
            } catch (Exception e) {
                OLogManager.instance().warn(this, "Error on formatting message", e);
            }
        } else if (log.isLoggable(iLevel)) {
            // USE THE LOG
            try {
                final String msg = String.format(iMessage, iAdditionalArgs);
                if (iException != null)
                    log.log(iLevel, msg, iException);
                else
                    log.log(iLevel, msg);
            } catch (Exception e) {
                System.err.print(String.format("Error on formatting message '%s'. Exception: %s", iMessage, e.toString()));
            }
        }
    }
}
Also used : OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 5 with OAbstractPaginatedStorage

use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.

the class OTransactionAbstract method lockRecord.

@Override
public OTransaction lockRecord(final OIdentifiable iRecord, final OStorage.LOCKING_STRATEGY lockingStrategy) {
    final OStorage stg = database.getStorage();
    if (!(stg.getUnderlying() instanceof OAbstractPaginatedStorage))
        throw new OLockException("Cannot lock record across remote connections");
    final ORID rid = new ORecordId(iRecord.getIdentity());
    LockedRecordMetadata lockedRecordMetadata = locks.get(rid);
    boolean addItem = false;
    if (lockedRecordMetadata == null) {
        lockedRecordMetadata = new LockedRecordMetadata(lockingStrategy);
        addItem = true;
    } else if (lockedRecordMetadata.strategy != lockingStrategy) {
        assert lockedRecordMetadata.locksCount == 0;
        lockedRecordMetadata = new LockedRecordMetadata(lockingStrategy);
        addItem = true;
    }
    if (lockingStrategy == OStorage.LOCKING_STRATEGY.EXCLUSIVE_LOCK)
        ((OAbstractPaginatedStorage) stg.getUnderlying()).acquireWriteLock(rid);
    else if (lockingStrategy == OStorage.LOCKING_STRATEGY.SHARED_LOCK)
        ((OAbstractPaginatedStorage) stg.getUnderlying()).acquireReadLock(rid);
    else
        throw new IllegalStateException("Unsupported locking strategy " + lockingStrategy);
    lockedRecordMetadata.locksCount++;
    if (addItem) {
        locks.put(rid, lockedRecordMetadata);
    }
    return this;
}
Also used : OLockException(com.orientechnologies.common.concur.lock.OLockException) OStorage(com.orientechnologies.orient.core.storage.OStorage) ORID(com.orientechnologies.orient.core.id.ORID) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Aggregations

OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)38 OStorage (com.orientechnologies.orient.core.storage.OStorage)12 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)9 OWriteCache (com.orientechnologies.orient.core.storage.cache.OWriteCache)7 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)5 Test (org.testng.annotations.Test)5 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 OLocalPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage)4 File (java.io.File)4 BeforeClass (org.testng.annotations.BeforeClass)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 IOException (java.io.IOException)3 OLockException (com.orientechnologies.common.concur.lock.OLockException)2 OException (com.orientechnologies.common.exception.OException)2 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)2 ORID (com.orientechnologies.orient.core.id.ORID)2 ORemoteIndexEngine (com.orientechnologies.orient.core.index.engine.ORemoteIndexEngine)2