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

@ -14,6 +14,8 @@
package google.registry.dns.writer;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.base.Joiner;
import java.util.HashSet;
import java.util.Set;
@ -35,6 +37,8 @@ public final class VoidDnsWriter implements DnsWriter {
private static final Logger logger = Logger.getLogger(VoidDnsWriter.class.getName());
private boolean committed = false;
private final Set<String> names = new HashSet<>();
@Inject
@ -51,7 +55,10 @@ public final class VoidDnsWriter implements DnsWriter {
}
@Override
public void close() {
public void commit() {
checkState(!committed, "commit() has already been called");
committed = true;
logger.warning("Ignoring DNS zone updates! No DnsWriterFactory implementation specified!\n"
+ Joiner.on('\n').join(names));
}