Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF
/** Lock wait timeout. */
private final long waitTimeout;

/** Time when the first primary batch starts, or zero before mapping. */
private long lockWaitStartTime;

/** Transaction. */
@GridToStringExclude
private final GridNearTxLocal tx;
Expand Down Expand Up @@ -805,7 +808,7 @@ void map() {
if (isDone()) // Possible due to async rollback.
return;

if (lockTimeout() > 0) {
if (timeout > 0) {
timeoutObj = new LockTimeoutObject();

cctx.time().addTimeoutObject(timeoutObj);
Expand Down Expand Up @@ -1124,7 +1127,6 @@ private synchronized void map0(
isolation(),
isInvalidate(),
timeout,
waitTimeout,
mappedKeys.size(),
inTx() ? tx.size() : mappedKeys.size(),
inTx() && tx.syncMode() == FULL_SYNC,
Expand Down Expand Up @@ -1250,9 +1252,24 @@ private void proceedMapping0()
final Collection<KeyCacheObject> mappedKeys = map.distributedKeys();
final ClusterNode node = map.node();

long remainingWaitTimeout = waitTimeout;

if (waitTimeout > 0) {
long now = U.currentTimeMillis();

if (lockWaitStartTime == 0)
lockWaitStartTime = now;

long elapsed = now - lockWaitStartTime;

remainingWaitTimeout = elapsed < waitTimeout ? waitTimeout - elapsed : -1;
}

if (node.isLocal())
lockLocally(mappedKeys, req.topologyVersion());
lockLocally(mappedKeys, req.topologyVersion(), remainingWaitTimeout);
else {
req.waitTimeout(remainingWaitTimeout);

final MiniFuture fut = new MiniFuture(node, mappedKeys, ++miniId);

req.miniId(fut.futureId());
Expand Down Expand Up @@ -1280,10 +1297,12 @@ private void proceedMapping0()
* Locks given keys directly through dht cache.
* @param keys Collection of keys.
* @param topVer Topology version to lock on.
* @param remainingWaitTimeout Remaining lock wait budget for this batch.
*/
private void lockLocally(
final Collection<KeyCacheObject> keys,
AffinityTopologyVersion topVer
AffinityTopologyVersion topVer,
long remainingWaitTimeout
) {
if (log.isDebugEnabled())
log.debug("Before locally locking keys : " + keys);
Expand All @@ -1297,7 +1316,7 @@ private void lockLocally(
read,
retval,
timeout,
waitTimeout,
remainingWaitTimeout,
createTtl,
accessTtl,
skipStore,
Expand Down Expand Up @@ -1418,7 +1437,7 @@ private boolean mapAsPrimary(Collection<KeyCacheObject> keys, AffinityTopologyVe
tx.addKeyMapping(cctx.txKey(key), cctx.localNode());
}

lockLocally(distributedKeys, topVer);
lockLocally(distributedKeys, topVer, waitTimeout);
}

GridDhtPartitionsExchangeFuture lastFinishedFut = cctx.shared().exchange().lastFinishedFuture();
Expand Down Expand Up @@ -1525,13 +1544,6 @@ private boolean errorOrTimeoutOnTopologyVersion(IgniteCheckedException e, boolea
return false;
}

/**
* @return Timeout value for this lock future.
*/
private long lockTimeout() {
return CU.isWaitTimeoutExpiresFirst(waitTimeout, timeout) ? waitTimeout : timeout;
}

/**
* Lock request timeout object.
*/
Expand All @@ -1540,7 +1552,7 @@ private class LockTimeoutObject extends GridTimeoutObjectAdapter {
* Default constructor.
*/
LockTimeoutObject() {
super(lockTimeout());
super(timeout);
}

/** Requested keys. */
Expand All @@ -1551,20 +1563,6 @@ private class LockTimeoutObject extends GridTimeoutObjectAdapter {
if (log.isDebugEnabled())
log.debug("Timed out waiting for lock response: " + this);

if (CU.isWaitTimeoutExpiresFirst(waitTimeout, timeout)) {
synchronized (GridDhtColocatedLockFuture.this) {
requestedKeys = requestedKeys0();

clear(); // Stop response processing.
}

synchronized (this) {
onComplete(false, true, false);
}

return;
}

if (inTx()) {
if (cctx.tm().deadlockDetectionEnabled()) {
synchronized (GridDhtColocatedLockFuture.this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture<Bo
/** Lock wait timeout. */
private final long waitTimeout;

/** Time when the first primary batch starts, or zero before mapping. */
private long lockWaitStartTime;

/** Transaction. */
@GridToStringExclude
private final GridNearTxLocal tx;
Expand Down Expand Up @@ -356,7 +359,7 @@ private boolean locked(GridCacheEntryEx cached) throws GridCacheEntryRemovedExce
threadId,
lockVer,
topVer,
lockTimeout(),
timeout,
!inTx(),
inTx(),
implicitSingleTx(),
Expand All @@ -371,16 +374,11 @@ private boolean locked(GridCacheEntryEx cached) throws GridCacheEntryRemovedExce

entries.add(entry);

if (c == null && lockTimeout() < 0) {
if (c == null && timeout < 0) {
if (log.isDebugEnabled())
log.debug("Failed to acquire lock with negative timeout: " + entry);

if (CU.isWaitTimeoutExpiresFirst(waitTimeout, timeout)) {
onComplete(false, true, false);
}
else {
onFailed();
}
onFailed();

return null;
}
Expand Down Expand Up @@ -817,7 +815,7 @@ void map() {
if (isDone()) // Possible due to async rollback.
return;

if (lockTimeout() > 0) {
if (timeout > 0) {
timeoutObj = new LockTimeoutObject();

cctx.time().addTimeoutObject(timeoutObj);
Expand Down Expand Up @@ -1088,7 +1086,6 @@ private void map(Iterable<KeyCacheObject> keys, boolean remap, boolean topLocked
isolation(),
isInvalidate(),
timeout,
waitTimeout,
mappedKeys.size(),
inTx() ? tx.size() : mappedKeys.size(),
inTx() && tx.syncMode() == FULL_SYNC,
Expand Down Expand Up @@ -1206,6 +1203,21 @@ private void proceedMapping0()
final Collection<KeyCacheObject> mappedKeys = map.distributedKeys();
final ClusterNode node = map.node();

long remainingWaitTimeout = waitTimeout;

if (waitTimeout > 0) {
long now = U.currentTimeMillis();

if (lockWaitStartTime == 0)
lockWaitStartTime = now;

long elapsed = now - lockWaitStartTime;

remainingWaitTimeout = elapsed < waitTimeout ? waitTimeout - elapsed : -1;
}

req.waitTimeout(remainingWaitTimeout);

if (node.isLocal()) {
req.miniId(-1);

Expand Down Expand Up @@ -1420,13 +1432,6 @@ private ClusterTopologyCheckedException newTopologyException(@Nullable Throwable
return topEx;
}

/**
* @return Timeout value for this lock future.
*/
private long lockTimeout() {
return CU.isWaitTimeoutExpiresFirst(waitTimeout, timeout) ? waitTimeout : timeout;
}

/**
* Lock request timeout object.
*/
Expand All @@ -1435,7 +1440,7 @@ private class LockTimeoutObject extends GridTimeoutObjectAdapter {
* Default constructor.
*/
LockTimeoutObject() {
super(lockTimeout());
super(timeout);
}

/** Requested keys. */
Expand All @@ -1448,20 +1453,6 @@ private class LockTimeoutObject extends GridTimeoutObjectAdapter {

timedOut = true;

if (CU.isWaitTimeoutExpiresFirst(waitTimeout, timeout)) {
synchronized (GridNearLockFuture.this) {
requestedKeys = requestedKeys0();

clear(); // Stop response processing.
}

synchronized (this) {
onComplete(false, true, false);
}

return;
}

txLockTimedOut = true;

if (inTx()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public GridNearLockRequest() {
* @param isolation Transaction isolation.
* @param isInvalidate Invalidation flag.
* @param timeout Transaction timeout.
* @param waitTimeout Lock wait timeout.
* @param keyCnt Number of keys.
* @param txSize Expected transaction size.
* @param syncCommit Synchronous commit flag.
Expand All @@ -128,7 +127,6 @@ public GridNearLockRequest(
TransactionIsolation isolation,
boolean isInvalidate,
long timeout,
long waitTimeout,
int keyCnt,
int txSize,
boolean syncCommit,
Expand Down Expand Up @@ -168,7 +166,6 @@ public GridNearLockRequest(
this.taskNameHash = taskNameHash;
this.createTtl = createTtl;
this.accessTtl = accessTtl;
this.waitTimeout = waitTimeout;

this.txLbl = txLbl;

Expand Down Expand Up @@ -221,6 +218,13 @@ public long waitTimeout() {
return waitTimeout;
}

/**
* @param timeout Remaining lock wait budget for this primary batch.
*/
public void waitTimeout(long timeout) {
waitTimeout = timeout;
}

/**
* @return Topology version.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ private <K, V> IgniteInternalFuture putAsync0(

IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted,
timeout,
timeout,
/*waitTimeout*/0,
this,
/*read*/entryProc != null, // Needed to force load from store.
retval,
Expand Down Expand Up @@ -822,7 +822,7 @@ private <K, V> IgniteInternalFuture putAllAsync0(

IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted,
timeout,
timeout,
/*waitTimeout*/0,
this,
/*read*/invokeVals != null, // Needed to force load from store.
retval,
Expand Down Expand Up @@ -1725,7 +1725,7 @@ private <K, V> IgniteInternalFuture<GridCacheReturn> removeAllAsync0(

IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted,
timeout,
timeout,
/*waitTimeout*/0,
this,
false,
retval,
Expand Down Expand Up @@ -1918,7 +1918,7 @@ public <K, V> IgniteInternalFuture<Map<K, V>> getAllAsync(

IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(lockKeys,
timeout,
timeout,
/*waitTimeout*/0,
this,
true,
true,
Expand Down
Loading
Loading