Cache Registrars in memory

This replaces the memcache caching, which we think is overall a bad idea.
We load all registrars at once instead of caching each as needed, so that
the loadAllCached() methods can be cached as well, and therefore will
always produce results consistent with loadByClientIdCached()'s view of the
registrar's values. All of our prod registrars together total 300k of data
right now, so this is hardly worth optimizing further, and in any case this
will likely reduce latency even further since most requests will be
served out of memory.

While I was in the Registrar file I standardized the error messages for incorrect
password and clientId length to be the same format, and cleaned up a few
random things I noticed in the code.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=156151828
This commit is contained in:
cgoldfeder 2017-05-16 00:42:49 -07:00 committed by Ben McIlwain
parent 9a48aae107
commit c9d7e75946
17 changed files with 149 additions and 179 deletions

View file

@ -15,12 +15,13 @@
package google.registry.rdap;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.rdap.RdapUtils.getRegistrarByIanaIdentifier;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.HEAD;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.primitives.Longs;
import com.google.re2j.Pattern;
import com.googlecode.objectify.Key;
import google.registry.model.contact.ContactResource;
@ -96,18 +97,14 @@ public class RdapEntityAction extends RdapActionBase {
OutputDataType.FULL);
}
}
try {
Long ianaIdentifier = Long.parseLong(pathSearchString);
Long ianaIdentifier = Longs.tryParse(pathSearchString);
if (ianaIdentifier != null) {
wasValidKey = true;
Registrar registrar = Iterables.getOnlyElement(
Registrar.loadByIanaIdentifierRange(ianaIdentifier, ianaIdentifier + 1, 1), null);
if ((registrar != null) && registrar.isActiveAndPubliclyVisible()) {
Optional<Registrar> registrar = getRegistrarByIanaIdentifier(ianaIdentifier);
if ((registrar.isPresent()) && registrar.get().isActiveAndPubliclyVisible()) {
return rdapJsonFormatter.makeRdapJsonForRegistrar(
registrar, true, rdapLinkBase, rdapWhoisServer, now, OutputDataType.FULL);
registrar.get(), true, rdapLinkBase, rdapWhoisServer, now, OutputDataType.FULL);
}
} catch (NumberFormatException e) {
// Although the search string was not a valid IANA identifier, it might still have been a
// valid ROID.
}
// At this point, we have failed to find either a contact or a registrar.
throw wasValidKey