diff --git a/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/keyvalue/api/cache/TransactionScopedCacheImpl.java b/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/keyvalue/api/cache/TransactionScopedCacheImpl.java index ce6f7557422..19bf6abf6fd 100644 --- a/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/keyvalue/api/cache/TransactionScopedCacheImpl.java +++ b/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/keyvalue/api/cache/TransactionScopedCacheImpl.java @@ -99,8 +99,8 @@ public ListenableFuture> getAsync( } else { return Futures.transform( valueLoader.apply(cacheLookup.missedCells()), - remoteReadValues -> processRemoteRead( - tableReference, cacheLookup.cacheHits(), cacheLookup.missedCells(), remoteReadValues), + uncachedValues -> processUncachedCells( + tableReference, cacheLookup.cacheHits(), cacheLookup.missedCells(), uncachedValues), MoreExecutors.directExecutor()); } } @@ -138,14 +138,16 @@ public NavigableMap> getRows( metrics.increaseGetRowsCellLookups(missedCells.size()); metrics.increaseGetRowsRowLookups(completelyMissedRows.size()); - Map remoteDirectRead = missedCells.isEmpty() ? ImmutableMap.of() : cellLoader.apply(missedCells); - Map cellLookups = processRemoteRead(tableRef, cached.cacheHits(), missedCells, remoteDirectRead); + Map uncachedCellsDirectRead = + missedCells.isEmpty() ? ImmutableMap.of() : cellLoader.apply(missedCells); + Map cellLookups = + processUncachedCells(tableRef, cached.cacheHits(), missedCells, uncachedCellsDirectRead); - NavigableMap> remoteRowRead = completelyMissedRows.isEmpty() + NavigableMap> uncachedRows = completelyMissedRows.isEmpty() ? new TreeMap<>(UnsignedBytes.lexicographicalComparator()) : rowLoader.apply(completelyMissedRows); NavigableMap> rowReads = - processRemoteReadRows(tableRef, completelyMissedRowsCells, remoteRowRead); + processUncachedRows(tableRef, completelyMissedRowsCells, uncachedRows); rowReads.putAll(RowResults.viewOfSortedMap(Cells.breakCellsUpByRow(cellLookups))); return rowReads; @@ -188,7 +190,16 @@ private void ensureNotFinalised() { } } - private synchronized Map processRemoteRead( + /** + * Processes values that were loaded from the value loader due to not being present in the cache at the time. + * Note that: + * - these may not necessarily be remote values: local writes may be read, but this is abstracted away from this + * cache as these are read through a regular {@link com.palantir.atlasdb.transaction.impl.SnapshotTransaction} + * read; + * - it is possible to read some values from the KVS that then become out of date due to local writes; these will + * not end up in the cache due to the use of {@link Map#putIfAbsent(Object, Object)} inside the value store. + */ + private synchronized Map processUncachedCells( TableReference tableReference, Map cacheHits, Set cacheMisses, @@ -201,7 +212,7 @@ private synchronized Map processRemoteRead( .build(); } - private synchronized NavigableMap> processRemoteReadRows( + private synchronized NavigableMap> processUncachedRows( TableReference tableReference, Set cacheMisses, Map> remoteReadValues) { Map rowsReadAsCells = remoteReadValues.values().stream() .map(RowResult::getCells)