You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by yz...@apache.org on 2017/05/11 22:06:20 UTC
ignite git commit: Removed condition, simplified logic
Repository: ignite
Updated Branches:
refs/heads/master 3a9dba5f8 -> 7ea5830a5
Removed condition, simplified logic
http://ci.ignite.apache.org/viewLog.html?buildId=606030&tab=buildResultsDiv&buildTypeId=IgniteTests_IgniteDataStrucutures
http://ci.ignite.apache.org/viewLog.html?buildId=606029&tab=buildResultsDiv&buildTypeId=IgniteTests_IgniteBinaryObjectsDataStrucutures
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7ea5830a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7ea5830a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7ea5830a
Branch: refs/heads/master
Commit: 7ea5830a5f28bb52db3efa6955f505e731e87f90
Parents: 3a9dba5
Author: Yakov Zhdanov <yz...@gridgain.com>
Authored: Fri May 12 01:06:05 2017 +0300
Committer: Yakov Zhdanov <yz...@gridgain.com>
Committed: Fri May 12 01:06:05 2017 +0300
----------------------------------------------------------------------
.../GridCacheAtomicSequenceImpl.java | 101 ++++---------------
1 file changed, 21 insertions(+), 80 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/7ea5830a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java
index d14bb47..5a87e4a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java
@@ -24,8 +24,6 @@ import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.ObjectStreamException;
import java.util.concurrent.Callable;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.ignite.IgniteCheckedException;
@@ -44,8 +42,6 @@ import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupp
import org.apache.ignite.lang.IgniteBiTuple;
import org.jetbrains.annotations.Nullable;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static org.apache.ignite.internal.util.typedef.internal.CU.retryTopologySafe;
import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
@@ -87,7 +83,7 @@ public final class GridCacheAtomicSequenceImpl implements GridCacheAtomicSequenc
/** Local value of sequence. */
@GridToStringInclude(sensitive = true)
- private long locVal;
+ private volatile long locVal;
/** Upper bound of local counter. */
private long upBound;
@@ -98,18 +94,12 @@ public final class GridCacheAtomicSequenceImpl implements GridCacheAtomicSequenc
/** Synchronization lock. */
private final Lock lock = new ReentrantLock();
- /** Await condition. */
- private Condition cond = lock.newCondition();
-
/** Callable for execution {@link #incrementAndGet} operation in async and sync mode. */
private final Callable<Long> incAndGetCall = internalUpdate(1, true);
/** Callable for execution {@link #getAndIncrement} operation in async and sync mode. */
private final Callable<Long> getAndIncCall = internalUpdate(1, false);
- /** Add and get cache call guard. */
- private final AtomicBoolean updateGuard = new AtomicBoolean();
-
/**
* Empty constructor required by {@link Externalizable}.
*/
@@ -161,14 +151,7 @@ public final class GridCacheAtomicSequenceImpl implements GridCacheAtomicSequenc
@Override public long get() {
checkRemoved();
- lock.lock();
-
- try {
- return locVal;
- }
- finally {
- lock.unlock();
- }
+ return locVal;
}
/** {@inheritDoc} */
@@ -235,70 +218,30 @@ public final class GridCacheAtomicSequenceImpl implements GridCacheAtomicSequenc
try {
// If reserved range isn't exhausted.
- if (locVal + l <= upBound) {
- long curVal = locVal;
+ long locVal0 = locVal;
- locVal += l;
+ if (locVal0 + l <= upBound) {
+ locVal = locVal0 + l;
- return updated ? locVal : curVal;
+ return updated ? locVal0 + l : locVal0;
}
- }
- finally {
- lock.unlock();
- }
-
- if (updateCall == null)
- updateCall = internalUpdate(l, updated);
-
- while (true) {
- if (updateGuard.compareAndSet(false, true)) {
- try {
- try {
- return retryTopologySafe(updateCall);
- }
- catch (IgniteCheckedException | IgniteException | IllegalStateException e) {
- throw e;
- }
- catch (Exception e) {
- throw new IgniteCheckedException(e);
- }
- }
- finally {
- lock.lock();
- try {
- updateGuard.set(false);
+ if (updateCall == null)
+ updateCall = internalUpdate(l, updated);
- cond.signalAll();
- }
- finally {
- lock.unlock();
- }
- }
+ try {
+ return updateCall.call();
}
- else {
- lock.lock();
-
- try {
- while (locVal >= upBound && updateGuard.get())
- U.await(cond, 500, MILLISECONDS);
-
- checkRemoved();
-
- // If reserved range isn't exhausted.
- if (locVal + l <= upBound) {
- long curVal = locVal;
-
- locVal += l;
-
- return updated ? locVal : curVal;
- }
- }
- finally {
- lock.unlock();
- }
+ catch (IgniteCheckedException | IgniteException | IllegalStateException e) {
+ throw e;
+ }
+ catch (Exception e) {
+ throw new IgniteCheckedException(e);
}
}
+ finally {
+ lock.unlock();
+ }
}
/** Get local batch size for this sequences.
@@ -422,12 +365,10 @@ public final class GridCacheAtomicSequenceImpl implements GridCacheAtomicSequenc
curLocVal = locVal;
// If local range was already reserved in another thread.
- if (locVal + l <= upBound) {
- long retVal = locVal;
-
- locVal += l;
+ if (curLocVal + l <= upBound) {
+ locVal = curLocVal + l;
- return updated ? locVal : retVal;
+ return updated ? curLocVal + l : curLocVal;
}
long curGlobalVal = seq.get();