IGNITE-1678 set default reservation percentage as 100
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2d262705 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2d262705 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2d262705 Branch: refs/heads/ignite-1678 Commit: 2d2627056ca288d95c68934286c0e80e66b4ca4e Parents: 62bc2c9 Author: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com> Authored: Sun Aug 26 21:48:07 2018 +0300 Committer: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com> Committed: Sun Aug 26 21:48:07 2018 +0300 ---------------------------------------------------------------------- .../configuration/AtomicConfiguration.java | 2 +- .../GridCacheAtomicSequenceImpl.java | 24 ++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/2d262705/modules/core/src/main/java/org/apache/ignite/configuration/AtomicConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/AtomicConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/AtomicConfiguration.java index 18dd8d0..34d28fc 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/AtomicConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/AtomicConfiguration.java @@ -38,7 +38,7 @@ public class AtomicConfiguration { public static final int DFLT_ATOMIC_SEQUENCE_RESERVE_SIZE = 1000; /** Default atomic sequence reservation size. */ - public static final int DFLT_ATOMIC_SEQUENCE_RESERVE_PERCENTAGE = 80; + public static final int DFLT_ATOMIC_SEQUENCE_RESERVE_PERCENTAGE = 100; /** Default batch size for all cache's sequences. */ private int seqReserveSize = DFLT_ATOMIC_SEQUENCE_RESERVE_SIZE; http://git-wip-us.apache.org/repos/asf/ignite/blob/2d262705/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 c69d483..295feea 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 @@ -92,6 +92,9 @@ public final class GridCacheAtomicSequenceImpl extends AtomicDataStructureProxy< /** Synchronization lock for local value updates. */ private final Lock localUpdateLock = new ReentrantLock(); + /** */ + private final Callable<Void> reserveCallableWithZeroOffset = reserveCallable(0); + /** * Empty constructor required by {@link Externalizable}. */ @@ -194,7 +197,6 @@ public final class GridCacheAtomicSequenceImpl extends AtomicDataStructureProxy< * @return Sequence value. * @throws IgniteCheckedException If update failed. */ - @SuppressWarnings("SignalWithoutCorrespondingAwait") private long internalUpdate(long l, boolean updated) throws IgniteCheckedException { assert l > 0; @@ -203,16 +205,18 @@ public final class GridCacheAtomicSequenceImpl extends AtomicDataStructureProxy< localUpdateLock.lock(); - IgniteInternalFuture<?> reservation = reservationFut; - try { + IgniteInternalFuture<?> reservation = reservationFut; + boolean reservationInProgress = reservation != null; long newLocalVal = locVal + l; // Reserve new interval if operation is not in progress. - if (newLocalVal >= newReservationLine && newLocalVal <= reservedUpBound && !reservationInProgress){ - reservationFut = runAsyncReservation(0); + if (newLocalVal >= newReservationLine && newLocalVal <= reservedUpBound && !reservationInProgress) { + reservationFut = reservation = runAsyncReservation(0); + + reservationInProgress = true; } long locVal0 = locVal; @@ -338,11 +342,11 @@ public final class GridCacheAtomicSequenceImpl extends AtomicDataStructureProxy< resFut.listen(f -> { if (f.error() == null) - reservationFut = null; + reservationFut = null; // Reset null only if there was not an error. }); ctx.kernalContext().closure().runLocalSafe(() -> { - Callable<Void> reserveCall = reserveCallable(off); + Callable<Void> reserveCall = off == 0 ? reserveCallableWithZeroOffset: reserveCallable(off); try { CU.retryTopologySafe(reserveCall); @@ -375,11 +379,11 @@ public final class GridCacheAtomicSequenceImpl extends AtomicDataStructureProxy< reservedBottomBound = curGlobalVal + off; - reservedUpBound = reservedBottomBound + batchSize; + reservedUpBound = reservedBottomBound + (batchSize > 1 ? batchSize - 1 : 1); newReservationLine = calculateNewReservationLine(reservedBottomBound); - seq.set(reservedUpBound); + seq.set(reservedUpBound + 1); cacheView.put(key, seq); @@ -401,7 +405,7 @@ public final class GridCacheAtomicSequenceImpl extends AtomicDataStructureProxy< * @return New reservation line. */ private long calculateNewReservationLine(long initialValue) { - return initialValue + (batchSize * reservePercentage / 100); + return initialValue + ((batchSize > 1 ? batchSize - 1 : 1) * reservePercentage / 100); } /** {@inheritDoc} */