当前位置: 首页>>代码示例>>Java>>正文


Java BlockCacheUtil类代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.io.hfile.BlockCacheUtil的典型用法代码示例。如果您正苦于以下问题:Java BlockCacheUtil类的具体用法?Java BlockCacheUtil怎么用?Java BlockCacheUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BlockCacheUtil类属于org.apache.hadoop.hbase.io.hfile包,在下文中一共展示了BlockCacheUtil类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cacheBlockWithWait

import org.apache.hadoop.hbase.io.hfile.BlockCacheUtil; //导入依赖的package包/类
/**
 * Cache the block to ramCache
 * @param cacheKey block's cache key
 * @param cachedItem block buffer
 * @param inMemory if block is in-memory
 * @param wait if true, blocking wait when queue is full
 */
public void cacheBlockWithWait(BlockCacheKey cacheKey, Cacheable cachedItem, boolean inMemory,
    boolean wait) {
  if (LOG.isTraceEnabled()) LOG.trace("Caching key=" + cacheKey + ", item=" + cachedItem);
  if (!cacheEnabled) {
    return;
  }

  if (backingMap.containsKey(cacheKey)) {
    Cacheable existingBlock = getBlock(cacheKey, false, false, false);
    try {
      if (BlockCacheUtil.compareCacheBlock(cachedItem, existingBlock) != 0) {
        throw new RuntimeException("Cached block contents differ, which should not have happened."
            + "cacheKey:" + cacheKey);
      }
      String msg = "Caching an already cached block: " + cacheKey;
      msg += ". This is harmless and can happen in rare cases (see HBASE-8547)";
      LOG.warn(msg);
    } finally {
      // return the block since we need to decrement the count
      returnBlock(cacheKey, existingBlock);
    }
    return;
  }

  /*
   * Stuff the entry into the RAM cache so it can get drained to the persistent store
   */
  RAMQueueEntry re =
      new RAMQueueEntry(cacheKey, cachedItem, accessCount.incrementAndGet(), inMemory);
  if (ramCache.putIfAbsent(cacheKey, re) != null) {
    return;
  }
  int queueNum = (cacheKey.hashCode() & 0x7FFFFFFF) % writerQueues.size();
  BlockingQueue<RAMQueueEntry> bq = writerQueues.get(queueNum);
  boolean successfulAddition = false;
  if (wait) {
    try {
      successfulAddition = bq.offer(re, DEFAULT_CACHE_WAIT_TIME, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  } else {
    successfulAddition = bq.offer(re);
  }
  if (!successfulAddition) {
    ramCache.remove(cacheKey);
    cacheStats.failInsert();
  } else {
    this.blockNumber.increment();
    this.heapSize.add(cachedItem.heapSize());
    blocksByHFile.add(cacheKey);
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:61,代码来源:BucketCache.java


注:本文中的org.apache.hadoop.hbase.io.hfile.BlockCacheUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。