@@ -125,7 +125,7 @@ public class CacheConfig implements PropagatingConfigurationObserver {
125125 private volatile boolean cacheDataOnRead ;
126126
127127 /** Whether blocks should be flagged as in-memory when being cached */
128- private final boolean inMemory ;
128+ private boolean inMemory ;
129129
130130 /** Whether data blocks should be cached when new files are written */
131131 private volatile boolean cacheDataOnWrite ;
@@ -140,28 +140,29 @@ public class CacheConfig implements PropagatingConfigurationObserver {
140140 private volatile boolean evictOnClose ;
141141
142142 /** Whether data blocks should be stored in compressed and/or encrypted form in the cache */
143- private final boolean cacheDataCompressed ;
143+ private boolean cacheDataCompressed ;
144144
145145 /** Whether data blocks should be prefetched into the cache */
146- private final boolean prefetchOnOpen ;
146+ private boolean prefetchOnOpen ;
147147
148148 /**
149149 * Whether data blocks should be cached when compacted file is written
150150 */
151- private final boolean cacheCompactedDataOnWrite ;
151+ private boolean cacheCompactedDataOnWrite ;
152152
153153 /**
154154 * Determine threshold beyond which we do not cache blocks on compaction
155155 */
156156 private long cacheCompactedDataOnWriteThreshold ;
157157
158- private final boolean dropBehindCompaction ;
158+ private boolean dropBehindCompaction ;
159159
160160 // Local reference to the block cache
161161 private final BlockCache blockCache ;
162162
163163 private final ByteBuffAllocator byteBuffAllocator ;
164164
165+
165166 /**
166167 * Create a cache configuration using the specified configuration object and defaults for family
167168 * level settings. Only use if no column family context.
@@ -182,30 +183,32 @@ public CacheConfig(Configuration conf, BlockCache blockCache) {
182183 */
183184 public CacheConfig (Configuration conf , ColumnFamilyDescriptor family , BlockCache blockCache ,
184185 ByteBuffAllocator byteBuffAllocator ) {
185- this .cacheDataOnRead = conf .getBoolean (CACHE_DATA_ON_READ_KEY , DEFAULT_CACHE_DATA_ON_READ )
186- && (family == null ? true : family .isBlockCacheEnabled ());
187- this .inMemory = family == null ? DEFAULT_IN_MEMORY : family .isInMemory ();
188- this .cacheDataCompressed =
189- conf .getBoolean (CACHE_DATA_BLOCKS_COMPRESSED_KEY , DEFAULT_CACHE_DATA_COMPRESSED );
190- this .dropBehindCompaction =
191- conf .getBoolean (DROP_BEHIND_CACHE_COMPACTION_KEY , DROP_BEHIND_CACHE_COMPACTION_DEFAULT );
192- // For the following flags we enable them regardless of per-schema settings
193- // if they are enabled in the global configuration.
194- this .cacheDataOnWrite = conf .getBoolean (CACHE_BLOCKS_ON_WRITE_KEY , DEFAULT_CACHE_DATA_ON_WRITE )
195- || (family == null ? false : family .isCacheDataOnWrite ());
196- this .cacheIndexesOnWrite =
197- conf .getBoolean (CACHE_INDEX_BLOCKS_ON_WRITE_KEY , DEFAULT_CACHE_INDEXES_ON_WRITE )
198- || (family == null ? false : family .isCacheIndexesOnWrite ());
199- this .cacheBloomsOnWrite =
200- conf .getBoolean (CACHE_BLOOM_BLOCKS_ON_WRITE_KEY , DEFAULT_CACHE_BLOOMS_ON_WRITE )
201- || (family == null ? false : family .isCacheBloomsOnWrite ());
202- this .evictOnClose = conf .getBoolean (EVICT_BLOCKS_ON_CLOSE_KEY , DEFAULT_EVICT_ON_CLOSE )
203- || (family == null ? false : family .isEvictBlocksOnClose ());
204- this .prefetchOnOpen = conf .getBoolean (PREFETCH_BLOCKS_ON_OPEN_KEY , DEFAULT_PREFETCH_ON_OPEN )
205- || (family == null ? false : family .isPrefetchBlocksOnOpen ());
206- this .cacheCompactedDataOnWrite =
207- conf .getBoolean (CACHE_COMPACTED_BLOCKS_ON_WRITE_KEY , DEFAULT_CACHE_COMPACTED_BLOCKS_ON_WRITE );
208- this .cacheCompactedDataOnWriteThreshold = getCacheCompactedBlocksOnWriteThreshold (conf );
186+ if (family == null || family .isBlockCacheEnabled ()) {
187+ this .cacheDataOnRead = conf .getBoolean (CACHE_DATA_ON_READ_KEY , DEFAULT_CACHE_DATA_ON_READ );
188+ this .inMemory = family == null ? DEFAULT_IN_MEMORY : family .isInMemory ();
189+ this .cacheDataCompressed =
190+ conf .getBoolean (CACHE_DATA_BLOCKS_COMPRESSED_KEY , DEFAULT_CACHE_DATA_COMPRESSED );
191+ this .dropBehindCompaction =
192+ conf .getBoolean (DROP_BEHIND_CACHE_COMPACTION_KEY , DROP_BEHIND_CACHE_COMPACTION_DEFAULT );
193+ // For the following flags we enable them regardless of per-schema settings
194+ // if they are enabled in the global configuration.
195+ this .cacheDataOnWrite =
196+ conf .getBoolean (CACHE_BLOCKS_ON_WRITE_KEY , DEFAULT_CACHE_DATA_ON_WRITE )
197+ || (family == null ? false : family .isCacheDataOnWrite ());
198+ this .cacheIndexesOnWrite =
199+ conf .getBoolean (CACHE_INDEX_BLOCKS_ON_WRITE_KEY , DEFAULT_CACHE_INDEXES_ON_WRITE )
200+ || (family == null ? false : family .isCacheIndexesOnWrite ());
201+ this .cacheBloomsOnWrite =
202+ conf .getBoolean (CACHE_BLOOM_BLOCKS_ON_WRITE_KEY , DEFAULT_CACHE_BLOOMS_ON_WRITE )
203+ || (family == null ? false : family .isCacheBloomsOnWrite ());
204+ this .evictOnClose = conf .getBoolean (EVICT_BLOCKS_ON_CLOSE_KEY , DEFAULT_EVICT_ON_CLOSE )
205+ || (family == null ? false : family .isEvictBlocksOnClose ());
206+ this .prefetchOnOpen = conf .getBoolean (PREFETCH_BLOCKS_ON_OPEN_KEY , DEFAULT_PREFETCH_ON_OPEN )
207+ || (family == null ? false : family .isPrefetchBlocksOnOpen ());
208+ this .cacheCompactedDataOnWrite = conf .getBoolean (CACHE_COMPACTED_BLOCKS_ON_WRITE_KEY ,
209+ DEFAULT_CACHE_COMPACTED_BLOCKS_ON_WRITE );
210+ this .cacheCompactedDataOnWriteThreshold = getCacheCompactedBlocksOnWriteThreshold (conf );
211+ }
209212 this .blockCache = blockCache ;
210213 this .byteBuffAllocator = byteBuffAllocator ;
211214 }
0 commit comments