@@ -500,6 +500,7 @@ public boolean maybeFetchFullEntry(
500500 ActionListener <Void > listener
501501 ) {
502502 int finalRegion = getEndingRegion (length );
503+ // TODO freeRegionCount uses freeRegions.size() which is is NOT a constant-time operation. Can we do better?
503504 if (freeRegionCount () < finalRegion ) {
504505 // Not enough room to download a full file without evicting existing data, so abort
505506 listener .onResponse (null );
@@ -571,7 +572,7 @@ public void maybeFetchRegion(
571572 final Executor fetchExecutor ,
572573 final ActionListener <Boolean > listener
573574 ) {
574- if (freeRegionCount () < 1 && maybeEvictLeastUsed () == false ) {
575+ if (freeRegions . isEmpty () && maybeEvictLeastUsed () == false ) {
575576 // no free page available and no old enough unused region to be evicted
576577 logger .info ("No free regions, skipping loading region [{}]" , region );
577578 listener .onResponse (false );
@@ -619,7 +620,7 @@ public void maybeFetchRange(
619620 final Executor fetchExecutor ,
620621 final ActionListener <Boolean > listener
621622 ) {
622- if (freeRegionCount () < 1 && maybeEvictLeastUsed () == false ) {
623+ if (freeRegions . isEmpty () && maybeEvictLeastUsed () == false ) {
623624 // no free page available and no old enough unused region to be evicted
624625 logger .info ("No free regions, skipping loading region [{}]" , region );
625626 listener .onResponse (false );
@@ -671,7 +672,11 @@ private static void throwAlreadyClosed(String message) {
671672 throw new AlreadyClosedException (message );
672673 }
673674
674- // used by tests
675+ /**
676+ * NOTE: Method is package private mostly to allow checking the number of fee regions in tests.
677+ * However, it is also used by {@link SharedBlobCacheService#maybeFetchFullEntry} but we should try
678+ * to move away from that because calling "size" on a ConcurrentLinkedQueue is not a constant time operation.
679+ */
675680 int freeRegionCount () {
676681 return freeRegions .size ();
677682 }
0 commit comments