Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DA7C4200CFD for ; Wed, 6 Sep 2017 17:14:03 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D91531609BA; Wed, 6 Sep 2017 15:14:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AEE4B1609C5 for ; Wed, 6 Sep 2017 17:14:01 +0200 (CEST) Received: (qmail 8095 invoked by uid 500); 6 Sep 2017 15:13:59 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 6186 invoked by uid 99); 6 Sep 2017 15:13:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Sep 2017 15:13:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B4DCCF56BE; Wed, 6 Sep 2017 15:13:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Wed, 06 Sep 2017 15:14:19 -0000 Message-Id: <06549cb126934b7cbe2d9b23d0a8075b@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [25/51] [partial] hbase-site git commit: Published site at . archived-at: Wed, 06 Sep 2017 15:14:04 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/e2f20c83/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.SimpleReporter.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.SimpleReporter.html b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.SimpleReporter.html index 64bce33..f8a036f 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.SimpleReporter.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.SimpleReporter.html @@ -53,7 +53,7 @@ 045import org.apache.commons.cli.Options; 046import org.apache.commons.cli.ParseException; 047import org.apache.commons.cli.PosixParser; -048import org.apache.commons.lang.StringUtils; +048import org.apache.commons.lang3.StringUtils; 049import org.apache.commons.logging.Log; 050import org.apache.commons.logging.LogFactory; 051import org.apache.hadoop.conf.Configuration; http://git-wip-us.apache.org/repos/asf/hbase-site/blob/e2f20c83/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.html b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.html index 64bce33..f8a036f 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.html @@ -53,7 +53,7 @@ 045import org.apache.commons.cli.Options; 046import org.apache.commons.cli.ParseException; 047import org.apache.commons.cli.PosixParser; -048import org.apache.commons.lang.StringUtils; +048import org.apache.commons.lang3.StringUtils; 049import org.apache.commons.logging.Log; 050import org.apache.commons.logging.LogFactory; 051import org.apache.hadoop.conf.Configuration; http://git-wip-us.apache.org/repos/asf/hbase-site/blob/e2f20c83/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/LruBlockCache.BlockBucket.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/LruBlockCache.BlockBucket.html b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/LruBlockCache.BlockBucket.html index 55c1e83..989423f 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/LruBlockCache.BlockBucket.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/LruBlockCache.BlockBucket.html @@ -848,375 +848,377 @@ 840 * 841 * @return max size in bytes 842 */ -843 public long getMaxSize() { -844 return this.maxSize; -845 } -846 -847 @Override -848 public long getCurrentSize() { -849 return this.size.get(); -850 } -851 -852 @Override -853 public long getCurrentDataSize() { -854 return this.dataBlockSize.get(); -855 } -856 -857 @Override -858 public long getFreeSize() { -859 return getMaxSize() - getCurrentSize(); -860 } -861 -862 @Override -863 public long size() { -864 return getMaxSize(); -865 } -866 -867 @Override -868 public long getBlockCount() { -869 return this.elements.get(); -870 } -871 -872 @Override -873 public long getDataBlockCount() { -874 return this.dataBlockElements.get(); -875 } -876 -877 EvictionThread getEvictionThread() { -878 return this.evictionThread; -879 } -880 -881 /* -882 * Eviction thread. Sits in waiting state until an eviction is triggered -883 * when the cache size grows above the acceptable level.<p> -884 * -885 * Thread is triggered into action by {@link LruBlockCache#runEviction()} -886 */ -887 static class EvictionThread extends HasThread { -888 -889 private WeakReference<LruBlockCache> cache; -890 private volatile boolean go = true; -891 // flag set after enter the run method, used for test -892 private boolean enteringRun = false; -893 -894 public EvictionThread(LruBlockCache cache) { -895 super(Thread.currentThread().getName() + ".LruBlockCache.EvictionThread"); -896 setDaemon(true); -897 this.cache = new WeakReference<>(cache); -898 } -899 -900 @Override -901 public void run() { -902 enteringRun = true; -903 while (this.go) { -904 synchronized (this) { -905 try { -906 this.wait(1000 * 10/*Don't wait for ever*/); -907 } catch (InterruptedException e) { -908 LOG.warn("Interrupted eviction thread ", e); -909 Thread.currentThread().interrupt(); -910 } -911 } -912 LruBlockCache cache = this.cache.get(); -913 if (cache == null) break; -914 cache.evict(); -915 } -916 } -917 -918 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="NN_NAKED_NOTIFY", -919 justification="This is what we want") -920 public void evict() { -921 synchronized (this) { -922 this.notifyAll(); -923 } -924 } -925 -926 synchronized void shutdown() { -927 this.go = false; -928 this.notifyAll(); -929 } -930 -931 /** -932 * Used for the test. -933 */ -934 boolean isEnteringRun() { -935 return this.enteringRun; -936 } -937 } -938 -939 /* -940 * Statistics thread. Periodically prints the cache statistics to the log. -941 */ -942 static class StatisticsThread extends Thread { -943 -944 private final LruBlockCache lru; +843 +844 @Override +845 public long getMaxSize() { +846 return this.maxSize; +847 } +848 +849 @Override +850 public long getCurrentSize() { +851 return this.size.get(); +852 } +853 +854 @Override +855 public long getCurrentDataSize() { +856 return this.dataBlockSize.get(); +857 } +858 +859 @Override +860 public long getFreeSize() { +861 return getMaxSize() - getCurrentSize(); +862 } +863 +864 @Override +865 public long size() { +866 return getMaxSize(); +867 } +868 +869 @Override +870 public long getBlockCount() { +871 return this.elements.get(); +872 } +873 +874 @Override +875 public long getDataBlockCount() { +876 return this.dataBlockElements.get(); +877 } +878 +879 EvictionThread getEvictionThread() { +880 return this.evictionThread; +881 } +882 +883 /* +884 * Eviction thread. Sits in waiting state until an eviction is triggered +885 * when the cache size grows above the acceptable level.<p> +886 * +887 * Thread is triggered into action by {@link LruBlockCache#runEviction()} +888 */ +889 static class EvictionThread extends HasThread { +890 +891 private WeakReference<LruBlockCache> cache; +892 private volatile boolean go = true; +893 // flag set after enter the run method, used for test +894 private boolean enteringRun = false; +895 +896 public EvictionThread(LruBlockCache cache) { +897 super(Thread.currentThread().getName() + ".LruBlockCache.EvictionThread"); +898 setDaemon(true); +899 this.cache = new WeakReference<>(cache); +900 } +901 +902 @Override +903 public void run() { +904 enteringRun = true; +905 while (this.go) { +906 synchronized (this) { +907 try { +908 this.wait(1000 * 10/*Don't wait for ever*/); +909 } catch (InterruptedException e) { +910 LOG.warn("Interrupted eviction thread ", e); +911 Thread.currentThread().interrupt(); +912 } +913 } +914 LruBlockCache cache = this.cache.get(); +915 if (cache == null) break; +916 cache.evict(); +917 } +918 } +919 +920 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="NN_NAKED_NOTIFY", +921 justification="This is what we want") +922 public void evict() { +923 synchronized (this) { +924 this.notifyAll(); +925 } +926 } +927 +928 synchronized void shutdown() { +929 this.go = false; +930 this.notifyAll(); +931 } +932 +933 /** +934 * Used for the test. +935 */ +936 boolean isEnteringRun() { +937 return this.enteringRun; +938 } +939 } +940 +941 /* +942 * Statistics thread. Periodically prints the cache statistics to the log. +943 */ +944 static class StatisticsThread extends Thread { 945 -946 public StatisticsThread(LruBlockCache lru) { -947 super("LruBlockCacheStats"); -948 setDaemon(true); -949 this.lru = lru; -950 } -951 -952 @Override -953 public void run() { -954 lru.logStats(); -955 } -956 } -957 -958 public void logStats() { -959 // Log size -960 long totalSize = heapSize(); -961 long freeSize = maxSize - totalSize; -962 LruBlockCache.LOG.info("totalSize=" + StringUtils.byteDesc(totalSize) + ", " + -963 "freeSize=" + StringUtils.byteDesc(freeSize) + ", " + -964 "max=" + StringUtils.byteDesc(this.maxSize) + ", " + -965 "blockCount=" + getBlockCount() + ", " + -966 "accesses=" + stats.getRequestCount() + ", " + -967 "hits=" + stats.getHitCount() + ", " + -968 "hitRatio=" + (stats.getHitCount() == 0 ? -969 "0" : (StringUtils.formatPercent(stats.getHitRatio(), 2)+ ", ")) + ", " + -970 "cachingAccesses=" + stats.getRequestCachingCount() + ", " + -971 "cachingHits=" + stats.getHitCachingCount() + ", " + -972 "cachingHitsRatio=" + (stats.getHitCachingCount() == 0 ? -973 "0,": (StringUtils.formatPercent(stats.getHitCachingRatio(), 2) + ", ")) + -974 "evictions=" + stats.getEvictionCount() + ", " + -975 "evicted=" + stats.getEvictedCount() + ", " + -976 "evictedPerRun=" + stats.evictedPerEviction()); -977 } -978 -979 /** -980 * Get counter statistics for this cache. -981 * -982 * <p>Includes: total accesses, hits, misses, evicted blocks, and runs -983 * of the eviction processes. -984 */ -985 public CacheStats getStats() { -986 return this.stats; -987 } -988 -989 public final static long CACHE_FIXED_OVERHEAD = ClassSize.align( -990 (4 * Bytes.SIZEOF_LONG) + (11 * ClassSize.REFERENCE) + -991 (6 * Bytes.SIZEOF_FLOAT) + (2 * Bytes.SIZEOF_BOOLEAN) -992 + ClassSize.OBJECT); -993 -994 @Override -995 public long heapSize() { -996 return getCurrentSize(); -997 } -998 -999 private static long calculateOverhead(long maxSize, long blockSize, int concurrency) { -1000 // FindBugs ICAST_INTEGER_MULTIPLY_CAST_TO_LONG -1001 return CACHE_FIXED_OVERHEAD + ClassSize.CONCURRENT_HASHMAP -1002 + ((long) Math.ceil(maxSize * 1.2 / blockSize) * ClassSize.CONCURRENT_HASHMAP_ENTRY) -1003 + ((long) concurrency * ClassSize.CONCURRENT_HASHMAP_SEGMENT); -1004 } -1005 -1006 @Override -1007 public Iterator<CachedBlock> iterator() { -1008 final Iterator<LruCachedBlock> iterator = map.values().iterator(); -1009 -1010 return new Iterator<CachedBlock>() { -1011 private final long now = System.nanoTime(); -1012 -1013 @Override -1014 public boolean hasNext() { -1015 return iterator.hasNext(); -1016 } -1017 -1018 @Override -1019 public CachedBlock next() { -1020 final LruCachedBlock b = iterator.next(); -1021 return new CachedBlock() { -1022 @Override -1023 public String toString() { -1024 return BlockCacheUtil.toString(this, now); -1025 } -1026 -1027 @Override -1028 public BlockPriority getBlockPriority() { -1029 return b.getPriority(); -1030 } -1031 -1032 @Override -1033 public BlockType getBlockType() { -1034 return b.getBuffer().getBlockType(); -1035 } -1036 -1037 @Override -1038 public long getOffset() { -1039 return b.getCacheKey().getOffset(); -1040 } -1041 -1042 @Override -1043 public long getSize() { -1044 return b.getBuffer().heapSize(); -1045 } -1046 -1047 @Override -1048 public long getCachedTime() { -1049 return b.getCachedTime(); -1050 } -1051 -1052 @Override -1053 public String getFilename() { -1054 return b.getCacheKey().getHfileName(); -1055 } -1056 -1057 @Override -1058 public int compareTo(CachedBlock other) { -1059 int diff = this.getFilename().compareTo(other.getFilename()); -1060 if (diff != 0) return diff; -1061 diff = Long.compare(this.getOffset(), other.getOffset()); +946 private final LruBlockCache lru; +947 +948 public StatisticsThread(LruBlockCache lru) { +949 super("LruBlockCacheStats"); +950 setDaemon(true); +951 this.lru = lru; +952 } +953 +954 @Override +955 public void run() { +956 lru.logStats(); +957 } +958 } +959 +960 public void logStats() { +961 // Log size +962 long totalSize = heapSize(); +963 long freeSize = maxSize - totalSize; +964 LruBlockCache.LOG.info("totalSize=" + StringUtils.byteDesc(totalSize) + ", " + +965 "freeSize=" + StringUtils.byteDesc(freeSize) + ", " + +966 "max=" + StringUtils.byteDesc(this.maxSize) + ", " + +967 "blockCount=" + getBlockCount() + ", " + +968 "accesses=" + stats.getRequestCount() + ", " + +969 "hits=" + stats.getHitCount() + ", " + +970 "hitRatio=" + (stats.getHitCount() == 0 ? +971 "0" : (StringUtils.formatPercent(stats.getHitRatio(), 2)+ ", ")) + ", " + +972 "cachingAccesses=" + stats.getRequestCachingCount() + ", " + +973 "cachingHits=" + stats.getHitCachingCount() + ", " + +974 "cachingHitsRatio=" + (stats.getHitCachingCount() == 0 ? +975 "0,": (StringUtils.formatPercent(stats.getHitCachingRatio(), 2) + ", ")) + +976 "evictions=" + stats.getEvictionCount() + ", " + +977 "evicted=" + stats.getEvictedCount() + ", " + +978 "evictedPerRun=" + stats.evictedPerEviction()); +979 } +980 +981 /** +982 * Get counter statistics for this cache. +983 * +984 * <p>Includes: total accesses, hits, misses, evicted blocks, and runs +985 * of the eviction processes. +986 */ +987 public CacheStats getStats() { +988 return this.stats; +989 } +990 +991 public final static long CACHE_FIXED_OVERHEAD = ClassSize.align( +992 (4 * Bytes.SIZEOF_LONG) + (11 * ClassSize.REFERENCE) + +993 (6 * Bytes.SIZEOF_FLOAT) + (2 * Bytes.SIZEOF_BOOLEAN) +994 + ClassSize.OBJECT); +995 +996 @Override +997 public long heapSize() { +998 return getCurrentSize(); +999 } +1000 +1001 private static long calculateOverhead(long maxSize, long blockSize, int concurrency) { +1002 // FindBugs ICAST_INTEGER_MULTIPLY_CAST_TO_LONG +1003 return CACHE_FIXED_OVERHEAD + ClassSize.CONCURRENT_HASHMAP +1004 + ((long) Math.ceil(maxSize * 1.2 / blockSize) * ClassSize.CONCURRENT_HASHMAP_ENTRY) +1005 + ((long) concurrency * ClassSize.CONCURRENT_HASHMAP_SEGMENT); +1006 } +1007 +1008 @Override +1009 public Iterator<CachedBlock> iterator() { +1010 final Iterator<LruCachedBlock> iterator = map.values().iterator(); +1011 +1012 return new Iterator<CachedBlock>() { +1013 private final long now = System.nanoTime(); +1014 +1015 @Override +1016 public boolean hasNext() { +1017 return iterator.hasNext(); +1018 } +1019 +1020 @Override +1021 public CachedBlock next() { +1022 final LruCachedBlock b = iterator.next(); +1023 return new CachedBlock() { +1024 @Override +1025 public String toString() { +1026 return BlockCacheUtil.toString(this, now); +1027 } +1028 +1029 @Override +1030 public BlockPriority getBlockPriority() { +1031 return b.getPriority(); +1032 } +1033 +1034 @Override +1035 public BlockType getBlockType() { +1036 return b.getBuffer().getBlockType(); +1037 } +1038 +1039 @Override +1040 public long getOffset() { +1041 return b.getCacheKey().getOffset(); +1042 } +1043 +1044 @Override +1045 public long getSize() { +1046 return b.getBuffer().heapSize(); +1047 } +1048 +1049 @Override +1050 public long getCachedTime() { +1051 return b.getCachedTime(); +1052 } +1053 +1054 @Override +1055 public String getFilename() { +1056 return b.getCacheKey().getHfileName(); +1057 } +1058 +1059 @Override +1060 public int compareTo(CachedBlock other) { +1061 int diff = this.getFilename().compareTo(other.getFilename()); 1062 if (diff != 0) return diff; -1063 if (other.getCachedTime() < 0 || this.getCachedTime() < 0) { -1064 throw new IllegalStateException(this.getCachedTime() + ", " + other.getCachedTime()); -1065 } -1066 return Long.compare(other.getCachedTime(), this.getCachedTime()); -1067 } -1068 -1069 @Override -1070 public int hashCode() { -1071 return b.hashCode(); -1072 } -1073 -1074 @Override -1075 public boolean equals(Object obj) { -1076 if (obj instanceof CachedBlock) { -1077 CachedBlock cb = (CachedBlock)obj; -1078 return compareTo(cb) == 0; -1079 } else { -1080 return false; -1081 } -1082 } -1083 }; -1084 } -1085 -1086 @Override -1087 public void remove() { -1088 throw new UnsupportedOperationException(); -1089 } -1090 }; -1091 } -1092 -1093 // Simple calculators of sizes given factors and maxSize +1063 diff = Long.compare(this.getOffset(), other.getOffset()); +1064 if (diff != 0) return diff; +1065 if (other.getCachedTime() < 0 || this.getCachedTime() < 0) { +1066 throw new IllegalStateException(this.getCachedTime() + ", " + other.getCachedTime()); +1067 } +1068 return Long.compare(other.getCachedTime(), this.getCachedTime()); +1069 } +1070 +1071 @Override +1072 public int hashCode() { +1073 return b.hashCode(); +1074 } +1075 +1076 @Override +1077 public boolean equals(Object obj) { +1078 if (obj instanceof CachedBlock) { +1079 CachedBlock cb = (CachedBlock)obj; +1080 return compareTo(cb) == 0; +1081 } else { +1082 return false; +1083 } +1084 } +1085 }; +1086 } +1087 +1088 @Override +1089 public void remove() { +1090 throw new UnsupportedOperationException(); +1091 } +1092 }; +1093 } 1094 -1095 long acceptableSize() { -1096 return (long)Math.floor(this.maxSize * this.acceptableFactor); -1097 } -1098 private long minSize() { -1099 return (long)Math.floor(this.maxSize * this.minFactor); -1100 } -1101 private long singleSize() { -1102 return (long)Math.floor(this.maxSize * this.singleFactor * this.minFactor); -1103 } -1104 private long multiSize() { -1105 return (long)Math.floor(this.maxSize * this.multiFactor * this.minFactor); -1106 } -1107 private long memorySize() { -1108 return (long) Math.floor(this.maxSize * this.memoryFactor * this.minFactor); -1109 } -1110 -1111 public void shutdown() { -1112 if (victimHandler != null) { -1113 victimHandler.shutdown(); -1114 } -1115 this.scheduleThreadPool.shutdown(); -1116 for (int i = 0; i < 10; i++) { -1117 if (!this.scheduleThreadPool.isShutdown()) { -1118 try { -1119 Thread.sleep(10); -1120 } catch (InterruptedException e) { -1121 LOG.warn("Interrupted while sleeping"); -1122 Thread.currentThread().interrupt(); -1123 break; -1124 } -1125 } -1126 } -1127 -1128 if (!this.scheduleThreadPool.isShutdown()) { -1129 List<Runnable> runnables = this.scheduleThreadPool.shutdownNow(); -1130 LOG.debug("Still running " + runnables); -1131 } -1132 this.evictionThread.shutdown(); -1133 } -1134 -1135 /** Clears the cache. Used in tests. */ -1136 @VisibleForTesting -1137 public void clearCache() { -1138 this.map.clear(); -1139 this.elements.set(0); -1140 } -1141 -1142 /** -1143 * Used in testing. May be very inefficient. -1144 * -1145 * @return the set of cached file names -1146 */ -1147 @VisibleForTesting -1148 SortedSet<String> getCachedFileNamesForTest() { -1149 SortedSet<String> fileNames = new TreeSet<>(); -1150 for (BlockCacheKey cacheKey : map.keySet()) { -1151 fileNames.add(cacheKey.getHfileName()); -1152 } -1153 return fileNames; -1154 } -1155 -1156 @VisibleForTesting -1157 Map<BlockType, Integer> getBlockTypeCountsForTest() { -1158 Map<BlockType, Integer> counts = new EnumMap<>(BlockType.class); -1159 for (LruCachedBlock cb : map.values()) { -1160 BlockType blockType = cb.getBuffer().getBlockType(); -1161 Integer count = counts.get(blockType); -1162 counts.put(blockType, (count == null ? 0 : count) + 1); -1163 } -1164 return counts; -1165 } -1166 -1167 @VisibleForTesting -1168 public Map<DataBlockEncoding, Integer> getEncodingCountsForTest() { -1169 Map<DataBlockEncoding, Integer> counts = new EnumMap<>(DataBlockEncoding.class); -1170 for (LruCachedBlock block : map.values()) { -1171 DataBlockEncoding encoding = ((HFileBlock) block.getBuffer()).getDataBlockEncoding(); -1172 Integer count = counts.get(encoding); -1173 counts.put(encoding, (count == null ? 0 : count) + 1); -1174 } -1175 return counts; -1176 } -1177 -1178 public void setVictimCache(BlockCache handler) { -1179 assert victimHandler == null; -1180 victimHandler = handler; -1181 } -1182 -1183 @VisibleForTesting -1184 Map<BlockCacheKey, LruCachedBlock> getMapForTests() { -1185 return map; -1186 } -1187 -1188 BlockCache getVictimHandler() { -1189 return this.victimHandler; -1190 } -1191 -1192 @Override -1193 @JsonIgnore -1194 public BlockCache[] getBlockCaches() { -1195 if (victimHandler != null) -1196 return new BlockCache[] {this, this.victimHandler}; -1197 return null; -1198 } -1199 -1200 @Override -1201 public void returnBlock(BlockCacheKey cacheKey, Cacheable block) { -1202 // There is no SHARED type here in L1. But the block might have been served from the Victim -1203 // handler L2 cache. (when the Combined mode = false). So just try return this block to -1204 // L2 victim handler cache. -1205 // Note : In case of CombinedBlockCache, we will have this victimHandler configured for L1 -1206 // cache. But CombinedBlockCache will only call returnBlock on L2 cache. -1207 if (this.victimHandler != null) { -1208 this.victimHandler.returnBlock(cacheKey, block); -1209 } -1210 } -1211} +1095 // Simple calculators of sizes given factors and maxSize +1096 +1097 long acceptableSize() { +1098 return (long)Math.floor(this.maxSize * this.acceptableFactor); +1099 } +1100 private long minSize() { +1101 return (long)Math.floor(this.maxSize * this.minFactor); +1102 } +1103 private long singleSize() { +1104 return (long)Math.floor(this.maxSize * this.singleFactor * this.minFactor); +1105 } +1106 private long multiSize() { +1107 return (long)Math.floor(this.maxSize * this.multiFactor * this.minFactor); +1108 } +1109 private long memorySize() { +1110 return (long) Math.floor(this.maxSize * this.memoryFactor * this.minFactor); +1111 } +1112 +1113 public void shutdown() { +1114 if (victimHandler != null) { +1115 victimHandler.shutdown(); +1116 } +1117 this.scheduleThreadPool.shutdown(); +1118 for (int i = 0; i < 10; i++) { +1119 if (!this.scheduleThreadPool.isShutdown()) { +1120 try { +1121 Thread.sleep(10); +1122 } catch (InterruptedException e) { +1123 LOG.warn("Interrupted while sleeping"); +1124 Thread.currentThread().interrupt(); +1125 break; +1126 } +1127 } +1128 } +1129 +1130 if (!this.scheduleThreadPool.isShutdown()) { +1131 List<Runnable> runnables = this.scheduleThreadPool.shutdownNow(); +1132 LOG.debug("Still running " + runnables); +1133 } +1134 this.evictionThread.shutdown(); +1135 } +1136 +1137 /** Clears the cache. Used in tests. */ +1138 @VisibleForTesting +1139 public void clearCache() { +1140 this.map.clear(); +1141 this.elements.set(0); +1142 } +1143 +1144 /** +1145 * Used in testing. May be very inefficient. +1146 * +1147 * @return the set of cached file names +1148 */ +1149 @VisibleForTesting +1150 SortedSet<String> getCachedFileNamesForTest() { +1151 SortedSet<String> fileNames = new TreeSet<>(); +1152 for (BlockCacheKey cacheKey : map.keySet()) { +1153 fileNames.add(cacheKey.getHfileName()); +1154 } +1155 return fileNames; +1156 } +1157 +1158 @VisibleForTesting +1159 Map<BlockType, Integer> getBlockTypeCountsForTest() { +1160 Map<BlockType, Integer> counts = new EnumMap<>(BlockType.class); +1161 for (LruCachedBlock cb : map.values()) { +1162 BlockType blockType = cb.getBuffer().getBlockType(); +1163 Integer count = counts.get(blockType); +1164 counts.put(blockType, (count == null ? 0 : count) + 1); +1165 } +1166 return counts; +1167 } +1168 +1169 @VisibleForTesting +1170 public Map<DataBlockEncoding, Integer> getEncodingCountsForTest() { +1171 Map<DataBlockEncoding, Integer> counts = new EnumMap<>(DataBlockEncoding.class); +1172 for (LruCachedBlock block : map.values()) { +1173 DataBlockEncoding encoding = ((HFileBlock) block.getBuffer()).getDataBlockEncoding(); +1174 Integer count = counts.get(encoding); +1175 counts.put(encoding, (count == null ? 0 : count) + 1); +1176 } +1177 return counts; +1178 } +1179 +1180 public void setVictimCache(BlockCache handler) { +1181 assert victimHandler == null; +1182 victimHandler = handler; +1183 } +1184 +1185 @VisibleForTesting +1186 Map<BlockCacheKey, LruCachedBlock> getMapForTests() { +1187 return map; +1188 } +1189 +1190 BlockCache getVictimHandler() { +1191 return this.victimHandler; +1192 } +1193 +1194 @Override +1195 @JsonIgnore +1196 public BlockCache[] getBlockCaches() { +1197 if (victimHandler != null) +1198 return new BlockCache[] {this, this.victimHandler}; +1199 return null; +1200 } +1201 +1202 @Override +1203 public void returnBlock(BlockCacheKey cacheKey, Cacheable block) { +1204 // There is no SHARED type here in L1. But the block might have been served from the Victim +1205 // handler L2 cache. (when the Combined mode = false). So just try return this block to +1206 // L2 victim handler cache. +1207 // Note : In case of CombinedBlockCache, we will have this victimHandler configured for L1 +1208 // cache. But CombinedBlockCache will only call returnBlock on L2 cache. +1209 if (this.victimHandler != null) { +1210 this.victimHandler.returnBlock(cacheKey, block); +1211 } +1212 } +1213}