Skip to content

Commit

Permalink
Issue #9156 has been fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii0lomakin committed Feb 28, 2020
1 parent fe12748 commit 4bfa857
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ public static OAtomicOperation getCurrentOperation() {

private void startComponentOperation(final OAtomicOperation atomicOperation, final String lockName) {
checkReadOnlyConditions(atomicOperation);
componentOperationsFreezer.startOperation();
acquireExclusiveLockTillOperationComplete(atomicOperation, lockName);

componentOperationsFreezer.startOperation();
}

private void endComponentOperation() {
Expand All @@ -280,14 +281,13 @@ public void releaseComponentOperations(final long freezeId) {

private boolean tryStartComponentOperation(final OAtomicOperation atomicOperation, final String lockName) {
checkReadOnlyConditions(atomicOperation);
componentOperationsFreezer.startOperation();

final boolean result = tryAcquireExclusiveLockTillOperationComplete(atomicOperation, lockName);
if (!result) {
componentOperationsFreezer.endOperation();
return false;
}

componentOperationsFreezer.startOperation();

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.types.OModifiableInteger;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -23,32 +24,48 @@ public final class OperationsFreezer {
private final AtomicLong freezeIdGen = new AtomicLong();
private final ConcurrentMap<Long, FreezeParameters> freezeParametersIdMap = new ConcurrentHashMap<>();

private final ThreadLocal<OModifiableInteger> operationDepth = ThreadLocal.withInitial(OModifiableInteger::new);

public void startOperation() {
operationsCount.increment();
final OModifiableInteger operationDepth = this.operationDepth.get();
if (operationDepth.value == 0) {
operationsCount.increment();

while (freezeRequests.get() > 0) {
assert freezeRequests.get() >= 0;
while (freezeRequests.get() > 0) {
assert freezeRequests.get() >= 0;

operationsCount.decrement();
operationsCount.decrement();

throwFreezeExceptionIfNeeded();
throwFreezeExceptionIfNeeded();

final Thread thread = Thread.currentThread();
final Thread thread = Thread.currentThread();

operationsWaitingList.addThreadInWaitingList(thread);
operationsWaitingList.addThreadInWaitingList(thread);

if (freezeRequests.get() > 0) {
LockSupport.park(this);
}
if (freezeRequests.get() > 0) {
LockSupport.park(this);
}

operationsCount.increment();
operationsCount.increment();
}
}

assert freezeRequests.get() >= 0;

operationDepth.increment();
}

public void endOperation() {
operationsCount.decrement();
final OModifiableInteger operationDepth = this.operationDepth.get();
if (operationDepth.value <= 0) {
throw new IllegalStateException("Invalid operation depth " + operationDepth.value);
} else {
operationDepth.value--;
}

if (operationDepth.value == 0) {
operationsCount.decrement();
}
}

public long freezeOperations(final Class<? extends OException> exceptionClass, final String message) {
Expand Down

0 comments on commit 4bfa857

Please sign in to comment.