Skip to content

Commit

Permalink
Merge branch 'newlocks' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Feb 2, 2014
2 parents 673bb3a + 07854f5 commit 418a949
Show file tree
Hide file tree
Showing 44 changed files with 888 additions and 561 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ public ORecordMetadata getRecordMetadata(final ORID rid) {
} while (true);
}

public OStorageOperationResult<ORawBuffer> readRecord(final ORecordId iRid, final String iFetchPlan, final boolean iIgnoreCache,
final ORecordCallback<ORawBuffer> iCallback, boolean loadTombstones) {
public OStorageOperationResult<ORawBuffer> readRecord(final ORecordId iRid, final String iFetchPlan, final boolean iIgnoreCache, final ORecordCallback<ORawBuffer> iCallback, boolean loadTombstones, LOCKING_STRATEGY iLockingStrategy) {
checkConnection();

if (OStorageRemoteThreadLocal.INSTANCE.get().commandExecuting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,10 @@ public OStorageOperationResult<OPhysicalPosition> createRecord(final int iDataSe
}
}

public OStorageOperationResult<ORawBuffer> readRecord(final ORecordId iRid, final String iFetchPlan, boolean iIgnoreCache,
ORecordCallback<ORawBuffer> iCallback, boolean loadTombstones) {
public OStorageOperationResult<ORawBuffer> readRecord(final ORecordId iRid, final String iFetchPlan, boolean iIgnoreCache, ORecordCallback<ORawBuffer> iCallback, boolean loadTombstones, LOCKING_STRATEGY iLockingStrategy) {
pushSession();
try {
return delegate.readRecord(iRid, iFetchPlan, iIgnoreCache, null, loadTombstones);
return delegate.readRecord(iRid, iFetchPlan, iIgnoreCache, null, loadTombstones, LOCKING_STRATEGY.DEFAULT);
} finally {
popSession();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,32 @@ public void releaseLock(final REQUESTER_TYPE iRequester, final RESOURCE_TYPE iRe
lock.readLock().unlock();
else
lock.writeLock().unlock();
}

public void modifyLock(final REQUESTER_TYPE iRequester, final RESOURCE_TYPE iResourceId, final LOCK iCurrentLockType,
final LOCK iNewLockType) throws OLockException {
if (!enabled || iNewLockType == iCurrentLockType)
return;

final CountableLock lock;
final Object internalLock = internalLock(iResourceId);
synchronized (internalLock) {
lock = map.get(iResourceId);
if (lock == null)
throw new OLockException("Error on releasing a non acquired lock by the requester '" + iRequester
+ "' against the resource: '" + iResourceId + "'");

if (iCurrentLockType == LOCK.SHARED)
lock.readLock().unlock();
else
lock.writeLock().unlock();

// RE-ACQUIRE IT
if (iNewLockType == LOCK.SHARED)
lock.readLock().lock();
else
lock.writeLock().lock();
}
}

public void clear() {
Expand All @@ -195,6 +220,9 @@ public int getCountCurrentLocks() {
return map.size();
}

public void releaseAllLocksOfRequester(REQUESTER_TYPE iRequester) {
}

protected RESOURCE_TYPE getImmutableResourceId(final RESOURCE_TYPE iResourceId) {
return iResourceId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/
package com.orientechnologies.orient.core.command;

import java.util.HashMap;
import java.util.Map;

import com.orientechnologies.common.listener.OProgressListener;
import com.orientechnologies.orient.core.command.OCommandContext.TIMEOUT_STRATEGY;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.storage.OStorage;

import java.util.HashMap;
import java.util.Map;

/**
* Text based Command Request abstract class.
Expand All @@ -31,15 +32,16 @@
*/
@SuppressWarnings("serial")
public abstract class OCommandRequestAbstract implements OCommandRequestInternal {
protected OCommandResultListener resultListener;
protected OProgressListener progressListener;
protected int limit = -1;
protected long timeoutMs = OGlobalConfiguration.COMMAND_TIMEOUT.getValueAsLong();
protected TIMEOUT_STRATEGY timeoutStrategy = TIMEOUT_STRATEGY.EXCEPTION;
protected Map<Object, Object> parameters;
protected String fetchPlan = null;
protected boolean useCache = false;
protected OCommandContext context;
protected OCommandResultListener resultListener;
protected OProgressListener progressListener;
protected int limit = -1;
protected long timeoutMs = OGlobalConfiguration.COMMAND_TIMEOUT.getValueAsLong();
protected TIMEOUT_STRATEGY timeoutStrategy = TIMEOUT_STRATEGY.EXCEPTION;
protected OStorage.LOCKING_STRATEGY lockStrategy = OStorage.LOCKING_STRATEGY.NONE;
protected Map<Object, Object> parameters;
protected String fetchPlan = null;
protected boolean useCache = false;
protected OCommandContext context;

protected OCommandRequestAbstract() {
}
Expand Down Expand Up @@ -137,12 +139,20 @@ public long getTimeoutTime() {
return timeoutMs;
}

public void setTimeout(final long timeout, TIMEOUT_STRATEGY strategy) {
public void setTimeout(final long timeout, final TIMEOUT_STRATEGY strategy) {
this.timeoutMs = timeout;
this.timeoutStrategy = strategy;
}

public TIMEOUT_STRATEGY getTimeoutStrategy() {
return timeoutStrategy;
}

public OStorage.LOCKING_STRATEGY getLockingStrategy() {
return lockStrategy;
}

public void setLockStrategy(final OStorage.LOCKING_STRATEGY lockStrategy) {
this.lockStrategy = lockStrategy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public OStorageConfiguration(final OStorage iStorage) {
* @throws OSerializationException
*/
public OStorageConfiguration load() throws OSerializationException {
final byte[] record = storage.readRecord(CONFIG_RID, null, false, null, false).getResult().buffer;
final byte[] record = storage.readRecord(CONFIG_RID, null, false, null, false, OStorage.LOCKING_STRATEGY.DEFAULT).getResult().buffer;

if (record == null)
throw new OStorageException("Cannot load database's configuration. The database seems to be corrupted.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,16 @@ public enum OPERATION_MODE {
/**
* Loads a record using a fetch plan.
*
*
* @param iObject
* Record to load
* @param iFetchPlan
* Fetch plan used
* @param iLockingStrategy
* @return The record received
*/
public <RET extends T> RET load(T iObject, String iFetchPlan, boolean iIgnoreCache, boolean loadTombstone);
public <RET extends T> RET load(T iObject, String iFetchPlan, boolean iIgnoreCache, boolean loadTombstone,
OStorage.LOCKING_STRATEGY iLockingStrategy);

/**
* Loads a record using a fetch plan.
Expand Down Expand Up @@ -172,7 +175,8 @@ public enum OPERATION_MODE {
*/
public <RET extends T> RET load(ORID iRecordId, String iFetchPlan, boolean iIgnoreCache);

public <RET extends T> RET load(ORID iRecordId, String iFetchPlan, boolean iIgnoreCache, boolean loadTombstone);
public <RET extends T> RET load(ORID iRecordId, String iFetchPlan, boolean iIgnoreCache, boolean loadTombstone,
OStorage.LOCKING_STRATEGY iLockingStrategy);

/**
* Saves an entity in synchronous mode. If the entity is not dirty, then the operation will be ignored. For custom entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
*/
package com.orientechnologies.orient.core.db;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;

import com.orientechnologies.orient.core.command.OCommandRequest;
import com.orientechnologies.orient.core.db.record.ODatabaseRecord;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
Expand All @@ -49,6 +41,14 @@
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
import com.orientechnologies.orient.core.version.ORecordVersion;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;

@SuppressWarnings("unchecked")
public abstract class ODatabaseRecordWrapperAbstract<DB extends ODatabaseRecord> extends ODatabaseWrapperAbstract<DB> implements
ODatabaseComplex<ORecordInternal<?>> {
Expand Down Expand Up @@ -226,14 +226,13 @@ public <RET extends ORecordInternal<?>> RET load(final ORID iRecordId, final Str
}

@Override
public <RET extends ORecordInternal<?>> RET load(ORID iRecordId, String iFetchPlan, boolean iIgnoreCache, boolean loadTombstone) {
return (RET) underlying.load(iRecordId, iFetchPlan, iIgnoreCache, loadTombstone);
public <RET extends ORecordInternal<?>> RET load(ORID iRecordId, String iFetchPlan, boolean iIgnoreCache, boolean loadTombstone, OStorage.LOCKING_STRATEGY iLockingStrategy) {
return (RET) underlying.load(iRecordId, iFetchPlan, iIgnoreCache, loadTombstone, OStorage.LOCKING_STRATEGY.DEFAULT);
}

@Override
public <RET extends ORecordInternal<?>> RET load(ORecordInternal<?> iObject, String iFetchPlan, boolean iIgnoreCache,
boolean loadTombstone) {
return (RET) underlying.load(iObject, iFetchPlan, iIgnoreCache, loadTombstone);
public <RET extends ORecordInternal<?>> RET load(ORecordInternal<?> iObject, String iFetchPlan, boolean iIgnoreCache, boolean loadTombstone, OStorage.LOCKING_STRATEGY iLockingStrategy) {
return (RET) underlying.load(iObject, iFetchPlan, iIgnoreCache, loadTombstone, OStorage.LOCKING_STRATEGY.DEFAULT);
}

public <RET extends ORecordInternal<?>> RET getRecord(final OIdentifiable iIdentifiable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.orientechnologies.orient.core.db.document;

import java.util.*;

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.Orient;
Expand All @@ -39,9 +37,17 @@
import com.orientechnologies.orient.core.record.ORecordInternal;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.storage.ORecordCallback;
import com.orientechnologies.orient.core.storage.OStorage;
import com.orientechnologies.orient.core.storage.impl.local.OFreezableStorage;
import com.orientechnologies.orient.core.version.ORecordVersion;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

@SuppressWarnings("unchecked")
public class ODatabaseDocumentTx extends ODatabaseRecordWrapperAbstract<ODatabaseRecordTx> implements ODatabaseDocument {
public ODatabaseDocumentTx(final String iURL) {
Expand Down Expand Up @@ -198,7 +204,7 @@ public ORecordIteratorCluster<ODocument> browseCluster(String iClusterName, OClu
checkSecurity(ODatabaseSecurityResources.CLUSTER, ORole.PERMISSION_READ, iClusterName);

return new ORecordIteratorCluster<ODocument>(this, underlying, getClusterIdByName(iClusterName), startClusterPosition,
endClusterPosition, true, loadTombstones);
endClusterPosition, true, loadTombstones, OStorage.LOCKING_STRATEGY.DEFAULT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.orientechnologies.orient.core.db.record.ODatabaseRecordTx;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.iterator.ORecordIteratorClass;
import com.orientechnologies.orient.core.metadata.schema.OClass;
Expand Down Expand Up @@ -149,7 +148,8 @@ public Iterable<ODocument> browseEdges(final boolean iPolymorphic) {
}

public Iterable<ODocument> browseElements(final String iClass, final boolean iPolymorphic) {
return new ORecordIteratorClass<ODocument>(this, (ODatabaseRecordAbstract) getUnderlying(), iClass, iPolymorphic, true, false);
return new ORecordIteratorClass<ODocument>(this, (ODatabaseRecordAbstract) getUnderlying(), iClass, iPolymorphic, true, false,
OStorage.LOCKING_STRATEGY.DEFAULT);
}

public ODocument createVertex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@

package com.orientechnologies.orient.core.db.raw;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
import java.util.concurrent.Callable;

import com.orientechnologies.common.concur.lock.ONoLock;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.listener.OListenerManger;
Expand Down Expand Up @@ -66,6 +50,13 @@
import com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage;
import com.orientechnologies.orient.core.version.ORecordVersion;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.Callable;

/**
* Lower level ODatabase implementation. It's extended or wrapped by all the others.
*
Expand Down Expand Up @@ -234,14 +225,14 @@ public long countClusterElements(int[] iClusterIds, boolean countTombstones) {
}

public OStorageOperationResult<ORawBuffer> read(final ORecordId iRid, final String iFetchPlan, final boolean iIgnoreCache,
boolean loadTombstones) {
final boolean loadTombstones, final OStorage.LOCKING_STRATEGY iLockingStrategy) {
if (!iRid.isValid())
return new OStorageOperationResult<ORawBuffer>(null);

OFetchHelper.checkFetchPlanValid(iFetchPlan);

try {
return storage.readRecord(iRid, iFetchPlan, iIgnoreCache, null, loadTombstones);
return storage.readRecord(iRid, iFetchPlan, iIgnoreCache, null, loadTombstones, iLockingStrategy);

} catch (Throwable t) {
if (iRid.isTemporary())
Expand Down
Loading

0 comments on commit 418a949

Please sign in to comment.