Map over Key instead of actual instances when deleting old commit logs

Attempting to run DeleteOldCommitLogs in prod resulted in a lot of DatastoreTimeoutException errors. The assumption is that attempting to load so many CommitLogManifests (over 200 million of them), when each one has a slight possibility of failure, has a very high probability of error.

The shard aborts after 20 of these errors, and by eliminating as many loads as possible and retrying the remaining loads inside a transaction we are effectively eliminating any exceptions "leaking" out to the mapreduce framework, which will hopefully keep us bellow 20. At least, that's our best guess currently as to why the mapreduce fails.

EppResources are loaded in the map stage to get the revisions, and CommitLogManifests are only loaded in the reduce stage for sanity check so we don't accidentally delete resources we need in prod. Both of these are wrapped in transactNew to make sure they retry individually.

The only "load" not done inside a transaction is the EppResourceIndex, but there's no getting around that without rewriting the EppResourceInputs.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=164176764
This commit is contained in:
guyben 2017-07-18 13:54:37 -04:00 committed by Ben McIlwain
parent 2f238a2c77
commit cf94d69a3e
5 changed files with 97 additions and 60 deletions

View file

@ -103,6 +103,10 @@ public class DeleteOldCommitLogsActionTest
assertThat(ofy().load().type(CommitLogMutation.class).count()).isEqualTo(33);
}
private <T> ImmutableList<T> ofyLoadType(Class<T> clazz) {
return ImmutableList.copyOf(ofy().load().type(clazz).iterable());
}
/**
* Check that with very short maxAge, only the referenced elements remain.
*/
@ -110,12 +114,11 @@ public class DeleteOldCommitLogsActionTest
public void test_shortMaxAge() throws Exception {
runMapreduce(Duration.millis(1));
assertThat(ofy().load().type(CommitLogManifest.class).keys().iterable())
assertThat(ImmutableList.copyOf(ofy().load().type(CommitLogManifest.class).keys().iterable()))
.containsExactlyElementsIn(contact.getRevisions().values());
// And each DatastoreHelper.persistResourceWithCommitLog creates 3 mutations
assertThat(ofy().load().type(CommitLogMutation.class).keys().iterable())
.hasSize(contact.getRevisions().size() * 3);
assertThat(ofyLoadType(CommitLogMutation.class)).hasSize(contact.getRevisions().size() * 3);
}
/**
@ -124,16 +127,12 @@ public class DeleteOldCommitLogsActionTest
@Test
public void test_longMaxAge() throws Exception {
ImmutableList<CommitLogManifest> initialManifests =
ImmutableList.copyOf(ofy().load().type(CommitLogManifest.class).iterable());
ImmutableList<CommitLogMutation> initialMutations =
ImmutableList.copyOf(ofy().load().type(CommitLogMutation.class).iterable());
ImmutableList<CommitLogManifest> initialManifests = ofyLoadType(CommitLogManifest.class);
ImmutableList<CommitLogMutation> initialMutations = ofyLoadType(CommitLogMutation.class);
runMapreduce(Duration.standardDays(1000));
assertThat(ofy().load().type(CommitLogManifest.class).iterable())
.containsExactlyElementsIn(initialManifests);
assertThat(ofy().load().type(CommitLogMutation.class).iterable())
.containsExactlyElementsIn(initialMutations);
assertThat(ofyLoadType(CommitLogManifest.class)).containsExactlyElementsIn(initialManifests);
assertThat(ofyLoadType(CommitLogMutation.class)).containsExactlyElementsIn(initialMutations);
}
}