Batch NORDN pull queue task deletions

They were failing because the maximum App Engine task batch size is 1,000, and
we currently have more than 4,000 tasks in the pull queue. We keep re-uploading
those to NORDN because we're unable to delete the tasks after successful upload,
so the leases expire and they get processed again.

Also renames TaskEnqueuer to TaskQueueUtils to reflect its newly expanded role.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=197060903
This commit is contained in:
mcilwain 2018-05-17 15:22:34 -07:00 committed by jianglai
parent 1248a7722b
commit c989911526
21 changed files with 129 additions and 73 deletions

View file

@ -28,7 +28,7 @@ import google.registry.request.Action;
import google.registry.request.auth.Auth;
import google.registry.util.Clock;
import google.registry.util.FormattingLogger;
import google.registry.util.TaskEnqueuer;
import google.registry.util.TaskQueueUtils;
import javax.inject.Inject;
import org.joda.time.DateTime;
@ -56,7 +56,7 @@ public final class CommitLogCheckpointAction implements Runnable {
@Inject Clock clock;
@Inject CommitLogCheckpointStrategy strategy;
@Inject TaskEnqueuer taskEnqueuer;
@Inject TaskQueueUtils taskQueueUtils;
@Inject CommitLogCheckpointAction() {}
@Override
@ -76,7 +76,7 @@ public final class CommitLogCheckpointAction implements Runnable {
.entities(
checkpoint, CommitLogCheckpointRoot.create(checkpoint.getCheckpointTime()));
// Enqueue a diff task between previous and current checkpoints.
taskEnqueuer.enqueue(
taskQueueUtils.enqueue(
getQueue(QUEUE_NAME),
withUrl(ExportCommitLogDiffAction.PATH)
.param(LOWER_CHECKPOINT_TIME_PARAM, lastWrittenTime.toString())

View file

@ -27,6 +27,7 @@ import com.google.common.net.HostAndPort;
import dagger.Module;
import dagger.Provides;
import google.registry.config.RegistryConfigSettings.AppEngine.ToolsServiceUrl;
import google.registry.util.TaskQueueUtils;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.net.URI;
@ -853,7 +854,7 @@ public final class RegistryConfig {
* <p>Note that this uses {@code @Named} instead of {@code @Config} so that it can be used from
* the low-level util package, which cannot have a dependency on the config package.
*
* @see google.registry.util.TaskEnqueuer
* @see TaskQueueUtils
*/
@Provides
@Named("transientFailureRetries")

View file

@ -23,7 +23,7 @@ import google.registry.model.ofy.CommitLogBucket;
import google.registry.request.Action;
import google.registry.request.Parameter;
import google.registry.request.auth.Auth;
import google.registry.util.TaskEnqueuer;
import google.registry.util.TaskQueueUtils;
import java.util.Optional;
import java.util.Random;
import javax.inject.Inject;
@ -40,7 +40,7 @@ public final class CommitLogFanoutAction implements Runnable {
private static final Random random = new Random();
@Inject TaskEnqueuer taskEnqueuer;
@Inject TaskQueueUtils taskQueueUtils;
@Inject @Parameter("endpoint") String endpoint;
@Inject @Parameter("queue") String queue;
@Inject @Parameter("jitterSeconds") Optional<Integer> jitterSeconds;
@ -55,7 +55,7 @@ public final class CommitLogFanoutAction implements Runnable {
.countdownMillis(jitterSeconds.isPresent()
? random.nextInt((int) SECONDS.toMillis(jitterSeconds.get()))
: 0);
taskEnqueuer.enqueue(taskQueue, taskOptions);
taskQueueUtils.enqueue(taskQueue, taskOptions);
}
}
}

View file

@ -43,7 +43,7 @@ import google.registry.request.RequestParameters;
import google.registry.request.Response;
import google.registry.request.auth.Auth;
import google.registry.util.FormattingLogger;
import google.registry.util.TaskEnqueuer;
import google.registry.util.TaskQueueUtils;
import java.util.Optional;
import java.util.Random;
import java.util.stream.Stream;
@ -103,7 +103,7 @@ public final class TldFanoutAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
@Inject TaskEnqueuer taskEnqueuer;
@Inject TaskQueueUtils taskQueueUtils;
@Inject Response response;
@Inject @Parameter(ENDPOINT_PARAM) String endpoint;
@Inject @Parameter(QUEUE_PARAM) String queue;
@ -144,7 +144,7 @@ public final class TldFanoutAction implements Runnable {
}
for (String tld : tlds) {
TaskOptions taskOptions = createTaskOptions(tld, flowThruParams);
TaskHandle taskHandle = taskEnqueuer.enqueue(taskQueue, taskOptions);
TaskHandle taskHandle = taskQueueUtils.enqueue(taskQueue, taskOptions);
outputPayload.append(
String.format(
"- Task: '%s', tld: '%s', endpoint: '%s'\n",

View file

@ -47,7 +47,7 @@ import google.registry.request.RequestParameters;
import google.registry.request.auth.Auth;
import google.registry.util.Clock;
import google.registry.util.FormattingLogger;
import google.registry.util.TaskEnqueuer;
import google.registry.util.TaskQueueUtils;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Comparator;
@ -101,7 +101,7 @@ public final class ReadDnsQueueAction implements Runnable {
@Inject Clock clock;
@Inject DnsQueue dnsQueue;
@Inject HashFunction hashFunction;
@Inject TaskEnqueuer taskEnqueuer;
@Inject TaskQueueUtils taskQueueUtils;
@Inject ReadDnsQueueAction() {}
/** Container for items we pull out of the DNS pull queue and process for fanout. */
@ -374,7 +374,7 @@ public final class ReadDnsQueueAction implements Runnable {
: PublishDnsUpdatesAction.PARAM_DOMAINS,
refreshItem.name());
}
taskEnqueuer.enqueue(dnsPublishPushQueue, options);
taskQueueUtils.enqueue(dnsPublishPushQueue, options);
}
}
}

View file

@ -33,7 +33,7 @@ import google.registry.request.HttpException.NotModifiedException;
import google.registry.request.Payload;
import google.registry.request.auth.Auth;
import google.registry.util.FormattingLogger;
import google.registry.util.TaskEnqueuer;
import google.registry.util.TaskQueueUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -64,7 +64,7 @@ public class BigqueryPollJobAction implements Runnable {
static final Duration POLL_COUNTDOWN = Duration.standardSeconds(20);
@Inject Bigquery bigquery;
@Inject TaskEnqueuer enqueuer;
@Inject TaskQueueUtils taskQueueUtils;
@Inject @Header(CHAINED_TASK_QUEUE_HEADER) Lazy<String> chainedQueueName;
@Inject @Header(PROJECT_ID_HEADER) String projectId;
@Inject @Header(JOB_ID_HEADER) String jobId;
@ -84,7 +84,7 @@ public class BigqueryPollJobAction implements Runnable {
} catch (ClassNotFoundException | IOException e) {
throw new BadRequestException("Cannot deserialize task from payload", e);
}
String taskName = enqueuer.enqueue(getQueue(chainedQueueName.get()), task).getName();
String taskName = taskQueueUtils.enqueue(getQueue(chainedQueueName.get()), task).getName();
logger.infofmt(
"Added chained task %s for %s to queue %s: %s",
taskName,
@ -127,16 +127,17 @@ public class BigqueryPollJobAction implements Runnable {
/** Helper class to enqueue a bigquery poll job. */
public static class BigqueryPollJobEnqueuer {
private final TaskEnqueuer enqueuer;
private final TaskQueueUtils taskQueueUtils;
@Inject
BigqueryPollJobEnqueuer(TaskEnqueuer enqueuer) {
this.enqueuer = enqueuer;
BigqueryPollJobEnqueuer(TaskQueueUtils taskQueueUtils) {
this.taskQueueUtils = taskQueueUtils;
}
/** Enqueue a task to poll for the success or failure of the referenced BigQuery job. */
public TaskHandle enqueuePollTask(JobReference jobRef) {
return enqueuer.enqueue(getQueue(QUEUE), createCommonPollTask(jobRef).method(Method.GET));
return taskQueueUtils.enqueue(
getQueue(QUEUE), createCommonPollTask(jobRef).method(Method.GET));
}
/**
@ -148,7 +149,7 @@ public class BigqueryPollJobAction implements Runnable {
// Serialize the chainedTask into a byte array to put in the task payload.
ByteArrayOutputStream taskBytes = new ByteArrayOutputStream();
new ObjectOutputStream(taskBytes).writeObject(chainedTask);
return enqueuer.enqueue(
return taskQueueUtils.enqueue(
getQueue(QUEUE),
createCommonPollTask(jobRef)
.method(Method.POST)

View file

@ -34,7 +34,7 @@ import google.registry.request.Parameter;
import google.registry.request.auth.Auth;
import google.registry.security.XsrfTokenManager;
import google.registry.util.FormattingLogger;
import google.registry.util.TaskEnqueuer;
import google.registry.util.TaskQueueUtils;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@ -147,8 +147,7 @@ public class LoadTestAction implements Runnable {
@Parameter("hostInfos")
int hostInfosPerSecond;
@Inject
TaskEnqueuer taskEnqueuer;
@Inject TaskQueueUtils taskQueueUtils;
private final String xmlContactCreateTmpl;
private final String xmlContactCreateFail;
@ -344,7 +343,7 @@ public class LoadTestAction implements Runnable {
List<List<TaskOptions>> chunks = partition(tasks, maxTasksPerAdd());
// Farm out tasks to multiple queues to work around queue qps quotas.
for (int i = 0; i < chunks.size(); i++) {
taskEnqueuer.enqueue(getQueue("load" + (i % NUM_QUEUES)), chunks.get(i));
taskQueueUtils.enqueue(getQueue("load" + (i % NUM_QUEUES)), chunks.get(i));
}
}
}

View file

@ -44,7 +44,7 @@ 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;
import google.registry.util.TaskQueueUtils;
import google.registry.xjc.rdeheader.XjcRdeHeader;
import google.registry.xjc.rdeheader.XjcRdeHeaderElement;
import google.registry.xml.XmlException;
@ -70,7 +70,7 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private final TaskEnqueuer taskEnqueuer;
private final TaskQueueUtils taskQueueUtils;
private final LockHandler lockHandler;
private final int gcsBufferSize;
private final String bucket;
@ -81,7 +81,7 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
@Inject
RdeStagingReducer(
TaskEnqueuer taskEnqueuer,
TaskQueueUtils taskQueueUtils,
LockHandler lockHandler,
@Config("gcsBufferSize") int gcsBufferSize,
@Config("rdeBucket") String bucket,
@ -89,7 +89,7 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
@Config("rdeStagingLockTimeout") Duration lockTimeout,
@KeyModule.Key("rdeStagingEncryptionKey") byte[] stagingKeyBytes,
@Parameter(RdeModule.PARAM_LENIENT) boolean lenient) {
this.taskEnqueuer = taskEnqueuer;
this.taskQueueUtils = taskQueueUtils;
this.lockHandler = lockHandler;
this.gcsBufferSize = gcsBufferSize;
this.bucket = bucket;
@ -248,11 +248,11 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
"Rolled forward %s on %s cursor to %s", key.cursor(), tld, newPosition);
RdeRevision.saveRevision(tld, watermark, mode, revision);
if (mode == RdeMode.FULL) {
taskEnqueuer.enqueue(
taskQueueUtils.enqueue(
getQueue("rde-upload"),
withUrl(RdeUploadAction.PATH).param(RequestParameters.PARAM_TLD, tld));
} else {
taskEnqueuer.enqueue(
taskQueueUtils.enqueue(
getQueue("brda"),
withUrl(BrdaCopyAction.PATH)
.param(RequestParameters.PARAM_TLD, tld)

View file

@ -52,7 +52,7 @@ import google.registry.request.auth.Auth;
import google.registry.util.Clock;
import google.registry.util.FormattingLogger;
import google.registry.util.Retrier;
import google.registry.util.TaskEnqueuer;
import google.registry.util.TaskQueueUtils;
import google.registry.util.TeeOutputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -108,7 +108,7 @@ public final class RdeUploadAction implements Runnable, EscrowTask {
@Inject RydePgpFileOutputStreamFactory pgpFileFactory;
@Inject RydePgpSigningOutputStreamFactory pgpSigningFactory;
@Inject RydeTarOutputStreamFactory tarFactory;
@Inject TaskEnqueuer taskEnqueuer;
@Inject TaskQueueUtils taskQueueUtils;
@Inject Retrier retrier;
@Inject @Parameter(RequestParameters.PARAM_TLD) String tld;
@Inject @Config("rdeBucket") String bucket;
@ -125,7 +125,7 @@ public final class RdeUploadAction implements Runnable, EscrowTask {
@Override
public void run() {
runner.lockRunAndRollForward(this, Registry.get(tld), timeout, CursorType.RDE_UPLOAD, interval);
taskEnqueuer.enqueue(
taskQueueUtils.enqueue(
reportQueue,
withUrl(RdeReportAction.PATH).param(RequestParameters.PARAM_TLD, tld));
}

View file

@ -33,6 +33,7 @@ import com.google.common.util.concurrent.Uninterruptibles;
import google.registry.model.domain.DomainResource;
import google.registry.model.registrar.Registrar;
import google.registry.util.NonFinalForTesting;
import google.registry.util.TaskQueueUtils;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@ -53,9 +54,6 @@ public class LordnTask {
+ "registration-datetime,application-datetime";
private static final Duration LEASE_PERIOD = Duration.standardHours(1);
/** This is the max allowable batch size. */
private static final long BATCH_SIZE = 1000;
@NonFinalForTesting
private static Long backOffMillis = 2000L;
@ -85,7 +83,7 @@ public class LordnTask {
List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder
.withTag(tld)
.leasePeriod(LEASE_PERIOD.getMillis(), TimeUnit.MILLISECONDS)
.countLimit(BATCH_SIZE));
.countLimit(TaskQueueUtils.getBatchSize()));
allTasks.addAll(tasks);
if (tasks.isEmpty()) {
return allTasks.build();

View file

@ -41,6 +41,7 @@ import google.registry.request.RequestParameters;
import google.registry.request.auth.Auth;
import google.registry.util.Clock;
import google.registry.util.FormattingLogger;
import google.registry.util.TaskQueueUtils;
import google.registry.util.UrlFetchException;
import java.io.IOException;
import java.net.URL;
@ -84,6 +85,7 @@ public final class NordnUploadAction implements Runnable {
@Inject @Config("tmchMarksdbUrl") String tmchMarksdbUrl;
@Inject @Parameter(LORDN_PHASE_PARAM) String phase;
@Inject @Parameter(RequestParameters.PARAM_TLD) String tld;
@Inject TaskQueueUtils taskQueueUtils;
@Inject NordnUploadAction() {}
/**
@ -117,7 +119,7 @@ public final class NordnUploadAction implements Runnable {
if (!tasks.isEmpty()) {
String csvData = convertTasksToCsv(tasks, now, columns);
uploadCsvToLordn(String.format("/LORDN/%s/%s", tld, phase), csvData);
queue.deleteTask(tasks);
taskQueueUtils.deleteTasks(queue, tasks);
}
}

View file

@ -1,4 +1,4 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,12 +20,14 @@ import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.TaskHandle;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.appengine.api.taskqueue.TransientFailureException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import java.io.Serializable;
import java.util.List;
import javax.inject.Inject;
/** Utilities for dealing with App Engine task queues. */
public class TaskEnqueuer implements Serializable {
public class TaskQueueUtils implements Serializable {
private static final long serialVersionUID = 7893211200220508362L;
@ -34,10 +36,23 @@ public class TaskEnqueuer implements Serializable {
private final Retrier retrier;
@Inject
public TaskEnqueuer(Retrier retrier) {
public TaskQueueUtils(Retrier retrier) {
this.retrier = retrier;
}
@NonFinalForTesting
@VisibleForTesting
static int BATCH_SIZE = 1000;
/**
* The batch size to use for App Engine task queue operations.
*
* <p>Note that 1,000 is currently the maximum allowable batch size in App Engine.
*/
public static int getBatchSize() {
return BATCH_SIZE;
}
/**
* Adds a task to a App Engine task queue in a reliable manner.
*
@ -73,4 +88,14 @@ public class TaskEnqueuer implements Serializable {
},
TransientFailureException.class);
}
/** Deletes the specified tasks from the queue in batches, with retrying. */
public void deleteTasks(Queue queue, List<TaskHandle> tasks) {
Lists.partition(tasks, BATCH_SIZE)
.stream()
.forEach(
batch ->
retrier.callWithRetry(
() -> queue.deleteTask(batch), TransientFailureException.class));
}
}