@@ -119,7 +119,6 @@ public class ChunkCache
119119
120120 // File id management
121121 private final ConcurrentHashMap <File , Long > fileIdMap = new ConcurrentHashMap <>();
122- private final ConcurrentHashMap <Long , File > idToFileMap = new ConcurrentHashMap <>();
123122 private final AtomicLong nextFileId = new AtomicLong (0 );
124123
125124 // number of bits required to store the log2 of the chunk size
@@ -271,7 +270,6 @@ protected long readerIdFor(ChunkReader source)
271270 private long assignFileId (File file )
272271 {
273272 long id = nextFileId .getAndIncrement ();
274- idToFileMap .put (id , file );
275273 return id ;
276274 }
277275
@@ -288,11 +286,7 @@ public void invalidateFile(File file)
288286 {
289287 // Removing the name from the id map suffices -- the next time someone wants to read this file, it will get
290288 // assigned a fresh id.
291- Long id = fileIdMap .remove (file );
292- if (id != null )
293- {
294- idToFileMap .remove (id );
295- }
289+ fileIdMap .remove (file );
296290 }
297291
298292 /**
@@ -807,8 +801,6 @@ public String toString()
807801 return String .format ("Chunk{file='%s', pos=%d, size=%d}" , file , position , size );
808802 }
809803 }
810-
811-
812804 /**
813805 * Inspects the "hottest" (most frequently/recently used) chunks in the cache.
814806 * Uses a consumer pattern to avoid materializing a full list in memory.
@@ -856,7 +848,12 @@ private void inspectCacheSegments(int limit, boolean hottest, java.util.function
856848 // this operation discards the rightmost 5 bits (ChunkSize + ReaderType) leaving just FileID:42
857849 long fileId = key .readerId >>> shift ;
858850
859- File file = idToFileMap .get (fileId );
851+ // Look up the File by searching through fileIdMap entries
852+ File file = fileIdMap .entrySet ().stream ()
853+ .filter (e -> e .getValue ().equals (fileId ))
854+ .map (Map .Entry ::getKey )
855+ .findFirst ()
856+ .orElse (null );
860857
861858 // Skip if we can't find the file (it may have been invalidated)
862859 if (file == null )
@@ -865,5 +862,5 @@ private void inspectCacheSegments(int limit, boolean hottest, java.util.function
865862 consumer .accept (new ChunkCacheInspectionEntry (file , key .position , chunk .capacity ()));
866863 });
867864 });
868- }
865+ }
869866}
0 commit comments