/** * This test inserts data into multiple tables and then reads both tables to ensure * they are in the block cache. * * @throws Exception exception */ @Test public void testBlockCacheSummary() throws Exception { HTable ht = TEST_UTIL.createTable(Bytes.toBytes(TEST_TABLE), FAMILY); addRows(ht, FAMILY); HTable ht2 = TEST_UTIL.createTable(Bytes.toBytes(TEST_TABLE2), FAMILY); addRows(ht2, FAMILY); TEST_UTIL.flush(); scan(ht, FAMILY); scan(ht2, FAMILY); BlockCache bc = new CacheConfig(TEST_UTIL.getConfiguration()).getBlockCache(); List<BlockCacheColumnFamilySummary> bcs = bc.getBlockCacheColumnFamilySummaries(TEST_UTIL.getConfiguration()); LOG.info("blockCacheSummary: " + bcs); assertEquals("blockCache summary has entries", 3, bcs.size()); BlockCacheColumnFamilySummary e = bcs.get(0); assertEquals("table", "-ROOT-", e.getTable()); assertEquals("cf", "info", e.getColumnFamily()); e = bcs.get(1); assertEquals("table", TEST_TABLE, e.getTable()); assertEquals("cf", TEST_CF, e.getColumnFamily()); e = bcs.get(2); assertEquals("table", TEST_TABLE2, e.getTable()); assertEquals("cf", TEST_CF, e.getColumnFamily()); ht.close(); ht2.close(); }
/** * This test inserts data into multiple tables and then reads both tables to ensure * they are in the block cache. * * @throws Exception exception */ @Test public void testBlockCacheSummary() throws Exception { HTable ht = TEST_UTIL.createTable(Bytes.toBytes(TEST_TABLE), FAMILY); addRows(ht, FAMILY); HTable ht2 = TEST_UTIL.createTable(Bytes.toBytes(TEST_TABLE2), FAMILY); addRows(ht2, FAMILY); TEST_UTIL.flush(); scan(ht, FAMILY); scan(ht2, FAMILY); BlockCache bc = new CacheConfig(TEST_UTIL.getConfiguration()).getBlockCache(); List<BlockCacheColumnFamilySummary> bcs = bc.getBlockCacheColumnFamilySummaries(TEST_UTIL.getConfiguration()); LOG.info("blockCacheSummary: " + bcs); assertTrue("blockCache summary has " + bcs.size() + " entries", bcs.size() >= 2); BlockCacheColumnFamilySummary e = bcs.get(bcs.size()-2); assertEquals("table", TEST_TABLE, e.getTable()); assertEquals("cf", TEST_CF, e.getColumnFamily()); e = bcs.get(bcs.size()-1); assertEquals("table", TEST_TABLE2, e.getTable()); assertEquals("cf", TEST_CF, e.getColumnFamily()); ht.close(); ht2.close(); }
@Override public List<BlockCacheColumnFamilySummary> getBlockCacheColumnFamilySummaries(Configuration conf) throws IOException { Map<String, Path> sfMap = FSUtils.getTableStoreFilePathMap( FileSystem.get(conf), FSUtils.getRootDir(conf)); // quirky, but it's a compound key and this is a shortcut taken instead of // creating a class that would represent only a key. Map<BlockCacheColumnFamilySummary, BlockCacheColumnFamilySummary> bcs = new HashMap<BlockCacheColumnFamilySummary, BlockCacheColumnFamilySummary>(); for (CachedBlock cb : map.values()) { String sf = cb.getCacheKey().getHfileName(); Path path = sfMap.get(sf); if ( path != null) { BlockCacheColumnFamilySummary lookup = BlockCacheColumnFamilySummary.createFromStoreFilePath(path); BlockCacheColumnFamilySummary bcse = bcs.get(lookup); if (bcse == null) { bcse = BlockCacheColumnFamilySummary.create(lookup); bcs.put(lookup,bcse); } bcse.incrementBlocks(); bcse.incrementHeapSize(cb.heapSize()); } } List<BlockCacheColumnFamilySummary> list = new ArrayList<BlockCacheColumnFamilySummary>(bcs.values()); Collections.sort( list ); return list; }
@Override public List<BlockCacheColumnFamilySummary> getBlockCacheColumnFamilySummaries() throws IOException { BlockCache c = new CacheConfig(this.conf).getBlockCache(); return c.getBlockCacheColumnFamilySummaries(this.conf); }
@Override public List<BlockCacheColumnFamilySummary> getBlockCacheColumnFamilySummaries( Configuration conf) { throw new UnsupportedOperationException(); }
@Override public List<BlockCacheColumnFamilySummary> getBlockCacheColumnFamilySummaries(Configuration conf) throws IOException { return null; }