Skip to content

Commit 05073b4

Browse files
author
“shenghui361”
committed
Avoid caching invalid entity (null entiry) into memory, thus avoiding triggering additional evictions
1 parent f3e40ba commit 05073b4

File tree

1 file changed

+13
-12
lines changed
  • core/server/master/src/main/java/alluxio/master/metastore/caching

1 file changed

+13
-12
lines changed

core/server/master/src/main/java/alluxio/master/metastore/caching/Cache.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,22 @@ private Optional<V> getSkipCache(K key) {
176176
* @param value the value
177177
*/
178178
public void put(K key, V value) {
179-
mMap.compute(key, (k, entry) -> {
180-
onPut(key, value);
181-
if (entry == null && cacheIsFull()) {
182-
writeToBackingStore(key, value);
183-
return null;
184-
}
185-
if (entry == null || entry.mValue == null) {
186-
onCacheUpdate(key, value);
187-
return new Entry(key, value);
188-
}
179+
onPut(key, value);
180+
Entry entry = mMap.get(key);
181+
if(entry == null && cacheIsFull()) {
182+
writeToBackingStore(key, value);
183+
return;
184+
}
185+
186+
if (entry == null || entry.mValue == null) {
187+
onCacheUpdate(key, value);
188+
entry = new Entry(key, value);
189+
} else {
189190
entry.mValue = value;
190191
entry.mReferenced = true;
191192
entry.mDirty = true;
192-
return entry;
193-
});
193+
}
194+
mMap.put(key, entry);
194195
wakeEvictionThreadIfNecessary();
195196
}
196197

0 commit comments

Comments
 (0)