Remove AccountByEmailCache

With change I1c24da1378 there is a new Emails class that allows looking
up accounts by email. To find accounts by email it gets external IDs by
email from the ExternalIdCache and extracts the account IDs from the
external IDs. This is exactly what AccountByEmailCacheImpl.Loader was
doing. In addition the Emails class does an index lookup to also find
accounts by preferred email (see commit message of change I1c24da1378
for an explanation of why this is needed).

Change I991d21b1ac removed all usages of AccountByEmailCache by using
the Emails class instead. Hence the AccountByEmailCache can be removed
now.

Change-Id: I3a4279f5abda7ff3f03268258bb1755ce528f0d4
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin 2017-06-01 11:29:29 +02:00
parent 3f57890fb8
commit e12c306ca3
12 changed files with 0 additions and 166 deletions

View File

@ -60,7 +60,6 @@ List caches available for flushing:
----
$ ssh -p 29418 review.example.com gerrit flush-caches --list
accounts
accounts_byemail
diff
groups
ldap_groups

View File

@ -58,7 +58,6 @@ Intended for interactive use only.
| Mem Disk Space| |Mem Disk|
--------------------------------+---------------------+---------+---------+
accounts | 4096 | 3.4ms | 99% |
accounts_byemail | 1024 | 7.6ms | 98% |
accounts_byname | 4096 | 11.3ms | 99% |
adv_bases | | | |
changes | | 27.1ms | 0% |

View File

@ -714,12 +714,6 @@ database tables:
If direct updates are made to any of these database tables, this
cache should be flushed.
cache `"accounts_byemail"`::
+
Caches account identities keyed by email address, which is scanned
from the `account_external_ids` database table. If updates are
made to this table, this cache should be flushed.
cache `"adv_bases"`::
+
Used only for push over smart HTTP when branch level access controls

View File

@ -94,8 +94,6 @@ are recognized in a reasonable period of time:
----
[cache "accounts"]
maxAge = 5 min
[cache "accounts_byemail"]
maxAge = 5 min
[cache "diff"]
maxAge = 5 min
[cache "groups"]

View File

@ -298,16 +298,6 @@ The entries in the map are sorted by cache name.
"mem": 94
}
},
"accounts_byemail": {
"type": "MEM",
"entries": {
"mem": 4
},
"average_get": "771.8us",
"hit_ratio": {
"mem": 95
}
},
"accounts_byname": {
"type": "MEM",
"entries": {
@ -514,7 +504,6 @@ The cache names are lexicographically sorted.
)]}'
[
"accounts",
"accounts_byemail",
"accounts_byname",
"adv_bases",
"change_kind",

View File

@ -23,7 +23,6 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.Sequences;
import com.google.gerrit.server.account.AccountByEmailCache;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.AccountsUpdate;
import com.google.gerrit.server.account.VersionedAuthorizedKeys;
@ -60,7 +59,6 @@ public class AccountCreator {
private final Provider<GroupsUpdate> groupsUpdateProvider;
private final SshKeyCache sshKeyCache;
private final AccountCache accountCache;
private final AccountByEmailCache byEmailCache;
private final ExternalIdsUpdate.Server externalIdsUpdate;
private final boolean sshEnabled;
@ -74,7 +72,6 @@ public class AccountCreator {
@ServerInitiated Provider<GroupsUpdate> groupsUpdateProvider,
SshKeyCache sshKeyCache,
AccountCache accountCache,
AccountByEmailCache byEmailCache,
ExternalIdsUpdate.Server externalIdsUpdate,
@SshEnabled boolean sshEnabled) {
accounts = new HashMap<>();
@ -86,7 +83,6 @@ public class AccountCreator {
this.groupsUpdateProvider = groupsUpdateProvider;
this.sshKeyCache = sshKeyCache;
this.accountCache = accountCache;
this.byEmailCache = byEmailCache;
this.externalIdsUpdate = externalIdsUpdate;
this.sshEnabled = sshEnabled;
}
@ -148,7 +144,6 @@ public class AccountCreator {
if (username != null) {
accountCache.evictByUsername(username);
}
byEmailCache.evict(email);
account = new TestAccount(id, username, email, fullName, sshKey, httpPass);
if (username != null) {

View File

@ -28,7 +28,6 @@ import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.rules.PrologModule;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountByEmailCacheImpl;
import com.google.gerrit.server.account.AccountCacheImpl;
import com.google.gerrit.server.account.AccountVisibility;
import com.google.gerrit.server.account.AccountVisibilityProvider;
@ -157,7 +156,6 @@ public class BatchProgramModule extends FactoryModule {
install(new GroupModule());
install(new NoteDbModule(cfg));
install(new PrologModule());
install(AccountByEmailCacheImpl.module());
install(AccountCacheImpl.module());
install(GroupCacheImpl.module());
install(GroupIncludeCacheImpl.module());

View File

@ -1,25 +0,0 @@
// Copyright (C) 2009 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.account;
import com.google.gerrit.reviewdb.client.Account;
import java.util.Set;
/** Translates an email address to a set of matching accounts. */
public interface AccountByEmailCache {
Set<Account.Id> get(String email);
void evict(String email);
}

View File

@ -1,96 +0,0 @@
// Copyright (C) 2009 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.account;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.account.externalids.ExternalIds;
import com.google.gerrit.server.cache.CacheModule;
import com.google.inject.Inject;
import com.google.inject.Module;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Named;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** Translates an email address to a set of matching accounts. */
@Singleton
public class AccountByEmailCacheImpl implements AccountByEmailCache {
private static final Logger log = LoggerFactory.getLogger(AccountByEmailCacheImpl.class);
private static final String CACHE_NAME = "accounts_byemail";
public static Module module() {
return new CacheModule() {
@Override
protected void configure() {
cache(CACHE_NAME, String.class, new TypeLiteral<Set<Account.Id>>() {}).loader(Loader.class);
bind(AccountByEmailCacheImpl.class);
bind(AccountByEmailCache.class).to(AccountByEmailCacheImpl.class);
}
};
}
private final LoadingCache<String, Set<Account.Id>> cache;
@Inject
AccountByEmailCacheImpl(@Named(CACHE_NAME) LoadingCache<String, Set<Account.Id>> cache) {
this.cache = cache;
}
@Override
public Set<Account.Id> get(String email) {
try {
return cache.get(email);
} catch (ExecutionException e) {
log.warn("Cannot resolve accounts by email", e);
return Collections.emptySet();
}
}
@Override
public void evict(String email) {
if (email != null) {
cache.invalidate(email);
}
}
static class Loader extends CacheLoader<String, Set<Account.Id>> {
// This must be a provider to prevent a cyclic dependency within Google-internal glue code.
private final Provider<ExternalIds> externalIds;
@Inject
Loader(Provider<ExternalIds> externalIds) {
this.externalIds = externalIds;
}
@Override
public Set<Account.Id> load(String email) throws Exception {
return externalIds
.get()
.byEmail(email)
.stream()
.map(e -> e.accountId())
.collect(toImmutableSet());
}
}
}

View File

@ -62,7 +62,6 @@ public class AccountManager {
private final Accounts accounts;
private final AccountsUpdate.Server accountsUpdateFactory;
private final AccountCache byIdCache;
private final AccountByEmailCache byEmailCache;
private final Realm realm;
private final IdentifiedUser.GenericFactory userFactory;
private final ChangeUserName.Factory changeUserNameFactory;
@ -81,7 +80,6 @@ public class AccountManager {
Accounts accounts,
AccountsUpdate.Server accountsUpdateFactory,
AccountCache byIdCache,
AccountByEmailCache byEmailCache,
Realm accountMapper,
IdentifiedUser.GenericFactory userFactory,
ChangeUserName.Factory changeUserNameFactory,
@ -95,7 +93,6 @@ public class AccountManager {
this.accounts = accounts;
this.accountsUpdateFactory = accountsUpdateFactory;
this.byIdCache = byIdCache;
this.byEmailCache = byEmailCache;
this.realm = accountMapper;
this.userFactory = userFactory;
this.changeUserNameFactory = changeUserNameFactory;
@ -197,11 +194,6 @@ public class AccountManager {
throw new OrmException("Account " + user.getAccountId() + " has been deleted");
}
}
if (newEmail != null && !newEmail.equals(oldEmail)) {
byEmailCache.evict(oldEmail);
byEmailCache.evict(newEmail);
}
}
private static boolean eq(String a, String b) {
@ -300,7 +292,6 @@ public class AccountManager {
}
}
byEmailCache.evict(account.getPreferredEmail());
realm.onCreateAccount(who, account);
return new AuthResult(newId, extId.key(), true);
}
@ -383,7 +374,6 @@ public class AccountManager {
a.setPreferredEmail(who.getEmailAddress());
}
});
byEmailCache.evict(who.getEmailAddress());
}
}
@ -481,7 +471,6 @@ public class AccountManager {
}
}
});
extIds.stream().forEach(e -> byEmailCache.evict(e.email()));
}
}
}

View File

@ -69,7 +69,6 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
private final SshKeyCache sshKeyCache;
private final AccountCache accountCache;
private final AccountsUpdate.User accountsUpdate;
private final AccountByEmailCache byEmailCache;
private final AccountLoader.Factory infoLoader;
private final DynamicSet<AccountExternalIdCreator> externalIdCreators;
private final ExternalIds externalIds;
@ -87,7 +86,6 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
SshKeyCache sshKeyCache,
AccountCache accountCache,
AccountsUpdate.User accountsUpdate,
AccountByEmailCache byEmailCache,
AccountLoader.Factory infoLoader,
DynamicSet<AccountExternalIdCreator> externalIdCreators,
ExternalIds externalIds,
@ -102,7 +100,6 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
this.sshKeyCache = sshKeyCache;
this.accountCache = accountCache;
this.accountsUpdate = accountsUpdate;
this.byEmailCache = byEmailCache;
this.infoLoader = infoLoader;
this.externalIdCreators = externalIdCreators;
this.externalIds = externalIds;
@ -202,7 +199,6 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
}
accountCache.evictByUsername(username);
byEmailCache.evict(input.email);
AccountLoader loader = infoLoader.create(true);
AccountInfo info = loader.get(id);

View File

@ -79,7 +79,6 @@ import com.google.gerrit.server.CmdLineParserModule;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.PluginUser;
import com.google.gerrit.server.Sequences;
import com.google.gerrit.server.account.AccountByEmailCacheImpl;
import com.google.gerrit.server.account.AccountCacheImpl;
import com.google.gerrit.server.account.AccountControl;
import com.google.gerrit.server.account.AccountManager;
@ -215,7 +214,6 @@ public class GerritGlobalModule extends FactoryModule {
bind(BlameCache.class).to(BlameCacheImpl.class);
bind(Sequences.class);
install(authModule);
install(AccountByEmailCacheImpl.module());
install(AccountCacheImpl.module());
install(BatchUpdate.module());
install(ChangeKindCacheImpl.module());