http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6b4bae59/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/CacheConfig.ExternalBlockCaches.html
----------------------------------------------------------------------
diff --git
a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/CacheConfig.ExternalBlockCaches.html
b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/CacheConfig.ExternalBlockCaches.html
index ad83c55..bff0679 100644
---
a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/CacheConfig.ExternalBlockCaches.html
+++
b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/CacheConfig.ExternalBlockCaches.html
@@ -291,435 +291,436 @@
<span class="sourceLineNo">283</span> }<a name="line.283"></a>
<span class="sourceLineNo">284</span><a name="line.284"></a>
<span class="sourceLineNo">285</span> /**<a name="line.285"></a>
-<span class="sourceLineNo">286</span> * Create a block cache configuration
with the specified cache and<a name="line.286"></a>
-<span class="sourceLineNo">287</span> * configuration parameters.<a
name="line.287"></a>
-<span class="sourceLineNo">288</span> * @param blockCache reference to block
cache, null if completely disabled<a name="line.288"></a>
-<span class="sourceLineNo">289</span> * @param cacheDataOnRead whether DATA
blocks should be cached on read (we always cache INDEX<a name="line.289"></a>
-<span class="sourceLineNo">290</span> * blocks and BLOOM blocks; this cannot
be disabled).<a name="line.290"></a>
-<span class="sourceLineNo">291</span> * @param inMemory whether blocks
should be flagged as in-memory<a name="line.291"></a>
-<span class="sourceLineNo">292</span> * @param cacheDataOnWrite whether data
blocks should be cached on write<a name="line.292"></a>
-<span class="sourceLineNo">293</span> * @param cacheIndexesOnWrite whether
index blocks should be cached on write<a name="line.293"></a>
-<span class="sourceLineNo">294</span> * @param cacheBloomsOnWrite whether
blooms should be cached on write<a name="line.294"></a>
-<span class="sourceLineNo">295</span> * @param evictOnClose whether blocks
should be evicted when HFile is closed<a name="line.295"></a>
-<span class="sourceLineNo">296</span> * @param cacheDataCompressed whether
to store blocks as compressed in the cache<a name="line.296"></a>
-<span class="sourceLineNo">297</span> * @param prefetchOnOpen whether to
prefetch blocks upon open<a name="line.297"></a>
-<span class="sourceLineNo">298</span> * @param cacheDataInL1 If more than
one cache tier deployed, if true, cache this column families<a
name="line.298"></a>
-<span class="sourceLineNo">299</span> * data blocks up in the L1 tier.<a
name="line.299"></a>
-<span class="sourceLineNo">300</span> */<a name="line.300"></a>
-<span class="sourceLineNo">301</span> CacheConfig(final BlockCache
blockCache,<a name="line.301"></a>
-<span class="sourceLineNo">302</span> final boolean cacheDataOnRead,
final boolean inMemory,<a name="line.302"></a>
-<span class="sourceLineNo">303</span> final boolean cacheDataOnWrite,
final boolean cacheIndexesOnWrite,<a name="line.303"></a>
-<span class="sourceLineNo">304</span> final boolean cacheBloomsOnWrite,
final boolean evictOnClose,<a name="line.304"></a>
-<span class="sourceLineNo">305</span> final boolean cacheDataCompressed,
final boolean prefetchOnOpen,<a name="line.305"></a>
-<span class="sourceLineNo">306</span> final boolean cacheDataInL1, final
boolean dropBehindCompaction) {<a name="line.306"></a>
-<span class="sourceLineNo">307</span> this.blockCache = blockCache;<a
name="line.307"></a>
-<span class="sourceLineNo">308</span> this.cacheDataOnRead =
cacheDataOnRead;<a name="line.308"></a>
-<span class="sourceLineNo">309</span> this.inMemory = inMemory;<a
name="line.309"></a>
-<span class="sourceLineNo">310</span> this.cacheDataOnWrite =
cacheDataOnWrite;<a name="line.310"></a>
-<span class="sourceLineNo">311</span> this.cacheIndexesOnWrite =
cacheIndexesOnWrite;<a name="line.311"></a>
-<span class="sourceLineNo">312</span> this.cacheBloomsOnWrite =
cacheBloomsOnWrite;<a name="line.312"></a>
-<span class="sourceLineNo">313</span> this.evictOnClose = evictOnClose;<a
name="line.313"></a>
-<span class="sourceLineNo">314</span> this.cacheDataCompressed =
cacheDataCompressed;<a name="line.314"></a>
-<span class="sourceLineNo">315</span> this.prefetchOnOpen =
prefetchOnOpen;<a name="line.315"></a>
-<span class="sourceLineNo">316</span> this.cacheDataInL1 = cacheDataInL1;<a
name="line.316"></a>
-<span class="sourceLineNo">317</span> this.dropBehindCompaction =
dropBehindCompaction;<a name="line.317"></a>
-<span class="sourceLineNo">318</span> }<a name="line.318"></a>
-<span class="sourceLineNo">319</span><a name="line.319"></a>
-<span class="sourceLineNo">320</span> /**<a name="line.320"></a>
-<span class="sourceLineNo">321</span> * Constructs a cache configuration
copied from the specified configuration.<a name="line.321"></a>
-<span class="sourceLineNo">322</span> * @param cacheConf<a
name="line.322"></a>
-<span class="sourceLineNo">323</span> */<a name="line.323"></a>
-<span class="sourceLineNo">324</span> public CacheConfig(CacheConfig
cacheConf) {<a name="line.324"></a>
-<span class="sourceLineNo">325</span> this(cacheConf.blockCache,
cacheConf.cacheDataOnRead, cacheConf.inMemory,<a name="line.325"></a>
-<span class="sourceLineNo">326</span> cacheConf.cacheDataOnWrite,
cacheConf.cacheIndexesOnWrite,<a name="line.326"></a>
-<span class="sourceLineNo">327</span> cacheConf.cacheBloomsOnWrite,
cacheConf.evictOnClose,<a name="line.327"></a>
-<span class="sourceLineNo">328</span> cacheConf.cacheDataCompressed,
cacheConf.prefetchOnOpen,<a name="line.328"></a>
-<span class="sourceLineNo">329</span> cacheConf.cacheDataInL1,
cacheConf.dropBehindCompaction);<a name="line.329"></a>
-<span class="sourceLineNo">330</span> }<a name="line.330"></a>
-<span class="sourceLineNo">331</span><a name="line.331"></a>
-<span class="sourceLineNo">332</span> private CacheConfig() {<a
name="line.332"></a>
-<span class="sourceLineNo">333</span> this(null, false, false, false,
false, false,<a name="line.333"></a>
-<span class="sourceLineNo">334</span> false, false, false,
false, false);<a name="line.334"></a>
-<span class="sourceLineNo">335</span> }<a name="line.335"></a>
-<span class="sourceLineNo">336</span><a name="line.336"></a>
-<span class="sourceLineNo">337</span> /**<a name="line.337"></a>
-<span class="sourceLineNo">338</span> * Checks whether the block cache is
enabled.<a name="line.338"></a>
-<span class="sourceLineNo">339</span> */<a name="line.339"></a>
-<span class="sourceLineNo">340</span> public boolean isBlockCacheEnabled()
{<a name="line.340"></a>
-<span class="sourceLineNo">341</span> return this.blockCache != null;<a
name="line.341"></a>
-<span class="sourceLineNo">342</span> }<a name="line.342"></a>
-<span class="sourceLineNo">343</span><a name="line.343"></a>
-<span class="sourceLineNo">344</span> /**<a name="line.344"></a>
-<span class="sourceLineNo">345</span> * Returns the block cache.<a
name="line.345"></a>
-<span class="sourceLineNo">346</span> * @return the block cache, or null if
caching is completely disabled<a name="line.346"></a>
-<span class="sourceLineNo">347</span> */<a name="line.347"></a>
-<span class="sourceLineNo">348</span> public BlockCache getBlockCache() {<a
name="line.348"></a>
-<span class="sourceLineNo">349</span> return this.blockCache;<a
name="line.349"></a>
-<span class="sourceLineNo">350</span> }<a name="line.350"></a>
-<span class="sourceLineNo">351</span><a name="line.351"></a>
-<span class="sourceLineNo">352</span> /**<a name="line.352"></a>
-<span class="sourceLineNo">353</span> * Returns whether the DATA blocks of
this HFile should be cached on read or not (we always<a name="line.353"></a>
-<span class="sourceLineNo">354</span> * cache the meta blocks, the INDEX and
BLOOM blocks).<a name="line.354"></a>
-<span class="sourceLineNo">355</span> * @return true if blocks should be
cached on read, false if not<a name="line.355"></a>
-<span class="sourceLineNo">356</span> */<a name="line.356"></a>
-<span class="sourceLineNo">357</span> public boolean shouldCacheDataOnRead()
{<a name="line.357"></a>
-<span class="sourceLineNo">358</span> return isBlockCacheEnabled()
&& cacheDataOnRead;<a name="line.358"></a>
-<span class="sourceLineNo">359</span> }<a name="line.359"></a>
-<span class="sourceLineNo">360</span><a name="line.360"></a>
-<span class="sourceLineNo">361</span> public boolean
shouldDropBehindCompaction() {<a name="line.361"></a>
-<span class="sourceLineNo">362</span> return dropBehindCompaction;<a
name="line.362"></a>
-<span class="sourceLineNo">363</span> }<a name="line.363"></a>
-<span class="sourceLineNo">364</span><a name="line.364"></a>
-<span class="sourceLineNo">365</span> /**<a name="line.365"></a>
-<span class="sourceLineNo">366</span> * Should we cache a block of a
particular category? We always cache<a name="line.366"></a>
-<span class="sourceLineNo">367</span> * important blocks such as index
blocks, as long as the block cache is<a name="line.367"></a>
-<span class="sourceLineNo">368</span> * available.<a name="line.368"></a>
-<span class="sourceLineNo">369</span> */<a name="line.369"></a>
-<span class="sourceLineNo">370</span> public boolean
shouldCacheBlockOnRead(BlockCategory category) {<a name="line.370"></a>
-<span class="sourceLineNo">371</span> return isBlockCacheEnabled()<a
name="line.371"></a>
-<span class="sourceLineNo">372</span> && (cacheDataOnRead ||<a
name="line.372"></a>
-<span class="sourceLineNo">373</span> category ==
BlockCategory.INDEX ||<a name="line.373"></a>
-<span class="sourceLineNo">374</span> category ==
BlockCategory.BLOOM ||<a name="line.374"></a>
-<span class="sourceLineNo">375</span> (prefetchOnOpen &&<a
name="line.375"></a>
-<span class="sourceLineNo">376</span> (category !=
BlockCategory.META &&<a name="line.376"></a>
-<span class="sourceLineNo">377</span> category !=
BlockCategory.UNKNOWN)));<a name="line.377"></a>
-<span class="sourceLineNo">378</span> }<a name="line.378"></a>
-<span class="sourceLineNo">379</span><a name="line.379"></a>
-<span class="sourceLineNo">380</span> /**<a name="line.380"></a>
-<span class="sourceLineNo">381</span> * @return true if blocks in this file
should be flagged as in-memory<a name="line.381"></a>
-<span class="sourceLineNo">382</span> */<a name="line.382"></a>
-<span class="sourceLineNo">383</span> public boolean isInMemory() {<a
name="line.383"></a>
-<span class="sourceLineNo">384</span> return isBlockCacheEnabled()
&& this.inMemory;<a name="line.384"></a>
-<span class="sourceLineNo">385</span> }<a name="line.385"></a>
-<span class="sourceLineNo">386</span><a name="line.386"></a>
-<span class="sourceLineNo">387</span> /**<a name="line.387"></a>
-<span class="sourceLineNo">388</span> * @return True if cache data blocks in
L1 tier (if more than one tier in block cache deploy).<a name="line.388"></a>
-<span class="sourceLineNo">389</span> */<a name="line.389"></a>
-<span class="sourceLineNo">390</span> public boolean isCacheDataInL1() {<a
name="line.390"></a>
-<span class="sourceLineNo">391</span> return isBlockCacheEnabled()
&& this.cacheDataInL1;<a name="line.391"></a>
-<span class="sourceLineNo">392</span> }<a name="line.392"></a>
-<span class="sourceLineNo">393</span><a name="line.393"></a>
-<span class="sourceLineNo">394</span> /**<a name="line.394"></a>
-<span class="sourceLineNo">395</span> * @return true if data blocks should
be written to the cache when an HFile is<a name="line.395"></a>
-<span class="sourceLineNo">396</span> * written, false if not<a
name="line.396"></a>
-<span class="sourceLineNo">397</span> */<a name="line.397"></a>
-<span class="sourceLineNo">398</span> public boolean shouldCacheDataOnWrite()
{<a name="line.398"></a>
-<span class="sourceLineNo">399</span> return isBlockCacheEnabled()
&& this.cacheDataOnWrite;<a name="line.399"></a>
-<span class="sourceLineNo">400</span> }<a name="line.400"></a>
-<span class="sourceLineNo">401</span><a name="line.401"></a>
-<span class="sourceLineNo">402</span> /**<a name="line.402"></a>
-<span class="sourceLineNo">403</span> * Only used for testing.<a
name="line.403"></a>
-<span class="sourceLineNo">404</span> * @param cacheDataOnWrite whether data
blocks should be written to the cache<a name="line.404"></a>
-<span class="sourceLineNo">405</span> * when an
HFile is written<a name="line.405"></a>
-<span class="sourceLineNo">406</span> */<a name="line.406"></a>
-<span class="sourceLineNo">407</span> @VisibleForTesting<a
name="line.407"></a>
-<span class="sourceLineNo">408</span> public void setCacheDataOnWrite(boolean
cacheDataOnWrite) {<a name="line.408"></a>
-<span class="sourceLineNo">409</span> this.cacheDataOnWrite =
cacheDataOnWrite;<a name="line.409"></a>
-<span class="sourceLineNo">410</span> }<a name="line.410"></a>
-<span class="sourceLineNo">411</span><a name="line.411"></a>
-<span class="sourceLineNo">412</span> /**<a name="line.412"></a>
-<span class="sourceLineNo">413</span> * Only used for testing.<a
name="line.413"></a>
-<span class="sourceLineNo">414</span> * @param cacheDataInL1 Whether to
cache data blocks up in l1 (if a multi-tier cache<a name="line.414"></a>
-<span class="sourceLineNo">415</span> * implementation).<a
name="line.415"></a>
-<span class="sourceLineNo">416</span> */<a name="line.416"></a>
-<span class="sourceLineNo">417</span> @VisibleForTesting<a
name="line.417"></a>
-<span class="sourceLineNo">418</span> public void setCacheDataInL1(boolean
cacheDataInL1) {<a name="line.418"></a>
-<span class="sourceLineNo">419</span> this.cacheDataInL1 = cacheDataInL1;<a
name="line.419"></a>
-<span class="sourceLineNo">420</span> }<a name="line.420"></a>
-<span class="sourceLineNo">421</span><a name="line.421"></a>
-<span class="sourceLineNo">422</span> /**<a name="line.422"></a>
-<span class="sourceLineNo">423</span> * @return true if index blocks should
be written to the cache when an HFile<a name="line.423"></a>
-<span class="sourceLineNo">424</span> * is written, false if not<a
name="line.424"></a>
-<span class="sourceLineNo">425</span> */<a name="line.425"></a>
-<span class="sourceLineNo">426</span> public boolean
shouldCacheIndexesOnWrite() {<a name="line.426"></a>
-<span class="sourceLineNo">427</span> return isBlockCacheEnabled()
&& this.cacheIndexesOnWrite;<a name="line.427"></a>
-<span class="sourceLineNo">428</span> }<a name="line.428"></a>
-<span class="sourceLineNo">429</span><a name="line.429"></a>
-<span class="sourceLineNo">430</span> /**<a name="line.430"></a>
-<span class="sourceLineNo">431</span> * @return true if bloom blocks should
be written to the cache when an HFile<a name="line.431"></a>
-<span class="sourceLineNo">432</span> * is written, false if not<a
name="line.432"></a>
-<span class="sourceLineNo">433</span> */<a name="line.433"></a>
-<span class="sourceLineNo">434</span> public boolean
shouldCacheBloomsOnWrite() {<a name="line.434"></a>
-<span class="sourceLineNo">435</span> return isBlockCacheEnabled()
&& this.cacheBloomsOnWrite;<a name="line.435"></a>
-<span class="sourceLineNo">436</span> }<a name="line.436"></a>
-<span class="sourceLineNo">437</span><a name="line.437"></a>
-<span class="sourceLineNo">438</span> /**<a name="line.438"></a>
-<span class="sourceLineNo">439</span> * @return true if blocks should be
evicted from the cache when an HFile<a name="line.439"></a>
-<span class="sourceLineNo">440</span> * reader is closed, false if
not<a name="line.440"></a>
-<span class="sourceLineNo">441</span> */<a name="line.441"></a>
-<span class="sourceLineNo">442</span> public boolean shouldEvictOnClose() {<a
name="line.442"></a>
-<span class="sourceLineNo">443</span> return isBlockCacheEnabled()
&& this.evictOnClose;<a name="line.443"></a>
-<span class="sourceLineNo">444</span> }<a name="line.444"></a>
-<span class="sourceLineNo">445</span><a name="line.445"></a>
-<span class="sourceLineNo">446</span> /**<a name="line.446"></a>
-<span class="sourceLineNo">447</span> * Only used for testing.<a
name="line.447"></a>
-<span class="sourceLineNo">448</span> * @param evictOnClose whether blocks
should be evicted from the cache when an<a name="line.448"></a>
-<span class="sourceLineNo">449</span> * HFile reader is
closed<a name="line.449"></a>
-<span class="sourceLineNo">450</span> */<a name="line.450"></a>
-<span class="sourceLineNo">451</span> public void setEvictOnClose(boolean
evictOnClose) {<a name="line.451"></a>
-<span class="sourceLineNo">452</span> this.evictOnClose = evictOnClose;<a
name="line.452"></a>
-<span class="sourceLineNo">453</span> }<a name="line.453"></a>
-<span class="sourceLineNo">454</span><a name="line.454"></a>
-<span class="sourceLineNo">455</span> /**<a name="line.455"></a>
-<span class="sourceLineNo">456</span> * @return true if data blocks should
be compressed in the cache, false if not<a name="line.456"></a>
-<span class="sourceLineNo">457</span> */<a name="line.457"></a>
-<span class="sourceLineNo">458</span> public boolean
shouldCacheDataCompressed() {<a name="line.458"></a>
-<span class="sourceLineNo">459</span> return isBlockCacheEnabled()
&& this.cacheDataOnRead && this.cacheDataCompressed;<a
name="line.459"></a>
-<span class="sourceLineNo">460</span> }<a name="line.460"></a>
-<span class="sourceLineNo">461</span><a name="line.461"></a>
-<span class="sourceLineNo">462</span> /**<a name="line.462"></a>
-<span class="sourceLineNo">463</span> * @return true if this {@link
BlockCategory} should be compressed in blockcache, false otherwise<a
name="line.463"></a>
-<span class="sourceLineNo">464</span> */<a name="line.464"></a>
-<span class="sourceLineNo">465</span> public boolean
shouldCacheCompressed(BlockCategory category) {<a name="line.465"></a>
-<span class="sourceLineNo">466</span> if (!isBlockCacheEnabled()) return
false;<a name="line.466"></a>
-<span class="sourceLineNo">467</span> switch (category) {<a
name="line.467"></a>
-<span class="sourceLineNo">468</span> case DATA:<a name="line.468"></a>
-<span class="sourceLineNo">469</span> return this.cacheDataOnRead
&& this.cacheDataCompressed;<a name="line.469"></a>
-<span class="sourceLineNo">470</span> default:<a name="line.470"></a>
-<span class="sourceLineNo">471</span> return false;<a
name="line.471"></a>
-<span class="sourceLineNo">472</span> }<a name="line.472"></a>
-<span class="sourceLineNo">473</span> }<a name="line.473"></a>
-<span class="sourceLineNo">474</span><a name="line.474"></a>
-<span class="sourceLineNo">475</span> /**<a name="line.475"></a>
-<span class="sourceLineNo">476</span> * @return true if blocks should be
prefetched into the cache on open, false if not<a name="line.476"></a>
-<span class="sourceLineNo">477</span> */<a name="line.477"></a>
-<span class="sourceLineNo">478</span> public boolean shouldPrefetchOnOpen()
{<a name="line.478"></a>
-<span class="sourceLineNo">479</span> return isBlockCacheEnabled()
&& this.prefetchOnOpen;<a name="line.479"></a>
-<span class="sourceLineNo">480</span> }<a name="line.480"></a>
-<span class="sourceLineNo">481</span><a name="line.481"></a>
-<span class="sourceLineNo">482</span> /**<a name="line.482"></a>
-<span class="sourceLineNo">483</span> * Return true if we may find this type
of block in block cache.<a name="line.483"></a>
-<span class="sourceLineNo">484</span> * <p><a name="line.484"></a>
-<span class="sourceLineNo">485</span> * TODO: today {@code
family.isBlockCacheEnabled()} only means {@code cacheDataOnRead}, so here we<a
name="line.485"></a>
-<span class="sourceLineNo">486</span> * consider lots of other
configurations such as {@code cacheDataOnWrite}. We should fix this in<a
name="line.486"></a>
-<span class="sourceLineNo">487</span> * the future, {@code cacheDataOnWrite}
should honor the CF level {@code isBlockCacheEnabled}<a name="line.487"></a>
-<span class="sourceLineNo">488</span> * configuration.<a name="line.488"></a>
-<span class="sourceLineNo">489</span> */<a name="line.489"></a>
-<span class="sourceLineNo">490</span> public boolean
shouldReadBlockFromCache(BlockType blockType) {<a name="line.490"></a>
-<span class="sourceLineNo">491</span> if (!isBlockCacheEnabled()) {<a
name="line.491"></a>
-<span class="sourceLineNo">492</span> return false;<a name="line.492"></a>
-<span class="sourceLineNo">493</span> }<a name="line.493"></a>
-<span class="sourceLineNo">494</span> if (cacheDataOnRead) {<a
name="line.494"></a>
-<span class="sourceLineNo">495</span> return true;<a name="line.495"></a>
-<span class="sourceLineNo">496</span> }<a name="line.496"></a>
-<span class="sourceLineNo">497</span> if (prefetchOnOpen) {<a
name="line.497"></a>
-<span class="sourceLineNo">498</span> return true;<a name="line.498"></a>
-<span class="sourceLineNo">499</span> }<a name="line.499"></a>
-<span class="sourceLineNo">500</span> if (cacheDataOnWrite) {<a
name="line.500"></a>
-<span class="sourceLineNo">501</span> return true;<a name="line.501"></a>
-<span class="sourceLineNo">502</span> }<a name="line.502"></a>
-<span class="sourceLineNo">503</span> if (blockType == null) {<a
name="line.503"></a>
-<span class="sourceLineNo">504</span> return true;<a name="line.504"></a>
-<span class="sourceLineNo">505</span> }<a name="line.505"></a>
-<span class="sourceLineNo">506</span> if (blockType.getCategory() ==
BlockCategory.BLOOM ||<a name="line.506"></a>
-<span class="sourceLineNo">507</span> blockType.getCategory() ==
BlockCategory.INDEX) {<a name="line.507"></a>
-<span class="sourceLineNo">508</span> return true;<a name="line.508"></a>
-<span class="sourceLineNo">509</span> }<a name="line.509"></a>
-<span class="sourceLineNo">510</span> return false;<a name="line.510"></a>
-<span class="sourceLineNo">511</span> }<a name="line.511"></a>
-<span class="sourceLineNo">512</span><a name="line.512"></a>
-<span class="sourceLineNo">513</span> /**<a name="line.513"></a>
-<span class="sourceLineNo">514</span> * If we make sure the block could not
be cached, we will not acquire the lock<a name="line.514"></a>
-<span class="sourceLineNo">515</span> * otherwise we will acquire lock<a
name="line.515"></a>
-<span class="sourceLineNo">516</span> */<a name="line.516"></a>
-<span class="sourceLineNo">517</span> public boolean
shouldLockOnCacheMiss(BlockType blockType) {<a name="line.517"></a>
-<span class="sourceLineNo">518</span> if (blockType == null) {<a
name="line.518"></a>
-<span class="sourceLineNo">519</span> return true;<a name="line.519"></a>
-<span class="sourceLineNo">520</span> }<a name="line.520"></a>
-<span class="sourceLineNo">521</span> return
shouldCacheBlockOnRead(blockType.getCategory());<a name="line.521"></a>
-<span class="sourceLineNo">522</span> }<a name="line.522"></a>
-<span class="sourceLineNo">523</span><a name="line.523"></a>
-<span class="sourceLineNo">524</span> @Override<a name="line.524"></a>
-<span class="sourceLineNo">525</span> public String toString() {<a
name="line.525"></a>
-<span class="sourceLineNo">526</span> if (!isBlockCacheEnabled()) {<a
name="line.526"></a>
-<span class="sourceLineNo">527</span> return "CacheConfig:disabled";<a
name="line.527"></a>
-<span class="sourceLineNo">528</span> }<a name="line.528"></a>
-<span class="sourceLineNo">529</span> return "blockCache=" +
getBlockCache() +<a name="line.529"></a>
-<span class="sourceLineNo">530</span> ", cacheDataOnRead=" +
shouldCacheDataOnRead() +<a name="line.530"></a>
-<span class="sourceLineNo">531</span> ", cacheDataOnWrite=" +
shouldCacheDataOnWrite() +<a name="line.531"></a>
-<span class="sourceLineNo">532</span> ", cacheIndexesOnWrite=" +
shouldCacheIndexesOnWrite() +<a name="line.532"></a>
-<span class="sourceLineNo">533</span> ", cacheBloomsOnWrite=" +
shouldCacheBloomsOnWrite() +<a name="line.533"></a>
-<span class="sourceLineNo">534</span> ", cacheEvictOnClose=" +
shouldEvictOnClose() +<a name="line.534"></a>
-<span class="sourceLineNo">535</span> ", cacheDataCompressed=" +
shouldCacheDataCompressed() +<a name="line.535"></a>
-<span class="sourceLineNo">536</span> ", prefetchOnOpen=" +
shouldPrefetchOnOpen();<a name="line.536"></a>
-<span class="sourceLineNo">537</span> }<a name="line.537"></a>
-<span class="sourceLineNo">538</span><a name="line.538"></a>
-<span class="sourceLineNo">539</span> // Static block cache reference and
methods<a name="line.539"></a>
-<span class="sourceLineNo">540</span><a name="line.540"></a>
-<span class="sourceLineNo">541</span> /**<a name="line.541"></a>
-<span class="sourceLineNo">542</span> * Static reference to the block cache,
or null if no caching should be used<a name="line.542"></a>
-<span class="sourceLineNo">543</span> * at all.<a name="line.543"></a>
-<span class="sourceLineNo">544</span> */<a name="line.544"></a>
-<span class="sourceLineNo">545</span> // Clear this if in tests you'd make
more than one block cache instance.<a name="line.545"></a>
-<span class="sourceLineNo">546</span> @VisibleForTesting<a
name="line.546"></a>
-<span class="sourceLineNo">547</span> static BlockCache
GLOBAL_BLOCK_CACHE_INSTANCE;<a name="line.547"></a>
-<span class="sourceLineNo">548</span> private static LruBlockCache
GLOBAL_L1_CACHE_INSTANCE;<a name="line.548"></a>
-<span class="sourceLineNo">549</span><a name="line.549"></a>
-<span class="sourceLineNo">550</span> /** Boolean whether we have disabled
the block cache entirely. */<a name="line.550"></a>
-<span class="sourceLineNo">551</span> @VisibleForTesting<a
name="line.551"></a>
-<span class="sourceLineNo">552</span> static boolean blockCacheDisabled =
false;<a name="line.552"></a>
-<span class="sourceLineNo">553</span><a name="line.553"></a>
-<span class="sourceLineNo">554</span> /**<a name="line.554"></a>
-<span class="sourceLineNo">555</span> * @param c Configuration to use.<a
name="line.555"></a>
-<span class="sourceLineNo">556</span> * @return An L1 instance. Currently
an instance of LruBlockCache.<a name="line.556"></a>
-<span class="sourceLineNo">557</span> */<a name="line.557"></a>
-<span class="sourceLineNo">558</span> public static LruBlockCache getL1(final
Configuration c) {<a name="line.558"></a>
-<span class="sourceLineNo">559</span> return getL1Internal(c);<a
name="line.559"></a>
-<span class="sourceLineNo">560</span> }<a name="line.560"></a>
-<span class="sourceLineNo">561</span><a name="line.561"></a>
-<span class="sourceLineNo">562</span> /**<a name="line.562"></a>
-<span class="sourceLineNo">563</span> * @param c Configuration to use.<a
name="line.563"></a>
-<span class="sourceLineNo">564</span> * @return An L1 instance. Currently
an instance of LruBlockCache.<a name="line.564"></a>
-<span class="sourceLineNo">565</span> */<a name="line.565"></a>
-<span class="sourceLineNo">566</span> private synchronized static
LruBlockCache getL1Internal(final Configuration c) {<a name="line.566"></a>
-<span class="sourceLineNo">567</span> if (GLOBAL_L1_CACHE_INSTANCE != null)
return GLOBAL_L1_CACHE_INSTANCE;<a name="line.567"></a>
-<span class="sourceLineNo">568</span> final long lruCacheSize =
MemorySizeUtil.getLruCacheSize(c);<a name="line.568"></a>
-<span class="sourceLineNo">569</span> if (lruCacheSize < 0) {<a
name="line.569"></a>
-<span class="sourceLineNo">570</span> blockCacheDisabled = true;<a
name="line.570"></a>
-<span class="sourceLineNo">571</span> }<a name="line.571"></a>
-<span class="sourceLineNo">572</span> if (blockCacheDisabled) return
null;<a name="line.572"></a>
-<span class="sourceLineNo">573</span> int blockSize =
c.getInt(BLOCKCACHE_BLOCKSIZE_KEY, HConstants.DEFAULT_BLOCKSIZE);<a
name="line.573"></a>
-<span class="sourceLineNo">574</span> LOG.info("Allocating LruBlockCache
size=" +<a name="line.574"></a>
-<span class="sourceLineNo">575</span> StringUtils.byteDesc(lruCacheSize)
+ ", blockSize=" + StringUtils.byteDesc(blockSize));<a name="line.575"></a>
-<span class="sourceLineNo">576</span> GLOBAL_L1_CACHE_INSTANCE = new
LruBlockCache(lruCacheSize, blockSize, true, c);<a name="line.576"></a>
-<span class="sourceLineNo">577</span> return GLOBAL_L1_CACHE_INSTANCE;<a
name="line.577"></a>
-<span class="sourceLineNo">578</span> }<a name="line.578"></a>
-<span class="sourceLineNo">579</span><a name="line.579"></a>
-<span class="sourceLineNo">580</span> /**<a name="line.580"></a>
-<span class="sourceLineNo">581</span> * @param c Configuration to use.<a
name="line.581"></a>
-<span class="sourceLineNo">582</span> * @return Returns L2 block cache
instance (for now it is BucketCache BlockCache all the time)<a
name="line.582"></a>
-<span class="sourceLineNo">583</span> * or null if not supposed to be a
L2.<a name="line.583"></a>
-<span class="sourceLineNo">584</span> */<a name="line.584"></a>
-<span class="sourceLineNo">585</span> private static BlockCache getL2(final
Configuration c) {<a name="line.585"></a>
-<span class="sourceLineNo">586</span> final boolean useExternal =
c.getBoolean(EXTERNAL_BLOCKCACHE_KEY, EXTERNAL_BLOCKCACHE_DEFAULT);<a
name="line.586"></a>
-<span class="sourceLineNo">587</span> if (LOG.isDebugEnabled()) {<a
name="line.587"></a>
-<span class="sourceLineNo">588</span> LOG.debug("Trying to use " +
(useExternal?" External":" Internal") + " l2 cache");<a name="line.588"></a>
-<span class="sourceLineNo">589</span> }<a name="line.589"></a>
-<span class="sourceLineNo">590</span><a name="line.590"></a>
-<span class="sourceLineNo">591</span> // If we want to use an external
block cache then create that.<a name="line.591"></a>
-<span class="sourceLineNo">592</span> if (useExternal) {<a
name="line.592"></a>
-<span class="sourceLineNo">593</span> return getExternalBlockcache(c);<a
name="line.593"></a>
-<span class="sourceLineNo">594</span> }<a name="line.594"></a>
-<span class="sourceLineNo">595</span><a name="line.595"></a>
-<span class="sourceLineNo">596</span> // otherwise use the bucket cache.<a
name="line.596"></a>
-<span class="sourceLineNo">597</span> return getBucketCache(c);<a
name="line.597"></a>
-<span class="sourceLineNo">598</span><a name="line.598"></a>
-<span class="sourceLineNo">599</span> }<a name="line.599"></a>
-<span class="sourceLineNo">600</span><a name="line.600"></a>
-<span class="sourceLineNo">601</span> private static BlockCache
getExternalBlockcache(Configuration c) {<a name="line.601"></a>
-<span class="sourceLineNo">602</span> Class klass = null;<a
name="line.602"></a>
-<span class="sourceLineNo">603</span><a name="line.603"></a>
-<span class="sourceLineNo">604</span> // Get the class, from the config.
s<a name="line.604"></a>
-<span class="sourceLineNo">605</span> try {<a name="line.605"></a>
-<span class="sourceLineNo">606</span> klass =
ExternalBlockCaches.valueOf(c.get(EXTERNAL_BLOCKCACHE_CLASS_KEY,
"memcache")).clazz;<a name="line.606"></a>
-<span class="sourceLineNo">607</span> } catch (IllegalArgumentException
exception) {<a name="line.607"></a>
-<span class="sourceLineNo">608</span> try {<a name="line.608"></a>
-<span class="sourceLineNo">609</span> klass =
c.getClass(EXTERNAL_BLOCKCACHE_CLASS_KEY, Class.forName(<a name="line.609"></a>
-<span class="sourceLineNo">610</span>
"org.apache.hadoop.hbase.io.hfile.MemcachedBlockCache"));<a name="line.610"></a>
-<span class="sourceLineNo">611</span> } catch (ClassNotFoundException e)
{<a name="line.611"></a>
-<span class="sourceLineNo">612</span> return null;<a
name="line.612"></a>
-<span class="sourceLineNo">613</span> }<a name="line.613"></a>
-<span class="sourceLineNo">614</span> }<a name="line.614"></a>
-<span class="sourceLineNo">615</span><a name="line.615"></a>
-<span class="sourceLineNo">616</span> // Now try and create an instance of
the block cache.<a name="line.616"></a>
-<span class="sourceLineNo">617</span> try {<a name="line.617"></a>
-<span class="sourceLineNo">618</span> LOG.info("Creating external block
cache of type: " + klass);<a name="line.618"></a>
-<span class="sourceLineNo">619</span> return (BlockCache)
ReflectionUtils.newInstance(klass, c);<a name="line.619"></a>
-<span class="sourceLineNo">620</span> } catch (Exception e) {<a
name="line.620"></a>
-<span class="sourceLineNo">621</span> LOG.warn("Error creating external
block cache", e);<a name="line.621"></a>
-<span class="sourceLineNo">622</span> }<a name="line.622"></a>
-<span class="sourceLineNo">623</span> return null;<a name="line.623"></a>
-<span class="sourceLineNo">624</span><a name="line.624"></a>
-<span class="sourceLineNo">625</span> }<a name="line.625"></a>
-<span class="sourceLineNo">626</span><a name="line.626"></a>
-<span class="sourceLineNo">627</span> private static BlockCache
getBucketCache(Configuration c) {<a name="line.627"></a>
-<span class="sourceLineNo">628</span> // Check for L2. ioengine name must
be non-null.<a name="line.628"></a>
-<span class="sourceLineNo">629</span> String bucketCacheIOEngineName =
c.get(BUCKET_CACHE_IOENGINE_KEY, null);<a name="line.629"></a>
-<span class="sourceLineNo">630</span> if (bucketCacheIOEngineName == null
|| bucketCacheIOEngineName.length() <= 0) return null;<a name="line.630"></a>
-<span class="sourceLineNo">631</span><a name="line.631"></a>
-<span class="sourceLineNo">632</span> int blockSize =
c.getInt(BLOCKCACHE_BLOCKSIZE_KEY, HConstants.DEFAULT_BLOCKSIZE);<a
name="line.632"></a>
-<span class="sourceLineNo">633</span> final long bucketCacheSize =
MemorySizeUtil.getBucketCacheSize(c);<a name="line.633"></a>
-<span class="sourceLineNo">634</span> if (bucketCacheSize <= 0) {<a
name="line.634"></a>
-<span class="sourceLineNo">635</span> throw new
IllegalStateException("bucketCacheSize <= 0; Check " +<a name="line.635"></a>
-<span class="sourceLineNo">636</span> BUCKET_CACHE_SIZE_KEY + " setting
and/or server java heap size");<a name="line.636"></a>
-<span class="sourceLineNo">637</span> }<a name="line.637"></a>
-<span class="sourceLineNo">638</span> if
(c.get("hbase.bucketcache.percentage.in.combinedcache") != null) {<a
name="line.638"></a>
-<span class="sourceLineNo">639</span> LOG.warn("Configuration
'hbase.bucketcache.percentage.in.combinedcache' is no longer "<a
name="line.639"></a>
-<span class="sourceLineNo">640</span> + "respected. See comments in
http://hbase.apache.org/book.html#_changes_of_note");<a name="line.640"></a>
-<span class="sourceLineNo">641</span> }<a name="line.641"></a>
-<span class="sourceLineNo">642</span> int writerThreads =
c.getInt(BUCKET_CACHE_WRITER_THREADS_KEY,<a name="line.642"></a>
-<span class="sourceLineNo">643</span>
DEFAULT_BUCKET_CACHE_WRITER_THREADS);<a name="line.643"></a>
-<span class="sourceLineNo">644</span> int writerQueueLen =
c.getInt(BUCKET_CACHE_WRITER_QUEUE_KEY,<a name="line.644"></a>
-<span class="sourceLineNo">645</span>
DEFAULT_BUCKET_CACHE_WRITER_QUEUE);<a name="line.645"></a>
-<span class="sourceLineNo">646</span> String persistentPath =
c.get(BUCKET_CACHE_PERSISTENT_PATH_KEY);<a name="line.646"></a>
-<span class="sourceLineNo">647</span> String[] configuredBucketSizes =
c.getStrings(BUCKET_CACHE_BUCKETS_KEY);<a name="line.647"></a>
-<span class="sourceLineNo">648</span> int [] bucketSizes = null;<a
name="line.648"></a>
-<span class="sourceLineNo">649</span> if (configuredBucketSizes != null)
{<a name="line.649"></a>
-<span class="sourceLineNo">650</span> bucketSizes = new
int[configuredBucketSizes.length];<a name="line.650"></a>
-<span class="sourceLineNo">651</span> for (int i = 0; i <
configuredBucketSizes.length; i++) {<a name="line.651"></a>
-<span class="sourceLineNo">652</span> bucketSizes[i] =
Integer.parseInt(configuredBucketSizes[i].trim());<a name="line.652"></a>
-<span class="sourceLineNo">653</span> }<a name="line.653"></a>
-<span class="sourceLineNo">654</span> }<a name="line.654"></a>
-<span class="sourceLineNo">655</span> BucketCache bucketCache = null;<a
name="line.655"></a>
-<span class="sourceLineNo">656</span> try {<a name="line.656"></a>
-<span class="sourceLineNo">657</span> int ioErrorsTolerationDuration =
c.getInt(<a name="line.657"></a>
-<span class="sourceLineNo">658</span>
"hbase.bucketcache.ioengine.errors.tolerated.duration",<a name="line.658"></a>
-<span class="sourceLineNo">659</span>
BucketCache.DEFAULT_ERROR_TOLERATION_DURATION);<a name="line.659"></a>
-<span class="sourceLineNo">660</span> // Bucket cache logs its stats on
creation internal to the constructor.<a name="line.660"></a>
-<span class="sourceLineNo">661</span> bucketCache = new
BucketCache(bucketCacheIOEngineName,<a name="line.661"></a>
-<span class="sourceLineNo">662</span> bucketCacheSize, blockSize,
bucketSizes, writerThreads, writerQueueLen, persistentPath,<a
name="line.662"></a>
-<span class="sourceLineNo">663</span> ioErrorsTolerationDuration);<a
name="line.663"></a>
-<span class="sourceLineNo">664</span> } catch (IOException ioex) {<a
name="line.664"></a>
-<span class="sourceLineNo">665</span> LOG.error("Can't instantiate bucket
cache", ioex); throw new RuntimeException(ioex);<a name="line.665"></a>
-<span class="sourceLineNo">666</span> }<a name="line.666"></a>
-<span class="sourceLineNo">667</span> return bucketCache;<a
name="line.667"></a>
-<span class="sourceLineNo">668</span> }<a name="line.668"></a>
-<span class="sourceLineNo">669</span><a name="line.669"></a>
-<span class="sourceLineNo">670</span> /**<a name="line.670"></a>
-<span class="sourceLineNo">671</span> * Returns the block cache or
<code>null</code> in case none should be used.<a
name="line.671"></a>
-<span class="sourceLineNo">672</span> * Sets GLOBAL_BLOCK_CACHE_INSTANCE<a
name="line.672"></a>
-<span class="sourceLineNo">673</span> *<a name="line.673"></a>
-<span class="sourceLineNo">674</span> * @param conf The current
configuration.<a name="line.674"></a>
-<span class="sourceLineNo">675</span> * @return The block cache or
<code>null</code>.<a name="line.675"></a>
-<span class="sourceLineNo">676</span> */<a name="line.676"></a>
-<span class="sourceLineNo">677</span> public static synchronized BlockCache
instantiateBlockCache(Configuration conf) {<a name="line.677"></a>
-<span class="sourceLineNo">678</span> if (GLOBAL_BLOCK_CACHE_INSTANCE !=
null) return GLOBAL_BLOCK_CACHE_INSTANCE;<a name="line.678"></a>
-<span class="sourceLineNo">679</span> if (blockCacheDisabled) return
null;<a name="line.679"></a>
-<span class="sourceLineNo">680</span> LruBlockCache l1 =
getL1Internal(conf);<a name="line.680"></a>
-<span class="sourceLineNo">681</span> // blockCacheDisabled is set as a
side-effect of getL1Internal(), so check it again after the call.<a
name="line.681"></a>
-<span class="sourceLineNo">682</span> if (blockCacheDisabled) return
null;<a name="line.682"></a>
-<span class="sourceLineNo">683</span> BlockCache l2 = getL2(conf);<a
name="line.683"></a>
-<span class="sourceLineNo">684</span> if (l2 == null) {<a
name="line.684"></a>
-<span class="sourceLineNo">685</span> GLOBAL_BLOCK_CACHE_INSTANCE = l1;<a
name="line.685"></a>
-<span class="sourceLineNo">686</span> } else {<a name="line.686"></a>
-<span class="sourceLineNo">687</span> boolean useExternal =
conf.getBoolean(EXTERNAL_BLOCKCACHE_KEY, EXTERNAL_BLOCKCACHE_DEFAULT);<a
name="line.687"></a>
-<span class="sourceLineNo">688</span> boolean combinedWithLru =
conf.getBoolean(BUCKET_CACHE_COMBINED_KEY,<a name="line.688"></a>
-<span class="sourceLineNo">689</span> DEFAULT_BUCKET_CACHE_COMBINED);<a
name="line.689"></a>
-<span class="sourceLineNo">690</span> if (useExternal) {<a
name="line.690"></a>
-<span class="sourceLineNo">691</span> GLOBAL_BLOCK_CACHE_INSTANCE = new
InclusiveCombinedBlockCache(l1, l2);<a name="line.691"></a>
-<span class="sourceLineNo">692</span> } else {<a name="line.692"></a>
-<span class="sourceLineNo">693</span> if (combinedWithLru) {<a
name="line.693"></a>
-<span class="sourceLineNo">694</span> GLOBAL_BLOCK_CACHE_INSTANCE =
new CombinedBlockCache(l1, l2);<a name="line.694"></a>
-<span class="sourceLineNo">695</span> } else {<a name="line.695"></a>
-<span class="sourceLineNo">696</span> // L1 and L2 are not
'combined'. They are connected via the LruBlockCache victimhandler<a
name="line.696"></a>
-<span class="sourceLineNo">697</span> // mechanism. It is a little
ugly but works according to the following: when the<a name="line.697"></a>
-<span class="sourceLineNo">698</span> // background eviction thread
runs, blocks evicted from L1 will go to L2 AND when we get<a
name="line.698"></a>
-<span class="sourceLineNo">699</span> // a block from the L1 cache,
if not in L1, we will search L2.<a name="line.699"></a>
-<span class="sourceLineNo">700</span> GLOBAL_BLOCK_CACHE_INSTANCE =
l1;<a name="line.700"></a>
-<span class="sourceLineNo">701</span> }<a name="line.701"></a>
-<span class="sourceLineNo">702</span> }<a name="line.702"></a>
-<span class="sourceLineNo">703</span> l1.setVictimCache(l2);<a
name="line.703"></a>
-<span class="sourceLineNo">704</span> }<a name="line.704"></a>
-<span class="sourceLineNo">705</span> return GLOBAL_BLOCK_CACHE_INSTANCE;<a
name="line.705"></a>
-<span class="sourceLineNo">706</span> }<a name="line.706"></a>
-<span class="sourceLineNo">707</span><a name="line.707"></a>
-<span class="sourceLineNo">708</span> // Supposed to use only from tests.
Some tests want to reinit the Global block cache instance<a name="line.708"></a>
-<span class="sourceLineNo">709</span> @VisibleForTesting<a
name="line.709"></a>
-<span class="sourceLineNo">710</span> static synchronized void
clearGlobalInstances() {<a name="line.710"></a>
-<span class="sourceLineNo">711</span> GLOBAL_L1_CACHE_INSTANCE = null;<a
name="line.711"></a>
-<span class="sourceLineNo">712</span> GLOBAL_BLOCK_CACHE_INSTANCE = null;<a
name="line.712"></a>
-<span class="sourceLineNo">713</span> }<a name="line.713"></a>
-<span class="sourceLineNo">714</span>}<a name="line.714"></a>
+<span class="sourceLineNo">286</span> * Create a block cache configuration
with the specified cache and configuration parameters.<a name="line.286"></a>
+<span class="sourceLineNo">287</span> * @param blockCache reference to block
cache, null if completely disabled<a name="line.287"></a>
+<span class="sourceLineNo">288</span> * @param cacheDataOnRead whether DATA
blocks should be cached on read (we always cache INDEX<a name="line.288"></a>
+<span class="sourceLineNo">289</span> * blocks and BLOOM blocks;
this cannot be disabled).<a name="line.289"></a>
+<span class="sourceLineNo">290</span> * @param inMemory whether blocks
should be flagged as in-memory<a name="line.290"></a>
+<span class="sourceLineNo">291</span> * @param cacheDataOnWrite whether data
blocks should be cached on write<a name="line.291"></a>
+<span class="sourceLineNo">292</span> * @param cacheIndexesOnWrite whether
index blocks should be cached on write<a name="line.292"></a>
+<span class="sourceLineNo">293</span> * @param cacheBloomsOnWrite whether
blooms should be cached on write<a name="line.293"></a>
+<span class="sourceLineNo">294</span> * @param evictOnClose whether blocks
should be evicted when HFile is closed<a name="line.294"></a>
+<span class="sourceLineNo">295</span> * @param cacheDataCompressed whether
to store blocks as compressed in the cache<a name="line.295"></a>
+<span class="sourceLineNo">296</span> * @param prefetchOnOpen whether to
prefetch blocks upon open<a name="line.296"></a>
+<span class="sourceLineNo">297</span> * @param cacheDataInL1 If more than
one cache tier deployed, if true, cache this column families<a
name="line.297"></a>
+<span class="sourceLineNo">298</span> * data blocks up in the L1
tier.<a name="line.298"></a>
+<span class="sourceLineNo">299</span> * @param dropBehindCompaction indicate
that we should set drop behind to true when open a store<a name="line.299"></a>
+<span class="sourceLineNo">300</span> * file reader for
compaction<a name="line.300"></a>
+<span class="sourceLineNo">301</span> */<a name="line.301"></a>
+<span class="sourceLineNo">302</span> CacheConfig(final BlockCache
blockCache,<a name="line.302"></a>
+<span class="sourceLineNo">303</span> final boolean cacheDataOnRead,
final boolean inMemory,<a name="line.303"></a>
+<span class="sourceLineNo">304</span> final boolean cacheDataOnWrite,
final boolean cacheIndexesOnWrite,<a name="line.304"></a>
+<span class="sourceLineNo">305</span> final boolean cacheBloomsOnWrite,
final boolean evictOnClose,<a name="line.305"></a>
+<span class="sourceLineNo">306</span> final boolean cacheDataCompressed,
final boolean prefetchOnOpen,<a name="line.306"></a>
+<span class="sourceLineNo">307</span> final boolean cacheDataInL1, final
boolean dropBehindCompaction) {<a name="line.307"></a>
+<span class="sourceLineNo">308</span> this.blockCache = blockCache;<a
name="line.308"></a>
+<span class="sourceLineNo">309</span> this.cacheDataOnRead =
cacheDataOnRead;<a name="line.309"></a>
+<span class="sourceLineNo">310</span> this.inMemory = inMemory;<a
name="line.310"></a>
+<span class="sourceLineNo">311</span> this.cacheDataOnWrite =
cacheDataOnWrite;<a name="line.311"></a>
+<span class="sourceLineNo">312</span> this.cacheIndexesOnWrite =
cacheIndexesOnWrite;<a name="line.312"></a>
+<span class="sourceLineNo">313</span> this.cacheBloomsOnWrite =
cacheBloomsOnWrite;<a name="line.313"></a>
+<span class="sourceLineNo">314</span> this.evictOnClose = evictOnClose;<a
name="line.314"></a>
+<span class="sourceLineNo">315</span> this.cacheDataCompressed =
cacheDataCompressed;<a name="line.315"></a>
+<span class="sourceLineNo">316</span> this.prefetchOnOpen =
prefetchOnOpen;<a name="line.316"></a>
+<span class="sourceLineNo">317</span> this.cacheDataInL1 = cacheDataInL1;<a
name="line.317"></a>
+<span class="sourceLineNo">318</span> this.dropBehindCompaction =
dropBehindCompaction;<a name="line.318"></a>
+<span class="sourceLineNo">319</span> }<a name="line.319"></a>
+<span class="sourceLineNo">320</span><a name="line.320"></a>
+<span class="sourceLineNo">321</span> /**<a name="line.321"></a>
+<span class="sourceLineNo">322</span> * Constructs a cache configuration
copied from the specified configuration.<a name="line.322"></a>
+<span class="sourceLineNo">323</span> * @param cacheConf<a
name="line.323"></a>
+<span class="sourceLineNo">324</span> */<a name="line.324"></a>
+<span class="sourceLineNo">325</span> public CacheConfig(CacheConfig
cacheConf) {<a name="line.325"></a>
+<span class="sourceLineNo">326</span> this(cacheConf.blockCache,
cacheConf.cacheDataOnRead, cacheConf.inMemory,<a name="line.326"></a>
+<span class="sourceLineNo">327</span> cacheConf.cacheDataOnWrite,
cacheConf.cacheIndexesOnWrite,<a name="line.327"></a>
+<span class="sourceLineNo">328</span> cacheConf.cacheBloomsOnWrite,
cacheConf.evictOnClose,<a name="line.328"></a>
+<span class="sourceLineNo">329</span> cacheConf.cacheDataCompressed,
cacheConf.prefetchOnOpen,<a name="line.329"></a>
+<span class="sourceLineNo">330</span> cacheConf.cacheDataInL1,
cacheConf.dropBehindCompaction);<a name="line.330"></a>
+<span class="sourceLineNo">331</span> }<a name="line.331"></a>
+<span class="sourceLineNo">332</span><a name="line.332"></a>
+<span class="sourceLineNo">333</span> private CacheConfig() {<a
name="line.333"></a>
+<span class="sourceLineNo">334</span> this(null, false, false, false,
false, false,<a name="line.334"></a>
+<span class="sourceLineNo">335</span> false, false, false,
false, false);<a name="line.335"></a>
+<span class="sourceLineNo">336</span> }<a name="line.336"></a>
+<span class="sourceLineNo">337</span><a name="line.337"></a>
+<span class="sourceLineNo">338</span> /**<a name="line.338"></a>
+<span class="sourceLineNo">339</span> * Checks whether the block cache is
enabled.<a name="line.339"></a>
+<span class="sourceLineNo">340</span> */<a name="line.340"></a>
+<span class="sourceLineNo">341</span> public boolean isBlockCacheEnabled()
{<a name="line.341"></a>
+<span class="sourceLineNo">342</span> return this.blockCache != null;<a
name="line.342"></a>
+<span class="sourceLineNo">343</span> }<a name="line.343"></a>
+<span class="sourceLineNo">344</span><a name="line.344"></a>
+<span class="sourceLineNo">345</span> /**<a name="line.345"></a>
+<span class="sourceLineNo">346</span> * Returns the block cache.<a
name="line.346"></a>
+<span class="sourceLineNo">347</span> * @return the block cache, or null if
caching is completely disabled<a name="line.347"></a>
+<span class="sourceLineNo">348</span> */<a name="line.348"></a>
+<span class="sourceLineNo">349</span> public BlockCache getBlockCache() {<a
name="line.349"></a>
+<span class="sourceLineNo">350</span> return this.blockCache;<a
name="line.350"></a>
+<span class="sourceLineNo">351</span> }<a name="line.351"></a>
+<span class="sourceLineNo">352</span><a name="line.352"></a>
+<span class="sourceLineNo">353</span> /**<a name="line.353"></a>
+<span class="sourceLineNo">354</span> * Returns whether the DATA blocks of
this HFile should be cached on read or not (we always<a name="line.354"></a>
+<span class="sourceLineNo">355</span> * cache the meta blocks, the INDEX and
BLOOM blocks).<a name="line.355"></a>
+<span class="sourceLineNo">356</span> * @return true if blocks should be
cached on read, false if not<a name="line.356"></a>
+<span class="sourceLineNo">357</span> */<a name="line.357"></a>
+<span class="sourceLineNo">358</span> public boolean shouldCacheDataOnRead()
{<a name="line.358"></a>
+<span class="sourceLineNo">359</span> return isBlockCacheEnabled()
&& cacheDataOnRead;<a name="line.359"></a>
+<span class="sourceLineNo">360</span> }<a name="line.360"></a>
+<span class="sourceLineNo">361</span><a name="line.361"></a>
+<span class="sourceLineNo">362</span> public boolean
shouldDropBehindCompaction() {<a name="line.362"></a>
+<span class="sourceLineNo">363</span> return dropBehindCompaction;<a
name="line.363"></a>
+<span class="sourceLineNo">364</span> }<a name="line.364"></a>
+<span class="sourceLineNo">365</span><a name="line.365"></a>
+<span class="sourceLineNo">366</span> /**<a name="line.366"></a>
+<span class="sourceLineNo">367</span> * Should we cache a block of a
particular category? We always cache<a name="line.367"></a>
+<span class="sourceLineNo">368</span> * important blocks such as index
blocks, as long as the block cache is<a name="line.368"></a>
+<span class="sourceLineNo">369</span> * available.<a name="line.369"></a>
+<span class="sourceLineNo">370</span> */<a name="line.370"></a>
+<span class="sourceLineNo">371</span> public boolean
shouldCacheBlockOnRead(BlockCategory category) {<a name="line.371"></a>
+<span class="sourceLineNo">372</span> return isBlockCacheEnabled()<a
name="line.372"></a>
+<span class="sourceLineNo">373</span> && (cacheDataOnRead ||<a
name="line.373"></a>
+<span class="sourceLineNo">374</span> category ==
BlockCategory.INDEX ||<a name="line.374"></a>
+<span class="sourceLineNo">375</span> category ==
BlockCategory.BLOOM ||<a name="line.375"></a>
+<span class="sourceLineNo">376</span> (prefetchOnOpen &&<a
name="line.376"></a>
+<span class="sourceLineNo">377</span> (category !=
BlockCategory.META &&<a name="line.377"></a>
+<span class="sourceLineNo">378</span> category !=
BlockCategory.UNKNOWN)));<a name="line.378"></a>
+<span class="sourceLineNo">379</span> }<a name="line.379"></a>
+<span class="sourceLineNo">380</span><a name="line.380"></a>
+<span class="sourceLineNo">381</span> /**<a name="line.381"></a>
+<span class="sourceLineNo">382</span> * @return true if blocks in this file
should be flagged as in-memory<a name="line.382"></a>
+<span class="sourceLineNo">383</span> */<a name="line.383"></a>
+<span class="sourceLineNo">384</span> public boolean isInMemory() {<a
name="line.384"></a>
+<span class="sourceLineNo">385</span> return isBlockCacheEnabled()
&& this.inMemory;<a name="line.385"></a>
+<span class="sourceLineNo">386</span> }<a name="line.386"></a>
+<span class="sourceLineNo">387</span><a name="line.387"></a>
+<span class="sourceLineNo">388</span> /**<a name="line.388"></a>
+<span class="sourceLineNo">389</span> * @return True if cache data blocks in
L1 tier (if more than one tier in block cache deploy).<a name="line.389"></a>
+<span class="sourceLineNo">390</span> */<a name="line.390"></a>
+<span class="sourceLineNo">391</span> public boolean isCacheDataInL1() {<a
name="line.391"></a>
+<span class="sourceLineNo">392</span> return isBlockCacheEnabled()
&& this.cacheDataInL1;<a name="line.392"></a>
+<span class="sourceLineNo">393</span> }<a name="line.393"></a>
+<span class="sourceLineNo">394</span><a name="line.394"></a>
+<span class="sourceLineNo">395</span> /**<a name="line.395"></a>
+<span class="sourceLineNo">396</span> * @return true if data blocks should
be written to the cache when an HFile is<a name="line.396"></a>
+<span class="sourceLineNo">397</span> * written, false if not<a
name="line.397"></a>
+<span class="sourceLineNo">398</span> */<a name="line.398"></a>
+<span class="sourceLineNo">399</span> public boolean shouldCacheDataOnWrite()
{<a name="line.399"></a>
+<span class="sourceLineNo">400</span> return isBlockCacheEnabled()
&& this.cacheDataOnWrite;<a name="line.400"></a>
+<span class="sourceLineNo">401</span> }<a name="line.401"></a>
+<span class="sourceLineNo">402</span><a name="line.402"></a>
+<span class="sourceLineNo">403</span> /**<a name="line.403"></a>
+<span class="sourceLineNo">404</span> * Only used for testing.<a
name="line.404"></a>
+<span class="sourceLineNo">405</span> * @param cacheDataOnWrite whether data
blocks should be written to the cache<a name="line.405"></a>
+<span class="sourceLineNo">406</span> * when an
HFile is written<a name="line.406"></a>
+<span class="sourceLineNo">407</span> */<a name="line.407"></a>
+<span class="sourceLineNo">408</span> @VisibleForTesting<a
name="line.408"></a>
+<span class="sourceLineNo">409</span> public void setCacheDataOnWrite(boolean
cacheDataOnWrite) {<a name="line.409"></a>
+<span class="sourceLineNo">410</span> this.cacheDataOnWrite =
cacheDataOnWrite;<a name="line.410"></a>
+<span class="sourceLineNo">411</span> }<a name="line.411"></a>
+<span class="sourceLineNo">412</span><a name="line.412"></a>
+<span class="sourceLineNo">413</span> /**<a name="line.413"></a>
+<span class="sourceLineNo">414</span> * Only used for testing.<a
name="line.414"></a>
+<span class="sourceLineNo">415</span> * @param cacheDataInL1 Whether to
cache data blocks up in l1 (if a multi-tier cache<a name="line.415"></a>
+<span class="sourceLineNo">416</span> * implementation).<a
name="line.416"></a>
+<span class="sourceLineNo">417</span> */<a name="line.417"></a>
+<span class="sourceLineNo">418</span> @VisibleForTesting<a
name="line.418"></a>
+<span class="sourceLineNo">419</span> public void setCacheDataInL1(boolean
cacheDataInL1) {<a name="line.419"></a>
+<span class="sourceLineNo">420</span> this.cacheDataInL1 = cacheDataInL1;<a
name="line.420"></a>
+<span class="sourceLineNo">421</span> }<a name="line.421"></a>
+<span class="sourceLineNo">422</span><a name="line.422"></a>
+<span class="sourceLineNo">423</span> /**<a name="line.423"></a>
+<span class="sourceLineNo">424</span> * @return true if index blocks should
be written to the cache when an HFile<a name="line.424"></a>
+<span class="sourceLineNo">425</span> * is written, false if not<a
name="line.425"></a>
+<span class="sourceLineNo">426</span> */<a name="line.426"></a>
+<span class="sourceLineNo">427</span> public boolean
shouldCacheIndexesOnWrite() {<a name="line.427"></a>
+<span class="sourceLineNo">428</span> return isBlockCacheEnabled()
&& this.cacheIndexesOnWrite;<a name="line.428"></a>
+<span class="sourceLineNo">429</span> }<a name="line.429"></a>
+<span class="sourceLineNo">430</span><a name="line.430"></a>
+<span class="sourceLineNo">431</span> /**<a name="line.431"></a>
+<span class="sourceLineNo">432</span> * @return true if bloom blocks should
be written to the cache when an HFile<a name="line.432"></a>
+<span class="sourceLineNo">433</span> * is written, false if not<a
name="line.433"></a>
+<span class="sourceLineNo">434</span> */<a name="line.434"></a>
+<span class="sourceLineNo">435</span> public boolean
shouldCacheBloomsOnWrite() {<a name="line.435"></a>
+<span class="sourceLineNo">436</span> return isBlockCacheEnabled()
&& this.cacheBloomsOnWrite;<a name="line.436"></a>
+<span class="sourceLineNo">437</span> }<a name="line.437"></a>
+<span class="sourceLineNo">438</span><a name="line.438"></a>
+<span class="sourceLineNo">439</span> /**<a name="line.439"></a>
+<span class="sourceLineNo">440</span> * @return true if blocks should be
evicted from the cache when an HFile<a name="line.440"></a>
+<span class="sourceLineNo">441</span> * reader is closed, false if
not<a name="line.441"></a>
+<span class="sourceLineNo">442</span> */<a name="line.442"></a>
+<span class="sourceLineNo">443</span> public boolean shouldEvictOnClose() {<a
name="line.443"></a>
+<span class="sourceLineNo">444</span> return isBlockCacheEnabled()
&& this.evictOnClose;<a name="line.444"></a>
+<span class="sourceLineNo">445</span> }<a name="line.445"></a>
+<span class="sourceLineNo">446</span><a name="line.446"></a>
+<span class="sourceLineNo">447</span> /**<a name="line.447"></a>
+<span class="sourceLineNo">448</span> * Only used for testing.<a
name="line.448"></a>
+<span class="sourceLineNo">449</span> * @param evictOnClose whether blocks
should be evicted from the cache when an<a name="line.449"></a>
+<span class="sourceLineNo">450</span> * HFile reader is
closed<a name="line.450"></a>
+<span class="sourceLineNo">451</span> */<a name="line.451"></a>
+<span class="sourceLineNo">452</span> public void setEvictOnClose(boolean
evictOnClose) {<a name="line.452"></a>
+<span class="sourceLineNo">453</span> this.evictOnClose = evictOnClose;<a
name="line.453"></a>
+<span class="sourceLineNo">454</span> }<a name="line.454"></a>
+<span class="sourceLineNo">455</span><a name="line.455"></a>
+<span class="sourceLineNo">456</span> /**<a name="line.456"></a>
+<span class="sourceLineNo">457</span> * @return true if data blocks should
be compressed in the cache, false if not<a name="line.457"></a>
+<span class="sourceLineNo">458</span> */<a name="line.458"></a>
+<span class="sourceLineNo">459</span> public boolean
shouldCacheDataCompressed() {<a name="line.459"></a>
+<span class="sourceLineNo">460</span> return isBlockCacheEnabled()
&& this.cacheDataOnRead && this.cacheDataCompressed;<a
name="line.460"></a>
+<span class="sourceLineNo">461</span> }<a name="line.461"></a>
+<span class="sourceLineNo">462</span><a name="line.462"></a>
+<span class="sourceLineNo">463</span> /**<a name="line.463"></a>
+<span class="sourceLineNo">464</span> * @return true if this {@link
BlockCategory} should be compressed in blockcache, false otherwise<a
name="line.464"></a>
+<span class="sourceLineNo">465</span> */<a name="line.465"></a>
+<span class="sourceLineNo">466</span> public boolean
shouldCacheCompressed(BlockCategory category) {<a name="line.466"></a>
+<span class="sourceLineNo">467</span> if (!isBlockCacheEnabled()) return
false;<a name="line.467"></a>
+<span class="sourceLineNo">468</span> switch (category) {<a
name="line.468"></a>
+<span class="sourceLineNo">469</span> case DATA:<a name="line.469"></a>
+<span class="sourceLineNo">470</span> return this.cacheDataOnRead
&& this.cacheDataCompressed;<a name="line.470"></a>
+<span class="sourceLineNo">471</span> default:<a name="line.471"></a>
+<span class="sourceLineNo">472</span> return false;<a
name="line.472"></a>
+<span class="sourceLineNo">473</span> }<a name="line.473"></a>
+<span class="sourceLineNo">474</span> }<a name="line.474"></a>
+<span class="sourceLineNo">475</span><a name="line.475"></a>
+<span class="sourceLineNo">476</span> /**<a name="line.476"></a>
+<span class="sourceLineNo">477</span> * @return true if blocks should be
prefetched into the cache on open, false if not<a name="line.477"></a>
+<span class="sourceLineNo">478</span> */<a name="line.478"></a>
+<span class="sourceLineNo">479</span> public boolean shouldPrefetchOnOpen()
{<a name="line.479"></a>
+<span class="sourceLineNo">480</span> return isBlockCacheEnabled()
&& this.prefetchOnOpen;<a name="line.480"></a>
+<span class="sourceLineNo">481</span> }<a name="line.481"></a>
+<span class="sourceLineNo">482</span><a name="line.482"></a>
+<span class="sourceLineNo">483</span> /**<a name="line.483"></a>
+<span class="sourceLineNo">484</span> * Return true if we may find this type
of block in block cache.<a name="line.484"></a>
+<span class="sourceLineNo">485</span> * <p><a name="line.485"></a>
+<span class="sourceLineNo">486</span> * TODO: today {@code
family.isBlockCacheEnabled()} only means {@code cacheDataOnRead}, so here we<a
name="line.486"></a>
+<span class="sourceLineNo">487</span> * consider lots of other
configurations such as {@code cacheDataOnWrite}. We should fix this in<a
name="line.487"></a>
+<span class="sourceLineNo">488</span> * the future, {@code cacheDataOnWrite}
should honor the CF level {@code isBlockCacheEnabled}<a name="line.488"></a>
+<span class="sourceLineNo">489</span> * configuration.<a name="line.489"></a>
+<span class="sourceLineNo">490</span> */<a name="line.490"></a>
+<span class="sourceLineNo">491</span> public boolean
shouldReadBlockFromCache(BlockType blockType) {<a name="line.491"></a>
+<span class="sourceLineNo">492</span> if (!isBlockCacheEnabled()) {<a
name="line.492"></a>
+<span class="sourceLineNo">493</span> return false;<a name="line.493"></a>
+<span class="sourceLineNo">494</span> }<a name="line.494"></a>
+<span class="sourceLineNo">495</span> if (cacheDataOnRead) {<a
name="line.495"></a>
+<span class="sourceLineNo">496</span> return true;<a name="line.496"></a>
+<span class="sourceLineNo">497</span> }<a name="line.497"></a>
+<span class="sourceLineNo">498</span> if (prefetchOnOpen) {<a
name="line.498"></a>
+<span class="sourceLineNo">499</span> return true;<a name="line.499"></a>
+<span class="sourceLineNo">500</span> }<a name="line.500"></a>
+<span class="sourceLineNo">501</span> if (cacheDataOnWrite) {<a
name="line.501"></a>
+<span class="sourceLineNo">502</span> return true;<a name="line.502"></a>
+<span class="sourceLineNo">503</span> }<a name="line.503"></a>
+<span class="sourceLineNo">504</span> if (blockType == null) {<a
name="line.504"></a>
+<span class="sourceLineNo">505</span> return true;<a name="line.505"></a>
+<span class="sourceLineNo">506</span> }<a name="line.506"></a>
+<span class="sourceLineNo">507</span> if (blockType.getCategory() ==
BlockCategory.BLOOM ||<a name="line.507"></a>
+<span class="sourceLineNo">508</span> blockType.getCategory() ==
BlockCategory.INDEX) {<a name="line.508"></a>
+<span class="sourceLineNo">509</span> return true;<a name="line.509"></a>
+<span class="sourceLineNo">510</span> }<a name="line.510"></a>
+<span class="sourceLineNo">511</span> return false;<a name="line.511"></a>
+<span class="sourceLineNo">512</span> }<a name="line.512"></a>
+<span class="sourceLineNo">513</span><a name="line.513"></a>
+<span class="sourceLineNo">514</span> /**<a name="line.514"></a>
+<span class="sourceLineNo">515</span> * If we make sure the block could not
be cached, we will not acquire the lock<a name="line.515"></a>
+<span class="sourceLineNo">516</span> * otherwise we will acquire lock<a
name="line.516"></a>
+<span class="sourceLineNo">517</span> */<a name="line.517"></a>
+<span class="sourceLineNo">518</span> public boolean
shouldLockOnCacheMiss(BlockType blockType) {<a name="line.518"></a>
+<span class="sourceLineNo">519</span> if (blockType == null) {<a
name="line.519"></a>
+<span class="sourceLineNo">520</span> return true;<a name="line.520"></a>
+<span class="sourceLineNo">521</span> }<a name="line.521"></a>
+<span class="sourceLineNo">522</span> return
shouldCacheBlockOnRead(blockType.getCategory());<a name="line.522"></a>
+<span class="sourceLineNo">523</span> }<a name="line.523"></a>
+<span class="sourceLineNo">524</span><a name="line.524"></a>
+<span class="sourceLineNo">525</span> @Override<a name="line.525"></a>
+<span class="sourceLineNo">526</span> public String toString() {<a
name="line.526"></a>
+<span class="sourceLineNo">527</span> if (!isBlockCacheEnabled()) {<a
name="line.527"></a>
+<span class="sourceLineNo">528</span> return "CacheConfig:disabled";<a
name="line.528"></a>
+<span class="sourceLineNo">529</span> }<a name="line.529"></a>
+<span class="sourceLineNo">530</span> return "blockCache=" +
getBlockCache() +<a name="line.530"></a>
+<span class="sourceLineNo">531</span> ", cacheDataOnRead=" +
shouldCacheDataOnRead() +<a name="line.531"></a>
+<span class="sourceLineNo">532</span> ", cacheDataOnWrite=" +
shouldCacheDataOnWrite() +<a name="line.532"></a>
+<span class="sourceLineNo">533</span> ", cacheIndexesOnWrite=" +
shouldCacheIndexesOnWrite() +<a name="line.533"></a>
+<span class="sourceLineNo">534</span> ", cacheBloomsOnWrite=" +
shouldCacheBloomsOnWrite() +<a name="line.534"></a>
+<span class="sourceLineNo">535</span> ", cacheEvictOnClose=" +
shouldEvictOnClose() +<a name="line.535"></a>
+<span class="sourceLineNo">536</span> ", cacheDataCompressed=" +
shouldCacheDataCompressed() +<a name="line.536"></a>
+<span class="sourceLineNo">537</span> ", prefetchOnOpen=" +
shouldPrefetchOnOpen();<a name="line.537"></a>
+<span class="sourceLineNo">538</span> }<a name="line.538"></a>
+<span class="sourceLineNo">539</span><a name="line.539"></a>
+<span class="sourceLineNo">540</span> // Static block cache reference and
methods<a name="line.540"></a>
+<span class="sourceLineNo">541</span><a name="line.541"></a>
+<span class="sourceLineNo">542</span> /**<a name="line.542"></a>
+<span class="sourceLineNo">543</span> * Static reference to the block cache,
or null if no caching should be used<a name="line.543"></a>
+<span class="sourceLineNo">544</span> * at all.<a name="line.544"></a>
+<span class="sourceLineNo">545</span> */<a name="line.545"></a>
+<span class="sourceLineNo">546</span> // Clear this if in tests you'd make
more than one block cache instance.<a name="line.546"></a>
+<span class="sourceLineNo">547</span> @VisibleForTesting<a
name="line.547"></a>
+<span class="sourceLineNo">548</span> static BlockCache
GLOBAL_BLOCK_CACHE_INSTANCE;<a name="line.548"></a>
+<span class="sourceLineNo">549</span> private static LruBlockCache
GLOBAL_L1_CACHE_INSTANCE;<a name="line.549"></a>
+<span class="sourceLineNo">550</span><a name="line.550"></a>
+<span class="sourceLineNo">551</span> /** Boolean whether we have disabled
the block cache entirely. */<a name="line.551"></a>
+<span class="sourceLineNo">552</span> @VisibleForTesting<a
name="line.552"></a>
+<span class="sourceLineNo">553</span> static boolean blockCacheDisabled =
false;<a name="line.553"></a>
+<span class="sourceLineNo">554</span><a name="line.554"></a>
+<span class="sourceLineNo">555</span> /**<a name="line.555"></a>
+<span class="sourceLineNo">556</span> * @param c Configuration to use.<a
name="line.556"></a>
+<span class="sourceLineNo">557</span> * @return An L1 instance. Currently
an instance of LruBlockCache.<a name="line.557"></a>
+<span class="sourceLineNo">558</span> */<a name="line.558"></a>
+<span class="sourceLineNo">559</span> public static LruBlockCache getL1(final
Configuration c) {<a name="line.559"></a>
+<span class="sourceLineNo">560</span> return getL1Internal(c);<a
name="line.560"></a>
+<span class="sourceLineNo">561</span> }<a name="line.561"></a>
+<span class="sourceLineNo">562</span><a name="line.562"></a>
+<span class="sourceLineNo">563</span> /**<a name="line.563"></a>
+<span class="sourceLineNo">564</span> * @param c Configuration to use.<a
name="line.564"></a>
+<span class="sourceLineNo">565</span> * @return An L1 instance. Currently
an instance of LruBlockCache.<a name="line.565"></a>
+<span class="sourceLineNo">566</span> */<a name="line.566"></a>
+<span class="sourceLineNo">567</span> private synchronized static
LruBlockCache getL1Internal(final Configuration c) {<a name="line.567"></a>
+<span class="sourceLineNo">568</span> if (GLOBAL_L1_CACHE_INSTANCE != null)
return GLOBAL_L1_CACHE_INSTANCE;<a name="line.568"></a>
+<span class="sourceLineNo">569</span> final long lruCacheSize =
MemorySizeUtil.getLruCacheSize(c);<a name="line.569"></a>
+<span class="sourceLineNo">570</span> if (lruCacheSize < 0) {<a
name="line.570"></a>
+<span class="sourceLineNo">571</span> blockCacheDisabled = true;<a
name="line.571"></a>
+<span class="sourceLineNo">572</span> }<a name="line.572"></a>
+<span class="sourceLineNo">573</span> if (blockCacheDisabled) return
null;<a name="line.573"></a>
+<span class="sourceLineNo">574</span> int blockSize =
c.getInt(BLOCKCACHE_BLOCKSIZE_KEY, HConstants.DEFAULT_BLOCKSIZE);<a
name="line.574"></a>
+<span class="sourceLineNo">575</span> LOG.info("Allocating LruBlockCache
size=" +<a name="line.575"></a>
+<span class="sourceLineNo">576</span> StringUtils.byteDesc(lruCacheSize)
+ ", blockSize=" + StringUtils.byteDesc(blockSize));<a name="line.576"></a>
+<span class="sourceLineNo">577</span> GLOBAL_L1_CACHE_INSTANCE = new
LruBlockCache(lruCacheSize, blockSize, true, c);<a name="line.577"></a>
+<span class="sourceLineNo">578</span> return GLOBAL_L1_CACHE_INSTANCE;<a
name="line.578"></a>
+<span class="sourceLineNo">579</span> }<a name="line.579"></a>
+<span class="sourceLineNo">580</span><a name="line.580"></a>
+<span class="sourceLineNo">581</span> /**<a name="line.581"></a>
+<span class="sourceLineNo">582</span> * @param c Configuration to use.<a
name="line.582"></a>
+<span class="sourceLineNo">583</span> * @return Returns L2 block cache
instance (for now it is BucketCache BlockCache all the time)<a
name="line.583"></a>
+<span class="sourceLineNo">584</span> * or null if not supposed to be a
L2.<a name="line.584"></a>
+<span class="sourceLineNo">585</span> */<a name="line.585"></a>
+<span class="sourceLineNo">586</span> private static BlockCache getL2(final
Configuration c) {<a name="line.586"></a>
+<span class="sourceLineNo">587</span> final boolean useExternal =
c.getBoolean(EXTERNAL_BLOCKCACHE_KEY, EXTERNAL_BLOCKCACHE_DEFAULT);<a
name="line.587"></a>
+<span class="sourceLineNo">588</span> if (LOG.isDebugEnabled()) {<a
name="line.588"></a>
+<span class="sourceLineNo">589</span> LOG.debug("Trying to use " +
(useExternal?" External":" Internal") + " l2 cache");<a name="line.589"></a>
+<span class="sourceLineNo">590</span> }<a name="line.590"></a>
+<span class="sourceLineNo">591</span><a name="line.591"></a>
+<span class="sourceLineNo">592</span> // If we want to use an external
block cache then create that.<a name="line.592"></a>
+<span class="sourceLineNo">593</span> if (useExternal) {<a
name="line.593"></a>
+<span class="sourceLineNo">594</span> return getExternalBlockcache(c);<a
name="line.594"></a>
+<span class="sourceLineNo">595</span> }<a name="line.595"></a>
+<span class="sourceLineNo">596</span><a name="line.596"></a>
+<span class="sourceLineNo">597</span> // otherwise use the bucket cache.<a
name="line.597"></a>
+<span class="sourceLineNo">598</span> return getBucketCache(c);<a
name="line.598"></a>
+<span class="sourceLineNo">599</span><a name="line.599"></a>
+<span class="sourceLineNo">600</span> }<a name="line.600"></a>
+<span class="sourceLineNo">601</span><a name="line.601"></a>
+<span class="sourceLineNo">602</span> private static BlockCache
getExternalBlockcache(Configuration c) {<a name="line.602"></a>
+<span class="sourceLineNo">603</span> Class klass = null;<a
name="line.603"></a>
+<span class="sourceLineNo">604</span><a name="line.604"></a>
+<span class="sourceLineNo">605</span> // Get the class, from the config.
s<a name="line.605"></a>
+<span class="sourceLineNo">606</span> try {<a name="line.606"></a>
+<span class="sourceLineNo">607</span> klass =
ExternalBlockCaches.valueOf(c.get(EXTERNAL_BLOCKCACHE_CLASS_KEY,
"memcache")).clazz;<a name="line.607"></a>
+<span class="sourceLineNo">608</span> } catch (IllegalArgumentException
exception) {<a name="line.608"></a>
+<span class="sourceLineNo">609</span> try {<a name="line.609"></a>
+<span class="sourceLineNo">610</span> klass =
c.getClass(EXTERNAL_BLOCKCACHE_CLASS_KEY, Class.forName(<a name="line.610"></a>
+<span class="sourceLineNo">611</span>
"org.apache.hadoop.hbase.io.hfile.MemcachedBlockCache"));<a name="line.611"></a>
+<span class="sourceLineNo">612</span> } catch (ClassNotFoundException e)
{<a name="line.612"></a>
+<span class="sourceLineNo">613</span> return null;<a
name="line.613"></a>
+<span class="sourceLineNo">614</span> }<a name="line.614"></a>
+<span class="sourceLineNo">615</span> }<a name="line.615"></a>
+<span class="sourceLineNo">616</span><a name="line.616"></a>
+<span class="sourceLineNo">617</span> // Now try and create an instance of
the block cache.<a name="line.617"></a>
+<span class="sourceLineNo">618</span> try {<a name="line.618"></a>
+<span class="sourceLineNo">619</span> LOG.info("Creating external block
cache of type: " + klass);<a name="line.619"></a>
+<span class="sourceLineNo">620</span> return (BlockCache)
ReflectionUtils.newInstance(klass, c);<a name="line.620"></a>
+<span class="sourceLineNo">621</span> } catch (Exception e) {<a
name="line.621"></a>
+<span class="sourceLineNo">622</span> LOG.warn("Error creating external
block cache", e);<a name="line.622"></a>
+<span class="sourceLineNo">623</span> }<a name="line.623"></a>
+<span class="sourceLineNo">624</span> return null;<a name="line.624"></a>
+<span class="sourceLineNo">625</span><a name="line.625"></a>
+<span class="sourceLineNo">626</span> }<a name="line.626"></a>
+<span class="sourceLineNo">627</span><a name="line.627"></a>
+<span class="sourceLineNo">628</span> private static BlockCache
getBucketCache(Configuration c) {<a name="line.628"></a>
+<span class="sourceLineNo">629</span> // Check for L2. ioengine name must
be non-null.<a name="line.629"></a>
+<span class="sourceLineNo">630</span> String bucketCacheIOEngineName =
c.get(BUCKET_CACHE_IOENGINE_KEY, null);<a name="line.630"></a>
+<span class="sourceLineNo">631</span> if (bucketCacheIOEngineName == null
|| bucketCacheIOEngineName.length() <= 0) return null;<a name="line.631"></a>
+<span class="sourceLineNo">632</span><a name="line.632"></a>
+<span class="sourceLineNo">633</span> int blockSize =
c.getInt(BLOCKCACHE_BLOCKSIZE_KEY, HConstants.DEFAULT_BLOCKSIZE);<a
name="line.633"></a>
+<span class="sourceLineNo">634</span> final long bucketCacheSize =
MemorySizeUtil.getBucketCacheSize(c);<a name="line.634"></a>
+<span class="sourceLineNo">635</span> if (bucketCacheSize <= 0) {<a
name="line.635"></a>
+<span class="sourceLineNo">636</span> throw new
IllegalStateException("bucketCacheSize <= 0; Check " +<a name="line.636"></a>
+<span class="sourceLineNo">637</span> BUCKET_CACHE_SIZE_KEY + " setting
and/or server java heap size");<a name="line.637"></a>
+<span class="sourceLineNo">638</span> }<a name="line.638"></a>
+<span class="sourceLineNo">639</span> if
(c.get("hbase.bucketcache.percentage.in.combinedcache") != null) {<a
name="line.639"></a>
+<span class="sourceLineNo">640</span> LOG.warn("Configuration
'hbase.bucketcache.percentage.in.combinedcache' is no longer "<a
name="line.640"></a>
+<span class="sourceLineNo">641</span> + "respected. See comments in
http://hbase.apache.org/book.html#_changes_of_note");<a name="line.641"></a>
+<span class="sourceLineNo">642</span> }<a name="line.642"></a>
+<span class="sourceLineNo">643</span> int writerThreads =
c.getInt(BUCKET_CACHE_WRITER_THREADS_KEY,<a name="line.643"></a>
+<span class="sourceLineNo">644</span>
DEFAULT_BUCKET_CACHE_WRITER_THREADS);<a name="line.644"></a>
+<span class="sourceLineNo">645</span> int writerQueueLen =
c.getInt(BUCKET_CACHE_WRITER_QUEUE_KEY,<a name="line.645"></a>
+<span class="sourceLineNo">646</span>
DEFAULT_BUCKET_CACHE_WRITER_QUEUE);<a name="line.646"></a>
+<span class="sourceLineNo">647</span> String persistentPath =
c.get(BUCKET_CACHE_PERSISTENT_PATH_KEY);<a name="line.647"></a>
+<span class="sourceLineNo">648</span> String[] configuredBucketSizes =
c.getStrings(BUCKET_CACHE_BUCKETS_KEY);<a name="line.648"></a>
+<span class="sourceLineNo">649</span> int [] bucketSizes = null;<a
name="line.649"></a>
+<span class="sourceLineNo">650</span> if (configuredBucketSizes != null)
{<a name="line.650"></a>
+<span class="sourceLineNo">651</span> bucketSizes = new
int[configuredBucketSizes.length];<a name="line.651"></a>
+<span class="sourceLineNo">652</span> for (int i = 0; i <
configuredBucketSizes.length; i++) {<a name="line.652"></a>
+<span class="sourceLineNo">653</span> bucketSizes[i] =
Integer.parseInt(configuredBucketSizes[i].trim());<a name="line.653"></a>
+<span class="sourceLineNo">654</span> }<a name="line.654"></a>
+<span class="sourceLineNo">655</span> }<a name="line.655"></a>
+<span class="sourceLineNo">656</span> BucketCache bucketCache = null;<a
name="line.656"></a>
+<span class="sourceLineNo">657</span> try {<a name="line.657"></a>
+<span class="sourceLineNo">658</span> int ioErrorsTolerationDuration =
c.getInt(<a name="line.658"></a>
+<span class="sourceLineNo">659</span>
"hbase.bucketcache.ioengine.errors.tolerated.duration",<a name="line.659"></a>
+<span class="sourceLineNo">660</span>
BucketCache.DEFAULT_ERROR_TOLERATION_DURATION);<a name="line.660"></a>
+<span class="sourceLineNo">661</span> // Bucket cache logs its stats on
creation internal to the constructor.<a name="line.661"></a>
+<span class="sourceLineNo">662</span> bucketCache = new
BucketCache(bucketCacheIOEngineName,<a name="line.662"></a>
+<span class="sourceLineNo">663</span> bucketCacheSize, blockSize,
bucketSizes, writerThreads, writerQueueLen, persistentPath,<a
name="line.663"></a>
+<span class="sourceLineNo">664</span> ioErrorsTolerationDuration);<a
name="line.664"></a>
+<span class="sourceLineNo">665</span> } catch (IOException ioex) {<a
name="line.665"></a>
+<span class="sourceLineNo">666</span> LOG.error("Can't instantiate bucket
cache", ioex); throw new RuntimeException(ioex);<a name="line.666"></a>
+<span class="sourceLineNo">667</span> }<a name="line.667"></a>
+<span class="sourceLineNo">668</span> return bucketCache;<a
name="line.668"></a>
+<span class="sourceLineNo">669</span> }<a name="line.669"></a>
+<span class="sourceLineNo">670</span><a name="line.670"></a>
+<span class="sourceLineNo">671</span> /**<a name="line.671"></a>
+<span class="sourceLineNo">672</span> * Returns the block cache or
<code>null</code> in case none should be used.<a
name="line.672"></a>
+<span class="sourceLineNo">673</span> * Sets GLOBAL_BLOCK_CACHE_INSTANCE<a
name="line.673"></a>
+<span class="sourceLineNo">674</span> *<a name="line.674"></a>
+<span class="sourceLineNo">675</span> * @param conf The current
configuration.<a name="line.675"></a>
+<span class="sourceLineNo">676</span> * @return The block cache or
<code>null</code>.<a name="line.676"></a>
+<span class="sourceLineNo">677</span> */<a name="line.677"></a>
+<span class="sourceLineNo">678</span> public static synchronized BlockCache
instantiateBlockCache(Configuration conf) {<a name="line.678"></a>
+<span class="sourceLineNo">679</span> if (GLOBAL_BLOCK_CACHE_INSTANCE !=
null) return GLOBAL_BLOCK_CACHE_INSTANCE;<a name="line.679"></a>
+<span class="sourceLineNo">680</span> if (blockCacheDisabled) return
null;<a name="line.680"></a>
+<span class="sourceLineNo">681</span> LruBlockCache l1 =
getL1Internal(conf);<a name="line.681"></a>
+<span class="sourceLineNo">682</span> // blockCacheDisabled is set as a
side-effect of getL1Internal(), so check it again after the call.<a
name="line.682"></a>
+<span class="sourceLineNo">683</span> if (blockCacheDisabled) return
null;<a name="line.683"></a>
+<span class="sourceLineNo">684</span> BlockCache l2 = getL2(conf);<a
name="line.684"></a>
+<span class="sourceLineNo">685</span> if (l2 == null) {<a
name="line.685"></a>
+<span class="sourceLineNo">686</span> GLOBAL_BLOCK_CACHE_INSTANCE = l1;<a
name="line.686"></a>
+<span class="sourceLineNo">687</span> } else {<a name="line.687"></a>
+<span class="sourceLineNo">688</span> boolean useExternal =
conf.getBoolean(EXTERNAL_BLOCKCACHE_KEY, EXTERNAL_BLOCKCACHE_DEFAULT);<a
name="line.688"></a>
+<span class="sourceLineNo">689</span> boolean combinedWithLru =
conf.getBoolean(BUCKET_CACHE_COMBINED_KEY,<a name="line.689"></a>
+<span class="sourceLineNo">690</span> DEFAULT_BUCKET_CACHE_COMBINED);<a
name="line.690"></a>
+<span class="sourceLineNo">691</span> if (useExternal) {<a
name="line.691"></a>
+<span class="sourceLineNo">692</span> GLOBAL_BLOCK_CACHE_INSTANCE = new
InclusiveCombinedBlockCache(l1, l2);<a name="line.692"></a>
+<span class="sourceLineNo">693</span> } else {<a name="line.693"></a>
+<span class="sourceLineNo">694</span> if (combinedWithLru) {<a
name="line.694"></a>
+<span class="sourceLineNo">695</span> GLOBAL_BLOCK_CACHE_INSTANCE =
new CombinedBlockCache(l1, l2);<a name="line.695"></a>
+<span class="sourceLineNo">696</span> } else {<a name="line.696"></a>
+<span class="sourceLineNo">697</span> // L1 and L2 are not
'combined'. They are connected via the LruBlockCache victimhandler<a
name="line.697"></a>
+<span class="sourceLineNo">698</span> // mechanism. It is a little
ugly but works according to the following: when the<a name="line.698"></a>
+<span class="sourceLineNo">699</span> // background eviction thread
runs, blocks evicted from L1 will go to L2 AND when we get<a
name="line.699"></a>
+<span class="sourceLineNo">700</span> // a block from the L1 cache,
if not in L1, we will search L2.<a name="line.700"></a>
+<span class="sourceLineNo">701</span> GLOBAL_BLOCK_CACHE_INSTANCE =
l1;<a name="line.701"></a>
+<span class="sourceLineNo">702</span> }<a name="line.702"></a>
+<span class="sourceLineNo">703</span> }<a name="line.703"></a>
+<span class="sourceLineNo">704</span> l1.setVictimCache(l2);<a
name="line.704"></a>
+<span class="sourceLineNo">705</span> }<a name="line.705"></a>
+<span class="sourceLineNo">706</span> return GLOBAL_BLOCK_CACHE_INSTANCE;<a
name="line.706"></a>
+<span class="sourceLineNo">707</span> }<a name="line.707"></a>
+<span class="sourceLineNo">708</span><a name="line.708"></a>
+<span class="sourceLineNo">709</span> // Supposed to use only from tests.
Some tests want to reinit the Global block cache instance<a name="line.709"></a>
+<span class="sourceLineNo">710</span> @VisibleForTesting<a
name="line.710"></a>
+<span class="sourceLineNo">711</span> static synchronized void
clearGlobalInstances() {<a name="line.711"></a>
+<span class="sourceLineNo">712</span> GLOBAL_L1_CACHE_INSTANCE = null;<a
name="line.712"></a>
+<span class="sourceLineNo">713</span> GLOBAL_BLOCK_CACHE_INSTANCE = null;<a
name="line.713"></a>
+<span class="sourceLineNo">714</span> }<a name="line.714"></a>
+<span class="sourceLineNo">715</span>}<a name="line.715"></a>