mirror of
https://github.com/google/nomulus.git
synced 2025-04-29 19:47:51 +02:00
Reload resources before saving in ReloadAllEppResourcesAction
This prevents a potential blind write scenario in which something else has concurrently modified the EppResource in between load and save, and those changes then get overwritten. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=138911873
This commit is contained in:
parent
fab8ca8414
commit
7ed02f4612
1 changed files with 8 additions and 7 deletions
|
@ -14,14 +14,15 @@
|
||||||
|
|
||||||
package google.registry.tools.server;
|
package google.registry.tools.server;
|
||||||
|
|
||||||
import static google.registry.mapreduce.inputs.EppResourceInputs.createEntityInput;
|
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.util.PipelineUtils.createJobPath;
|
import static google.registry.util.PipelineUtils.createJobPath;
|
||||||
|
|
||||||
import com.google.appengine.tools.mapreduce.Mapper;
|
import com.google.appengine.tools.mapreduce.Mapper;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.googlecode.objectify.Key;
|
||||||
import com.googlecode.objectify.VoidWork;
|
import com.googlecode.objectify.VoidWork;
|
||||||
import google.registry.mapreduce.MapreduceRunner;
|
import google.registry.mapreduce.MapreduceRunner;
|
||||||
|
import google.registry.mapreduce.inputs.EppResourceInputs;
|
||||||
import google.registry.model.EppResource;
|
import google.registry.model.EppResource;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
import google.registry.request.Response;
|
import google.registry.request.Response;
|
||||||
|
@ -49,24 +50,24 @@ public class ResaveAllEppResourcesAction implements Runnable {
|
||||||
.setModuleName("tools")
|
.setModuleName("tools")
|
||||||
.runMapOnly(
|
.runMapOnly(
|
||||||
new ResaveAllEppResourcesActionMapper(),
|
new ResaveAllEppResourcesActionMapper(),
|
||||||
ImmutableList.of(createEntityInput(EppResource.class)))));
|
ImmutableList.of(EppResourceInputs.createKeyInput(EppResource.class)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Mapper to re-save all EPP resources. */
|
/** Mapper to re-save all EPP resources. */
|
||||||
public static class ResaveAllEppResourcesActionMapper extends Mapper<EppResource, Void, Void> {
|
public static class ResaveAllEppResourcesActionMapper
|
||||||
|
extends Mapper<Key<EppResource>, Void, Void> {
|
||||||
|
|
||||||
private static final long serialVersionUID = -7721628665138087001L;
|
private static final long serialVersionUID = -7721628665138087001L;
|
||||||
public ResaveAllEppResourcesActionMapper() {}
|
public ResaveAllEppResourcesActionMapper() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void map(final EppResource resource) {
|
public final void map(final Key<EppResource> resourceKey) {
|
||||||
ofy().transact(new VoidWork() {
|
ofy().transact(new VoidWork() {
|
||||||
@Override
|
@Override
|
||||||
public void vrun() {
|
public void vrun() {
|
||||||
ofy().save().entity(resource).now();
|
ofy().save().entity(ofy().load().key(resourceKey).now()).now();
|
||||||
}});
|
}});
|
||||||
getContext().incrementCounter(
|
getContext().incrementCounter(String.format("%s entities re-saved", resourceKey.getKind()));
|
||||||
String.format("%s entities re-saved", resource.getClass().getSimpleName()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue