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);
}
}
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);
}
}
}
}
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;
}
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));
}
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());
}
Aggregations