Make DnsWriter truly atomic

Right now - if there's an error during DnsWriter.publish*, all the publish from
before that error will be committed, while all the publish after that error
will not.

More than that - in some writers partial publishes can be committed, depending
on implementation.

This defines a new contract that publish* are only committed when .commit is
called. That way any error will simply mean no publish is committed.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=165708063
This commit is contained in:
guyben 2017-08-18 08:27:34 -07:00 committed by Ben McIlwain
parent fcb554947c
commit d5ac03aae4
8 changed files with 204 additions and 90 deletions

View file

@ -92,7 +92,7 @@ public class PublishDnsUpdatesActionTest {
action.run();
verify(dnsWriter).publishHost("ns1.example.xn--q9jyb4c");
verify(dnsWriter).close();
verify(dnsWriter).commit();
verifyNoMoreInteractions(dnsWriter);
verify(dnsMetrics).incrementPublishHostRequests("xn--q9jyb4c", Status.ACCEPTED);
@ -106,7 +106,7 @@ public class PublishDnsUpdatesActionTest {
action.run();
verify(dnsWriter).publishDomain("example.xn--q9jyb4c");
verify(dnsWriter).close();
verify(dnsWriter).commit();
verifyNoMoreInteractions(dnsWriter);
verify(dnsMetrics).incrementPublishDomainRequests("xn--q9jyb4c", Status.ACCEPTED);
@ -126,7 +126,7 @@ public class PublishDnsUpdatesActionTest {
verify(dnsWriter).publishHost("ns1.example.xn--q9jyb4c");
verify(dnsWriter).publishHost("ns2.example.xn--q9jyb4c");
verify(dnsWriter).publishHost("ns1.example2.xn--q9jyb4c");
verify(dnsWriter).close();
verify(dnsWriter).commit();
verifyNoMoreInteractions(dnsWriter);
verify(dnsMetrics, times(2)).incrementPublishDomainRequests("xn--q9jyb4c", Status.ACCEPTED);
@ -141,7 +141,7 @@ public class PublishDnsUpdatesActionTest {
action.hosts = ImmutableSet.of("ns1.example.com", "ns2.example.com", "ns1.example2.com");
action.run();
verify(dnsWriter).close();
verify(dnsWriter).commit();
verifyNoMoreInteractions(dnsWriter);
verify(dnsMetrics, times(2)).incrementPublishDomainRequests("xn--q9jyb4c", Status.REJECTED);