diff --git a/java/com/google/domain/registry/tools/server/KillAllCommitLogsAction.java b/java/com/google/domain/registry/tools/server/KillAllCommitLogsAction.java index ec2c3f30f..a3cdde0b1 100644 --- a/java/com/google/domain/registry/tools/server/KillAllCommitLogsAction.java +++ b/java/com/google/domain/registry/tools/server/KillAllCommitLogsAction.java @@ -15,7 +15,6 @@ package com.google.domain.registry.tools.server; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.collect.Lists.partition; import static com.google.domain.registry.model.ofy.ObjectifyService.ofy; import static com.google.domain.registry.request.Action.Method.POST; import static com.google.domain.registry.util.PipelineUtils.createJobPath; @@ -23,16 +22,21 @@ import static com.google.domain.registry.util.PipelineUtils.createJobPath; import com.google.appengine.tools.mapreduce.Input; import com.google.appengine.tools.mapreduce.Mapper; import com.google.appengine.tools.mapreduce.inputs.InMemoryInput; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; import com.google.domain.registry.config.RegistryEnvironment; import com.google.domain.registry.mapreduce.MapreduceAction; import com.google.domain.registry.mapreduce.MapreduceRunner; import com.google.domain.registry.model.ofy.CommitLogBucket; +import com.google.domain.registry.model.ofy.CommitLogCheckpointRoot; import com.google.domain.registry.request.Action; import com.google.domain.registry.request.Response; import com.googlecode.objectify.Key; +import java.util.Arrays; + import javax.inject.Inject; /** Deletes all commit logs in datastore. */ @@ -49,9 +53,15 @@ public class KillAllCommitLogsAction implements MapreduceAction { RegistryEnvironment.get() == RegistryEnvironment.CRASH || RegistryEnvironment.get() == RegistryEnvironment.UNITTEST, "DO NOT RUN ANYWHERE ELSE EXCEPT CRASH OR TESTS."); - // Create a in-memory input, assigning each bucket to its own shard for maximum parallelization. - Input> input = - new InMemoryInput<>(partition(CommitLogBucket.getAllBucketKeys().asList(), 1)); + // Create a in-memory input, assigning each bucket to its own shard for maximum parallelization, + // with one extra shard for the CommitLogCheckpointRoot. + Input> input = new InMemoryInput<>( + Lists.partition( + FluentIterable + .from(Arrays.>asList(CommitLogCheckpointRoot.getKey())) + .append(CommitLogBucket.getAllBucketKeys()) + .toList(), + 1)); response.sendJavaScriptRedirect(createJobPath(mrRunner .setJobName("Delete all commit logs") .setModuleName("tools") @@ -62,23 +72,26 @@ public class KillAllCommitLogsAction implements MapreduceAction { } /** - * Mapper to delete a {@link CommitLogBucket} and any commit logs in the bucket. + * Mapper to delete a {@link CommitLogBucket} or {@link CommitLogCheckpointRoot} and any commit + * logs or checkpoints that descend from it. * *

This will delete: *

    *
  • {@link CommitLogBucket} + *
  • {@code CommitLogCheckpoint} + *
  • {@link CommitLogCheckpointRoot} *
  • {@code CommitLogManifest} *
  • {@code CommitLogMutation} *
*/ - static class KillAllCommitLogsMapper extends Mapper, Key, Key> { + static class KillAllCommitLogsMapper extends Mapper, Key, Key> { private static final long serialVersionUID = 1504266335352952033L; @Override - public void map(Key bucket) { - for (Key key : ofy().load().ancestor(bucket).keys()) { - emit(bucket, key); + public void map(Key bucketOrRoot) { + for (Key key : ofy().load().ancestor(bucketOrRoot).keys()) { + emit(bucketOrRoot, key); getContext().incrementCounter("entities emitted"); getContext().incrementCounter(String.format("%s emitted", key.getKind())); } diff --git a/javatests/com/google/domain/registry/tools/server/KillAllCommitLogsActionTest.java b/javatests/com/google/domain/registry/tools/server/KillAllCommitLogsActionTest.java index 1811eea2d..9c6d0a08c 100644 --- a/javatests/com/google/domain/registry/tools/server/KillAllCommitLogsActionTest.java +++ b/javatests/com/google/domain/registry/tools/server/KillAllCommitLogsActionTest.java @@ -21,7 +21,9 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.domain.registry.model.ofy.ObjectifyService.ofy; import static com.google.domain.registry.testing.DatastoreHelper.createTld; import static com.google.domain.registry.testing.DatastoreHelper.newContactResource; +import static com.google.domain.registry.testing.DatastoreHelper.persistResource; import static com.google.domain.registry.testing.DatastoreHelper.persistResourceWithCommitLog; +import static com.google.domain.registry.util.DateTimeUtils.START_OF_TIME; import static java.util.Arrays.asList; import com.google.appengine.api.datastore.Entity; @@ -29,9 +31,12 @@ import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.domain.registry.mapreduce.MapreduceRunner; import com.google.domain.registry.model.ImmutableObject; import com.google.domain.registry.model.ofy.CommitLogBucket; +import com.google.domain.registry.model.ofy.CommitLogCheckpoint; +import com.google.domain.registry.model.ofy.CommitLogCheckpointRoot; import com.google.domain.registry.model.ofy.CommitLogManifest; import com.google.domain.registry.model.ofy.CommitLogMutation; import com.google.domain.registry.testing.FakeResponse; @@ -49,6 +54,8 @@ public class KillAllCommitLogsActionTest extends MapreduceTestCase> AFFECTED_TYPES = ImmutableList.of( CommitLogBucket.class, + CommitLogCheckpoint.class, + CommitLogCheckpointRoot.class, CommitLogMutation.class, CommitLogManifest.class); @@ -68,6 +75,11 @@ public class KillAllCommitLogsActionTest extends MapreduceTestCase clazz : AFFECTED_TYPES) { assertThat(ofy().load().type(clazz)).named("entities of type " + clazz).isNotEmpty(); }