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

@ -25,6 +25,7 @@ import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import google.registry.model.registrar.Registrar;
import google.registry.util.FormattingLogger;
@ -48,10 +49,9 @@ final class RegistrarLookupCommand implements WhoisCommand {
@Override
public Map<String, Registrar> get() {
Map<String, Registrar> map = new HashMap<>();
// Use the normalized registrar name as a key.
Iterable<Registrar> registrars = Registrar.loadAllActiveAndPubliclyVisible();
for (Registrar registrar : registrars) {
if (registrar.getRegistrarName() == null) {
// Use the normalized registrar name as a key, and ignore inactive and hidden registrars.
for (Registrar registrar : Registrar.loadAllCached()) {
if (!registrar.isActiveAndPubliclyVisible() || registrar.getRegistrarName() == null) {
continue;
}
String normalized = normalizeRegistrarName(registrar.getRegistrarName());
@ -65,7 +65,7 @@ final class RegistrarLookupCommand implements WhoisCommand {
// if there isn't already a mapping for this string, so that if there's a registrar with a
// two word name (Go Daddy) and no business-type suffix and another registrar with just
// that first word as its name (Go), the latter will win.
for (Registrar registrar : registrars) {
for (Registrar registrar : ImmutableList.copyOf(map.values())) {
if (registrar.getRegistrarName() == null) {
continue;
}