HHH-11373 Silence lock acquisition failures on remote nodes

This commit is contained in:
Radim Vansa 2017-01-06 18:14:39 +01:00 committed by Galder Zamarreño
parent 1ba6e00e00
commit 69ba7a50ce
2 changed files with 36 additions and 5 deletions

View File

@ -7,8 +7,12 @@
package org.hibernate.cache.infinispan.access; package org.hibernate.cache.infinispan.access;
import org.infinispan.commands.write.DataWriteCommand; import org.infinispan.commands.write.DataWriteCommand;
import org.infinispan.context.Flag;
import org.infinispan.context.InvocationContext; import org.infinispan.context.InvocationContext;
import org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor; import org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor;
import org.infinispan.util.concurrent.TimeoutException;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionException;
@ -27,6 +31,9 @@ import java.util.concurrent.CompletionException;
* {@link CompletableFuture} and we'll wait for it here. * {@link CompletableFuture} and we'll wait for it here.
*/ */
public class LockingInterceptor extends NonTransactionalLockingInterceptor { public class LockingInterceptor extends NonTransactionalLockingInterceptor {
private static final Log log = LogFactory.getLog(LockingInterceptor.class);
private static final boolean trace = log.isTraceEnabled();
@Override @Override
protected Object visitDataWriteCommand(InvocationContext ctx, DataWriteCommand command) throws Throwable { protected Object visitDataWriteCommand(InvocationContext ctx, DataWriteCommand command) throws Throwable {
Object returnValue = null; Object returnValue = null;
@ -39,6 +46,19 @@ public class LockingInterceptor extends NonTransactionalLockingInterceptor {
returnValue = invokeNextInterceptor(ctx, command); returnValue = invokeNextInterceptor(ctx, command);
return returnValue; return returnValue;
} }
catch (TimeoutException e) {
if (!ctx.isOriginLocal() && command.hasFlag(Flag.ZERO_LOCK_ACQUISITION_TIMEOUT)) {
// FAIL_SILENTLY flag is not replicated to remote nodes and zero acquisition timeouts cause
// very noisy logs.
if (trace) {
log.tracef("Silently ignoring exception", e);
}
return null;
}
else {
throw e;
}
}
finally { finally {
lockManager.unlockAll(ctx); lockManager.unlockAll(ctx);
if (returnValue instanceof CompletableFuture) { if (returnValue instanceof CompletableFuture) {

View File

@ -38,17 +38,23 @@ public class ExpectingInterceptor extends BaseCustomInterceptor {
} }
public synchronized Condition when(BiPredicate<InvocationContext, VisitableCommand> predicate) { public synchronized Condition when(BiPredicate<InvocationContext, VisitableCommand> predicate) {
Condition condition = new Condition(predicate, null); Condition condition = new Condition(predicate, source(), null);
conditions.add(condition); conditions.add(condition);
return condition; return condition;
} }
public synchronized Condition whenFails(BiPredicate<InvocationContext, VisitableCommand> predicate) { public synchronized Condition whenFails(BiPredicate<InvocationContext, VisitableCommand> predicate) {
Condition condition = new Condition(predicate, Boolean.FALSE); Condition condition = new Condition(predicate, source(), Boolean.FALSE);
conditions.add(condition); conditions.add(condition);
return condition; return condition;
} }
private static String source() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
StackTraceElement ste = stackTrace[3];
return ste.getFileName() + ":" + ste.getLineNumber();
}
@Override @Override
protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable { protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable {
boolean succeeded = false; boolean succeeded = false;
@ -64,7 +70,9 @@ public class ExpectingInterceptor extends BaseCustomInterceptor {
for (Iterator<Condition> iterator = conditions.iterator(); iterator.hasNext(); ) { for (Iterator<Condition> iterator = conditions.iterator(); iterator.hasNext(); ) {
Condition condition = iterator.next(); Condition condition = iterator.next();
log.tracef("Testing condition %s", condition); log.tracef("Testing condition %s", condition);
if ((condition.success == null || condition.success == succeeded) && condition.predicate.test(ctx, command)) { if (condition.success != null && condition.success != succeeded) {
log.trace("Condition test failed, succeeded: " + succeeded);
} else if (condition.predicate.test(ctx, command)) {
assert condition.action != null; assert condition.action != null;
log.trace("Condition succeeded"); log.trace("Condition succeeded");
toExecute.add(condition.action); toExecute.add(condition.action);
@ -86,12 +94,14 @@ public class ExpectingInterceptor extends BaseCustomInterceptor {
public class Condition { public class Condition {
private final BiPredicate<InvocationContext, VisitableCommand> predicate; private final BiPredicate<InvocationContext, VisitableCommand> predicate;
private final String source;
private final Boolean success; private final Boolean success;
private BooleanSupplier removeCheck; private BooleanSupplier removeCheck;
private Runnable action; private Runnable action;
public Condition(BiPredicate<InvocationContext, VisitableCommand> predicate, Boolean success) { public Condition(BiPredicate<InvocationContext, VisitableCommand> predicate, String source, Boolean success) {
this.predicate = predicate; this.predicate = predicate;
this.source = source;
this.success = success; this.success = success;
} }
@ -120,7 +130,8 @@ public class ExpectingInterceptor extends BaseCustomInterceptor {
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder("Condition{"); final StringBuilder sb = new StringBuilder("Condition{");
sb.append("predicate=").append(predicate); sb.append("source=").append(source);
sb.append(", predicate=").append(predicate);
sb.append(", success=").append(success); sb.append(", success=").append(success);
sb.append(", action=").append(action); sb.append(", action=").append(action);
sb.append('}'); sb.append('}');