Make sure to never use cached values when indexing accounts

This change does the same for accounts what was done for groups by
change I0b281d7b72.

Indexed accounts are retrieved from the account cache. As the account
cache may possibly have stale entries, we have to be careful not to use
outdated values. All code paths which referred to the AccountIndexer
correctly invalidated the account cache. Requiring the cache evictions
in other classes is a bit dangerous, though.

This situation becomes even worse with the recently added
AccountIndexer#reindexIfStale method (see change I66d5bb09e4). Whether
the account index is stale is determined by comparing the account stored
in the index with the one stored in NoteDb. For updating a stale index
entry, we didn't ensure that the account was freshly read from NoteDb.
This means that users of AccountIndexer#reindexIfStale which care about
up-to-date values would need to manually invalidate the cache, which
would trigger an indexing without the stale check, and hence make the
call to AccountIndexer#reindexIfStale obsolete. Alternatively, they
would need to accept outdated values without any guarantee when they are
updated.

To prevent future errors due to missing cache invalidations and to allow
calling AccountIndexer#index and AccountIndexer#reindexIfStale even with
stale caches, we explicitly use a non-cached value for indexing now.

As the necessity for manual cache evictions is removed, it makes sense
in other parts of the code to not indirectly trigger an indexing for an
account by evicting it from the cache but to explicitly call the
indexer.

As a result, evicting an element from the cache doesn't need to trigger
an indexing anymore. It would also have created an infinite loop for the
new eviction in the indexer.

Since the AccountCache is no longer doing any reindex on eviction, we
can now rename AccountCache#evictAllNoReindex() to
AccountCache#evictAll().

For AllAccountsIndexer, there was even a possibly unintended
side-effect: The cache invalidation triggered an indirect indexing for
the account before the account was retrieved from the cache and
explicitly put in the index. The adjusted code should avoid this
situation by doing all interaction with the index in AllAccountsIndexer.

We also use the opportunity to add some tests for the AccountIndexer and
the adjusted behavior.

Change-Id: I8eba8b0c5e1d65ad63c15970275b2a597d475c9d
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-03-12 11:26:40 +01:00
parent 05c36a0ad0
commit 06c328d5a2
18 changed files with 306 additions and 59 deletions

View File

@@ -322,7 +322,7 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
}
private TestAccount evictAndCopy(TestAccount account) throws IOException {
accountCache.evict(account.id);
evictAndReindexAccount(account.id);
return account;
}