AccountCache#evictAll(): Remove indexing and rename it to evictAllNoReindex()
Evicting an account from the account cache by the evict(Account.Id) method implies that the account is reindexed. Hence the expectation for evictAll() was that it would reindex all accounts, however this was not working, since AccountCacheimpl#evictAll was first removing all accounts from the cache and then it iterated over the empty cache to do the reindexing. Even if we would have saved all cached accounts in a local variable before emptying the cache this would have only reindexed accounts that were cached, but not all accounts. Since all caller of evictAll() don't need reindexing of all accounts, but only dropping of all entries from the cache, the reindexing logic is removed from evictAll() and the method is renamed to evictAllNoReindex() to make this clear. The single caller (besides test code) is updating the default preferences and must evict all accounts from the cache because the general preferences are part of the Account instances in the cache, however non of the fields in the account index uses the preferences, hence reindex is not needed. Change-Id: If461ea914a15bc962486628bbc8478654d520f39 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
parent
ced6f32e86
commit
3015c22f07
@ -66,7 +66,7 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
|
||||
assertThat(u.delete()).isEqualTo(RefUpdate.Result.FORCED);
|
||||
}
|
||||
}
|
||||
accountCache.evictAll();
|
||||
accountCache.evictAllNoReindex();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -41,7 +41,7 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
|
||||
assertThat(u.delete()).isEqualTo(RefUpdate.Result.FORCED);
|
||||
}
|
||||
}
|
||||
accountCache.evictAll();
|
||||
accountCache.evictAllNoReindex();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -44,9 +44,16 @@ public interface AccountCache {
|
||||
|
||||
AccountState getByUsername(String username);
|
||||
|
||||
/**
|
||||
* Evicts the account from the cache and triggers a reindex for it.
|
||||
*
|
||||
* @param accountId account ID of the account that should be evicted
|
||||
* @throws IOException thrown if reindexing fails
|
||||
*/
|
||||
void evict(Account.Id accountId) throws IOException;
|
||||
|
||||
void evictByUsername(String username);
|
||||
|
||||
void evictAll() throws IOException;
|
||||
/** Evict all accounts from the cache, but doesn't trigger reindex of all accounts. */
|
||||
void evictAllNoReindex();
|
||||
}
|
||||
|
@ -130,11 +130,8 @@ public class AccountCacheImpl implements AccountCache {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evictAll() throws IOException {
|
||||
public void evictAllNoReindex() {
|
||||
byId.invalidateAll();
|
||||
for (Account.Id accountId : byId.asMap().keySet()) {
|
||||
indexer.get().index(accountId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,7 +85,7 @@ public class SetPreferences implements RestModifyView<ConfigResource, GeneralPre
|
||||
com.google.gerrit.server.account.SetPreferences.storeUrlAliases(p, i.urlAliases);
|
||||
p.commit(md);
|
||||
|
||||
accountCache.evictAll();
|
||||
accountCache.evictAllNoReindex();
|
||||
|
||||
GeneralPreferencesInfo r =
|
||||
loadSection(
|
||||
|
@ -64,7 +64,7 @@ public class FakeAccountCache implements AccountCache {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void evictAll() {
|
||||
public synchronized void evictAllNoReindex() {
|
||||
byId.clear();
|
||||
byUsername.clear();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user