mirror of
https://github.com/google/nomulus.git
synced 2025-07-04 18:23:26 +02:00
Swap all uses of Lock to LockHandler
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=167661348
This commit is contained in:
parent
57bcd6b1eb
commit
c3861f6e95
10 changed files with 50 additions and 21 deletions
|
@ -16,6 +16,7 @@ java_library(
|
|||
"//java/google/registry/model",
|
||||
"//java/google/registry/request",
|
||||
"//java/google/registry/request/auth",
|
||||
"//java/google/registry/request/lock",
|
||||
"//java/google/registry/tldconfig/idn",
|
||||
"//java/google/registry/util",
|
||||
"//java/google/registry/xjc",
|
||||
|
|
|
@ -20,11 +20,11 @@ import com.googlecode.objectify.VoidWork;
|
|||
import google.registry.model.common.Cursor;
|
||||
import google.registry.model.common.Cursor.CursorType;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.server.Lock;
|
||||
import google.registry.request.HttpException.NoContentException;
|
||||
import google.registry.request.HttpException.ServiceUnavailableException;
|
||||
import google.registry.request.Parameter;
|
||||
import google.registry.request.RequestParameters;
|
||||
import google.registry.request.lock.LockHandler;
|
||||
import google.registry.util.Clock;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -38,7 +38,7 @@ import org.joda.time.Duration;
|
|||
* <p>This class implements the <i>Locking Rolling Cursor</i> pattern, which solves the problem of
|
||||
* how to reliably execute App Engine tasks which can't be made idempotent.
|
||||
*
|
||||
* <p>{@link Lock} is used to ensure only one task executes at a time for a given
|
||||
* <p>{@link LockHandler} is used to ensure only one task executes at a time for a given
|
||||
* {@code LockedCursorTask} subclass + TLD combination. This is necessary because App Engine tasks
|
||||
* might double-execute. Normally tasks solve this by being idempotent, but that's not possible for
|
||||
* RDE, which writes to a GCS filename with a deterministic name. So Datastore is used to to
|
||||
|
@ -71,6 +71,7 @@ class EscrowTaskRunner {
|
|||
|
||||
@Inject Clock clock;
|
||||
@Inject @Parameter(RequestParameters.PARAM_TLD) String tld;
|
||||
@Inject LockHandler lockHandler;
|
||||
@Inject EscrowTaskRunner() {}
|
||||
|
||||
/**
|
||||
|
@ -109,7 +110,7 @@ class EscrowTaskRunner {
|
|||
return null;
|
||||
}};
|
||||
String lockName = String.format("%s %s", task.getClass().getSimpleName(), registry.getTld());
|
||||
if (!Lock.executeWithLocks(lockRunner, tld, timeout, lockName)) {
|
||||
if (!lockHandler.executeWithLocks(lockRunner, tld, timeout, lockName)) {
|
||||
// This will happen if either: a) the task is double-executed; b) the task takes a long time
|
||||
// to run and the retry task got executed while the first one is still running. In both
|
||||
// situations the safest thing to do is to just return 503 so the task gets retried later.
|
||||
|
|
|
@ -40,9 +40,9 @@ import google.registry.model.rde.RdeMode;
|
|||
import google.registry.model.rde.RdeNamingUtils;
|
||||
import google.registry.model.rde.RdeRevision;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.server.Lock;
|
||||
import google.registry.request.Parameter;
|
||||
import google.registry.request.RequestParameters;
|
||||
import google.registry.request.lock.LockHandler;
|
||||
import google.registry.tldconfig.idn.IdnTableEnum;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import google.registry.util.TaskEnqueuer;
|
||||
|
@ -66,11 +66,12 @@ import org.joda.time.Duration;
|
|||
/** Reducer for {@link RdeStagingAction}. */
|
||||
public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFragment, Void> {
|
||||
|
||||
private static final long serialVersionUID = -3366189042770402345L;
|
||||
private static final long serialVersionUID = 60326234579091203L;
|
||||
|
||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||
|
||||
private final TaskEnqueuer taskEnqueuer;
|
||||
private final LockHandler lockHandler;
|
||||
private final int gcsBufferSize;
|
||||
private final String bucket;
|
||||
private final int ghostrydeBufferSize;
|
||||
|
@ -81,6 +82,7 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
|
|||
@Inject
|
||||
RdeStagingReducer(
|
||||
TaskEnqueuer taskEnqueuer,
|
||||
LockHandler lockHandler,
|
||||
@Config("gcsBufferSize") int gcsBufferSize,
|
||||
@Config("rdeBucket") String bucket,
|
||||
@Config("rdeGhostrydeBufferSize") int ghostrydeBufferSize,
|
||||
|
@ -88,6 +90,7 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
|
|||
@KeyModule.Key("rdeStagingEncryptionKey") byte[] stagingKeyBytes,
|
||||
@Parameter(RdeModule.PARAM_LENIENT) boolean lenient) {
|
||||
this.taskEnqueuer = taskEnqueuer;
|
||||
this.lockHandler = lockHandler;
|
||||
this.gcsBufferSize = gcsBufferSize;
|
||||
this.bucket = bucket;
|
||||
this.ghostrydeBufferSize = ghostrydeBufferSize;
|
||||
|
@ -105,7 +108,7 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
|
|||
return null;
|
||||
}};
|
||||
String lockName = String.format("RdeStaging %s", key.tld());
|
||||
if (!Lock.executeWithLocks(lockRunner, null, lockTimeout, lockName)) {
|
||||
if (!lockHandler.executeWithLocks(lockRunner, null, lockTimeout, lockName)) {
|
||||
logger.warningfmt("Lock in use: %s", lockName);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue