Search in sources :

Example 31 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage 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)

Example 32 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class OTransactionAbstract method unlockRecord.

@Override
public OTransaction unlockRecord(final OIdentifiable iRecord) {
    final OStorage stg = database.getStorage();
    if (!(stg.getUnderlying() instanceof OAbstractPaginatedStorage))
        throw new OLockException("Cannot lock record across remote connections");
    final ORID rid = iRecord.getIdentity();
    final LockedRecordMetadata lockedRecordMetadata = locks.get(rid);
    if (lockedRecordMetadata == null || lockedRecordMetadata.locksCount == 0)
        throw new OLockException("Cannot unlock a never acquired lock");
    else if (lockedRecordMetadata.strategy == OStorage.LOCKING_STRATEGY.EXCLUSIVE_LOCK)
        ((OAbstractPaginatedStorage) stg.getUnderlying()).releaseWriteLock(rid);
    else if (lockedRecordMetadata.strategy == OStorage.LOCKING_STRATEGY.SHARED_LOCK)
        ((OAbstractPaginatedStorage) stg.getUnderlying()).releaseReadLock(rid);
    else
        throw new IllegalStateException("Unsupported locking strategy " + lockedRecordMetadata.strategy);
    lockedRecordMetadata.locksCount--;
    if (lockedRecordMetadata.locksCount == 0)
        locks.remove(rid);
    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)

Example 33 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class OrientBaseGraph method shutdown.

/**
   * Closes the Graph. After closing the Graph cannot be used.
   */
public void shutdown(boolean closeDb, boolean commitTx) {
    makeActive();
    try {
        if (!isClosed() && commitTx) {
            final OStorage storage = getDatabase().getStorage().getUnderlying();
            if (storage instanceof OAbstractPaginatedStorage) {
                if (((OAbstractPaginatedStorage) storage).getWALInstance() != null)
                    getDatabase().commit();
            }
        }
    } catch (RuntimeException e) {
        OLogManager.instance().error(this, "Error during context close for db " + url, e);
        throw e;
    } catch (Exception e) {
        OLogManager.instance().error(this, "Error during context close for db " + url, e);
        throw OException.wrapException(new ODatabaseException("Error during context close for db " + url), e);
    } finally {
        try {
            if (closeDb) {
                getDatabase().close();
                if (getDatabase().isPooled()) {
                    database = null;
                }
            }
        } catch (Exception e) {
            OLogManager.instance().error(this, "Error during context close for db " + url, e);
        }
    }
    url = null;
    username = null;
    password = null;
    pollGraphFromStack(closeDb);
    if (!closeDb)
        getDatabase().activateOnCurrentThread();
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) OException(com.orientechnologies.common.exception.OException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 34 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class OServer method getAvailableStorageNames.

public Map<String, String> getAvailableStorageNames() {
    final OServerConfiguration configuration = serverCfg.getConfiguration();
    // SEARCH IN CONFIGURED PATHS
    final Map<String, String> storages = new HashMap<String, String>();
    if (configuration.storages != null && configuration.storages.length > 0)
        for (OServerStorageConfiguration s : configuration.storages) storages.put(OIOUtils.getDatabaseNameFromPath(s.name), s.path);
    // SEARCH IN DEFAULT DATABASE DIRECTORY
    final String rootDirectory = getDatabaseDirectory();
    scanDatabaseDirectory(new File(rootDirectory), storages);
    for (OStorage storage : Orient.instance().getStorages()) {
        final String storageUrl = storage.getURL();
        // TEST IT'S OF CURRENT SERVER INSTANCE BY CHECKING THE PATH
        if (storage instanceof OAbstractPaginatedStorage && storage.exists() && !storages.containsValue(storageUrl) && isStorageOfCurrentServerInstance(storage))
            storages.put(OIOUtils.getDatabaseNameFromPath(storage.getName()), storageUrl);
    }
    if (storages != null)
        storages.remove(OSystemDatabase.SYSTEM_DB_NAME);
    return storages;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) OStorage(com.orientechnologies.orient.core.storage.OStorage) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) File(java.io.File)

Example 35 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class OServer method getStoragePath.

public String getStoragePath(final String iName) {
    if (iName == null)
        throw new IllegalArgumentException("Storage path is null");
    final String name = iName.indexOf(':') > -1 ? iName.substring(iName.indexOf(':') + 1) : iName;
    final String dbName = Orient.isRegisterDatabaseByPath() ? getDatabaseDirectory() + name : name;
    final String dbPath = Orient.isRegisterDatabaseByPath() ? dbName : getDatabaseDirectory() + name;
    if (dbPath.contains(".."))
        throw new IllegalArgumentException("Storage path is invalid because it contains '..'");
    if (dbPath.contains("*"))
        throw new IllegalArgumentException("Storage path is invalid because of the wildcard '*'");
    if (dbPath.startsWith("/")) {
        if (!dbPath.startsWith(getDatabaseDirectory()))
            throw new IllegalArgumentException("Storage path is invalid because it points to an absolute directory");
    }
    final OStorage stg = Orient.instance().getStorage(dbName);
    if (stg != null)
        // ALREADY OPEN
        return stg.getURL();
    // SEARCH IN CONFIGURED PATHS
    final OServerConfiguration configuration = serverCfg.getConfiguration();
    String dbURL = configuration.getStoragePath(name);
    if (dbURL == null) {
        // SEARCH IN DEFAULT DATABASE DIRECTORY
        if (new File(OIOUtils.getPathFromDatabaseName(dbPath) + "/database.ocf").exists())
            dbURL = "plocal:" + dbPath;
        else
            throw new OConfigurationException("Database '" + name + "' is not configured on server (home=" + getDatabaseDirectory() + ")");
    }
    return dbURL;
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OStorage(com.orientechnologies.orient.core.storage.OStorage) File(java.io.File)

Aggregations

OStorage (com.orientechnologies.orient.core.storage.OStorage)90 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)31 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)23 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)22 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)21 ORecordId (com.orientechnologies.orient.core.id.ORecordId)20 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)18 OPhysicalPosition (com.orientechnologies.orient.core.storage.OPhysicalPosition)12 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)11 File (java.io.File)11 ORID (com.orientechnologies.orient.core.id.ORID)10 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)7 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)7 Test (org.testng.annotations.Test)7 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)6 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)5 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5