diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLSelect.java b/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLSelect.java index 40957d7f20e..2912a84349e 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLSelect.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLSelect.java @@ -73,6 +73,7 @@ import com.orientechnologies.orient.core.sql.operator.OQueryOperatorOr; import com.orientechnologies.orient.core.sql.query.OSQLQuery; import com.orientechnologies.orient.core.storage.OStorage; +import com.orientechnologies.orient.core.storage.OStorageEmbedded; /** * Executes the SQL SELECT statement. the parse() method compiles the query and builds the meta information needed by the execute(). @@ -361,8 +362,9 @@ protected boolean executeSearchRecord(final OIdentifiable id) { final OStorage.LOCKING_STRATEGY lockingStrategy = context.getVariable("$locking") != null ? (OStorage.LOCKING_STRATEGY) context .getVariable("$locking") : OStorage.LOCKING_STRATEGY.DEFAULT; - - final ORecordInternal record = id instanceof ORecordInternal ? (ORecordInternal) id : getDatabase().load( + ORecordInternal record = null; + try{ + record = id instanceof ORecordInternal ? (ORecordInternal) id : getDatabase().load( id.getIdentity(), null, false, false, lockingStrategy); context.updateMetric("recordReads", +1); @@ -377,7 +379,16 @@ protected boolean executeSearchRecord(final OIdentifiable id) { if (!handleResult(record, true)) // END OF EXECUTION return false; - + }finally{ + // lock must be released (no matter if filtered or not) + if (lockingStrategy==OStorage.LOCKING_STRATEGY.KEEP_EXCLUSIVE_LOCK) + { + if (record!=null) + { + ((OStorageEmbedded) getDatabase().getStorage()).releaseWriteLock(record.getIdentity()); + } + } + } return true; } @@ -878,7 +889,7 @@ protected int parseProjections() { return -1; int upperBound = OStringSerializerHelper.getLowerIndexOf(parserTextUpperCase, parserGetCurrentPosition(), KEYWORD_FROM_2FIND, - KEYWORD_LET_2FIND); + KEYWORD_LET_2FIND); if (upperBound == -1) // UP TO THE END upperBound = parserText.length(); diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLUpdate.java b/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLUpdate.java index 674e6ca3d24..1c61fa2859d 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLUpdate.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLUpdate.java @@ -423,8 +423,6 @@ else if (v instanceof OCommandRequest) return true; } finally { - if (lockStrategy.equalsIgnoreCase("RECORD")) - ((OStorageEmbedded) getDatabase().getStorage()).releaseWriteLock(record.getIdentity()); } } diff --git a/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OLocalPaginatedStorage.java b/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OLocalPaginatedStorage.java index 6af66317cd3..f360b569cdb 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OLocalPaginatedStorage.java +++ b/core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OLocalPaginatedStorage.java @@ -1248,9 +1248,11 @@ protected ORawBuffer readRecord(final OCluster clusterSegment, final ORecordId r case DEFAULT: lockManager.releaseLock(Thread.currentThread(), rid, OLockManager.LOCK.SHARED); break; + case KEEP_EXCLUSIVE_LOCK: + // DO NOTHING - THIS EXCLUSIVE LOCK IS RELEASED LATER IN UPPER CALLERs + break; case NONE: case KEEP_SHARED_LOCK: - case KEEP_EXCLUSIVE_LOCK: // DO NOTHING break; }