Search in sources :

Example 1 with OWriteCache

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

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

the class OIndexAbstract method removeValuesContainer.

private void removeValuesContainer() {
    if (valueContainerAlgorithm.equals(ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER)) {
        final OAtomicOperation atomicOperation = storage.getAtomicOperationsManager().getCurrentOperation();
        final OReadCache readCache = storage.getReadCache();
        final OWriteCache writeCache = storage.getWriteCache();
        if (atomicOperation == null) {
            try {
                final String fileName = getName() + OIndexRIDContainer.INDEX_FILE_EXTENSION;
                if (writeCache.exists(fileName)) {
                    final long fileId = writeCache.loadFile(fileName);
                    readCache.deleteFile(fileId, writeCache);
                }
            } catch (IOException e) {
                OLogManager.instance().error(this, "Cannot delete file for value containers", e);
            }
        } else {
            try {
                final String fileName = getName() + OIndexRIDContainer.INDEX_FILE_EXTENSION;
                if (atomicOperation.isFileExists(fileName)) {
                    final long fileId = atomicOperation.loadFile(fileName);
                    atomicOperation.deleteFile(fileId);
                }
            } catch (IOException e) {
                OLogManager.instance().error(this, "Cannot delete file for value containers", 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)

Example 3 with OWriteCache

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

the class OPerformanceStatisticManager method getWowCache.

/**
   * @return Returns current instance of write cache and initializes local reference if such one is not initialized yet.
   */
private OWOWCache getWowCache() {
    if (wowCacheInitialized)
        return wowCache;
    final OWriteCache writeCache = storage.getWriteCache();
    if (writeCache instanceof OWOWCache)
        this.wowCache = (OWOWCache) writeCache;
    else
        this.wowCache = null;
    wowCacheInitialized = true;
    return this.wowCache;
}
Also used : OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OWOWCache(com.orientechnologies.orient.core.storage.cache.local.OWOWCache)

Example 4 with OWriteCache

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

the class ClassTest method testRename.

@Test
public void testRename() {
    OSchema schema = db.getMetadata().getSchema();
    OClass oClass = schema.createClass("ClassName");
    final OStorage storage = db.getStorage();
    final OAbstractPaginatedStorage paginatedStorage = (OAbstractPaginatedStorage) storage;
    final OWriteCache writeCache = paginatedStorage.getWriteCache();
    Assert.assertTrue(writeCache.exists("classname" + OPaginatedCluster.DEF_EXTENSION));
    oClass.setName("ClassNameNew");
    Assert.assertTrue(!writeCache.exists("classname" + OPaginatedCluster.DEF_EXTENSION));
    Assert.assertTrue(writeCache.exists("classnamenew" + OPaginatedCluster.DEF_EXTENSION));
    oClass.setName("ClassName");
    Assert.assertTrue(!writeCache.exists("classnamenew" + OPaginatedCluster.DEF_EXTENSION));
    Assert.assertTrue(writeCache.exists("classname" + OPaginatedCluster.DEF_EXTENSION));
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OStorage(com.orientechnologies.orient.core.storage.OStorage) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) Test(org.testng.annotations.Test)

Example 5 with OWriteCache

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

the class ClassTest method testShortName.

@Test
public void testShortName() {
    OSchema schema = db.getMetadata().getSchema();
    OClass oClass = schema.createClass(SHORTNAME_CLASS_NAME);
    Assert.assertNull(oClass.getShortName());
    Assert.assertNull(queryShortName());
    final OStorage storage = db.getStorage();
    if (storage instanceof OAbstractPaginatedStorage) {
        final OAbstractPaginatedStorage paginatedStorage = (OAbstractPaginatedStorage) storage;
        final OWriteCache writeCache = paginatedStorage.getWriteCache();
        Assert.assertTrue(writeCache.exists(SHORTNAME_CLASS_NAME.toLowerCase() + OPaginatedCluster.DEF_EXTENSION));
    }
    String shortName = "shortname";
    oClass.setShortName(shortName);
    Assert.assertEquals(shortName, oClass.getShortName());
    Assert.assertEquals(shortName, queryShortName());
    // FAILS, saves null value and stores "null" string (not null value) internally
    shortName = "null";
    oClass.setShortName(shortName);
    Assert.assertEquals(shortName, oClass.getShortName());
    Assert.assertEquals(shortName, queryShortName());
    oClass.setShortName(null);
    Assert.assertNull(oClass.getShortName());
    Assert.assertNull(queryShortName());
    oClass.setShortName("");
    Assert.assertNull(oClass.getShortName());
    Assert.assertNull(queryShortName());
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OStorage(com.orientechnologies.orient.core.storage.OStorage) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) Test(org.testng.annotations.Test)

Aggregations

OWriteCache (com.orientechnologies.orient.core.storage.cache.OWriteCache)9 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)7 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OReadCache (com.orientechnologies.orient.core.storage.cache.OReadCache)3 Test (org.testng.annotations.Test)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)2 IOException (java.io.IOException)2 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)1 OWOWCache (com.orientechnologies.orient.core.storage.cache.local.OWOWCache)1 ODurablePage (com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage)1 ArrayList (java.util.ArrayList)1