@@ -41,17 +41,17 @@ public class MainIndexBuffer implements Closeable
4141{
4242 /**
4343 * Issue #1150:
44- * If the number of files in this buffer is over this threshold, index cache is enabled. 6-8 are tested to be good
45- * settings. This threshold avoids redundant cache+buffer when the number of files is small (i.e., buffer can provide
46- * good lookup performance).
44+ * If the number of files in this buffer is over this threshold, synchronous cache population is enabled.
45+ * 6-8 are tested to be good settings. This threshold avoids redundant cache population when the number of files
46+ * is small (i.e., the buffer can be used as a cache and provide good lookup performance).
4747 */
48- private static final int CACHE_ENABLE_THRESHOLD = 6 ;
48+ private static final int CACHE_POP_ENABLE_THRESHOLD = 6 ;
4949 /**
5050 * fileId -> {tableRowId -> rowLocation}.
5151 */
5252 private final Map <Long , Map <Long , IndexProto .RowLocation >> indexBuffer ;
5353 private final MainIndexCache indexCache ;
54- private boolean enableCache = false ;
54+ private boolean populateCache = false ;
5555
5656 /**
5757 * Create a main index buffer and bind the main index cache to it.
@@ -75,14 +75,14 @@ public boolean insert(long rowId, IndexProto.RowLocation location)
7575 Map <Long , IndexProto .RowLocation > fileBuffer = this .indexBuffer .get (location .getFileId ());
7676 if (fileBuffer == null )
7777 {
78- if (this .indexBuffer .size () > CACHE_ENABLE_THRESHOLD )
78+ if (this .indexBuffer .size () > CACHE_POP_ENABLE_THRESHOLD )
7979 {
80- this .enableCache = true ;
80+ this .populateCache = true ;
8181 }
8282 // Issue #1115: use HashMap for better performance and do post-sorting in flush().
8383 fileBuffer = new HashMap <>();
8484 fileBuffer .put (rowId , location );
85- if (this .enableCache )
85+ if (this .populateCache )
8686 {
8787 this .indexCache .admit (rowId , location );
8888 }
@@ -94,7 +94,7 @@ public boolean insert(long rowId, IndexProto.RowLocation location)
9494 if (!fileBuffer .containsKey (rowId ))
9595 {
9696 fileBuffer .put (rowId , location );
97- if (this .enableCache )
97+ if (this .populateCache )
9898 {
9999 this .indexCache .admit (rowId , location );
100100 }
@@ -112,7 +112,7 @@ protected IndexProto.RowLocation lookup(long fileId, long rowId) throws MainInde
112112 return null ;
113113 }
114114 IndexProto .RowLocation location = fileBuffer .get (rowId );
115- if (location == null && ! this . enableCache )
115+ if (location == null )
116116 {
117117 location = this .indexCache .lookup (rowId );
118118 }
@@ -126,10 +126,7 @@ protected IndexProto.RowLocation lookup(long fileId, long rowId) throws MainInde
126126 public IndexProto .RowLocation lookup (long rowId ) throws MainIndexException
127127 {
128128 IndexProto .RowLocation location = null ;
129- if (this .enableCache )
130- {
131- location = this .indexCache .lookup (rowId );
132- }
129+ location = this .indexCache .lookup (rowId );
133130 if (location == null )
134131 {
135132 for (Map .Entry <Long , Map <Long , IndexProto .RowLocation >> entry : this .indexBuffer .entrySet ())
@@ -149,8 +146,8 @@ public IndexProto.RowLocation lookup(long rowId) throws MainIndexException
149146 /**
150147 * Flush the (row id -> row location) mappings of the given file id into ranges and remove them from the buffer.
151148 * This method does not evict the main index cache bind to this buffer as the cached entries are not out of date.
152- * However, this method may disable and clear the cache if remaining file ids in the buffer is below or equals to
153- * the {@link #CACHE_ENABLE_THRESHOLD }.
149+ * However, this method may disable synchronous cache population and clear the cache if remaining file ids in the
150+ * buffer is below or equals to the {@link #CACHE_POP_ENABLE_THRESHOLD }.
154151 * @param fileId the given file id to flush
155152 * @return the flushed row id ranges to be persisited into the storage
156153 * @throws MainIndexException
@@ -213,9 +210,9 @@ public List<RowIdRange> flush(long fileId) throws MainIndexException
213210 // release the flushed file index buffer
214211 fileBuffer .clear ();
215212 this .indexBuffer .remove (fileId );
216- if (this .indexBuffer .size () <= CACHE_ENABLE_THRESHOLD )
213+ if (this .indexBuffer .size () <= CACHE_POP_ENABLE_THRESHOLD )
217214 {
218- this .enableCache = false ;
215+ this .populateCache = false ;
219216 this .indexCache .evictAllEntries ();
220217 }
221218 return ranges .build ();
0 commit comments