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