Search in sources :

Example 6 with CachableBuilder

use of org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile.CachableBuilder in project accumulo by apache.

the class RFileTest method runVersionTest.

private void runVersionTest(int version, ConfigurationCopy aconf) throws Exception {
    InputStream in = this.getClass().getClassLoader().getResourceAsStream("org/apache/accumulo/core/file/rfile/ver_" + version + ".rf");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    int read;
    while ((read = in.read(buf)) > 0) baos.write(buf, 0, read);
    byte[] data = baos.toByteArray();
    SeekableByteArrayInputStream bais = new SeekableByteArrayInputStream(data);
    FSDataInputStream in2 = new FSDataInputStream(bais);
    aconf.set(Property.TSERV_CACHE_MANAGER_IMPL, LruBlockCacheManager.class.getName());
    aconf.set(Property.TSERV_DEFAULT_BLOCKSIZE, Long.toString(100000));
    aconf.set(Property.TSERV_DATACACHE_SIZE, Long.toString(100000000));
    aconf.set(Property.TSERV_INDEXCACHE_SIZE, Long.toString(100000000));
    BlockCacheManager manager = BlockCacheManagerFactory.getInstance(aconf);
    manager.start(new BlockCacheConfiguration(aconf));
    CachableBuilder cb = new CachableBuilder().input(in2, "cache-1").length(data.length).conf(hadoopConf).cryptoService(CryptoServiceFactory.newInstance(aconf, ClassloaderType.JAVA)).cacheProvider(new BasicCacheProvider(manager.getBlockCache(CacheType.INDEX), manager.getBlockCache(CacheType.DATA)));
    Reader reader = new RFile.Reader(cb);
    checkIndex(reader);
    ColumnFamilySkippingIterator iter = new ColumnFamilySkippingIterator(reader);
    for (int start : new int[] { 0, 10, 100, 998 }) {
        for (int cf = 1; cf <= 4; cf++) {
            if (start == 0)
                iter.seek(new Range(), newColFamByteSequence(formatString("cf_", cf)), true);
            else
                iter.seek(new Range(formatString("r_", start), null), newColFamByteSequence(formatString("cf_", cf)), true);
            for (int i = start; i < 1000; i++) {
                assertTrue(iter.hasTop());
                assertEquals(newKey(formatString("r_", i), formatString("cf_", cf), formatString("cq_", 0), "", 1000 - i), iter.getTopKey());
                assertEquals(newValue(i + ""), iter.getTopValue());
                iter.next();
            }
            assertFalse(iter.hasTop());
        }
        if (start == 0)
            iter.seek(new Range(), newColFamByteSequence(), false);
        else
            iter.seek(new Range(formatString("r_", start), null), newColFamByteSequence(), false);
        for (int i = start; i < 1000; i++) {
            for (int cf = 1; cf <= 4; cf++) {
                assertTrue(iter.hasTop());
                assertEquals(newKey(formatString("r_", i), formatString("cf_", cf), formatString("cq_", 0), "", 1000 - i), iter.getTopKey());
                assertEquals(newValue(i + ""), iter.getTopValue());
                iter.next();
            }
        }
        assertFalse(iter.hasTop());
    }
    manager.stop();
    reader.close();
}
Also used : ColumnFamilySkippingIterator(org.apache.accumulo.core.iteratorsImpl.system.ColumnFamilySkippingIterator) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) ByteArrayInputStream(java.io.ByteArrayInputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) BasicCacheProvider(org.apache.accumulo.core.file.blockfile.impl.BasicCacheProvider) Reader(org.apache.accumulo.core.file.rfile.RFile.Reader) BlockCacheManager(org.apache.accumulo.core.spi.cache.BlockCacheManager) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Range(org.apache.accumulo.core.data.Range) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) BlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration) CachableBuilder(org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile.CachableBuilder)

Aggregations

CachableBuilder (org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile.CachableBuilder)6 IOException (java.io.IOException)4 Key (org.apache.accumulo.core.data.Key)4 Reader (org.apache.accumulo.core.file.rfile.RFile.Reader)4 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)4 Range (org.apache.accumulo.core.data.Range)3 Value (org.apache.accumulo.core.data.Value)3 BasicCacheProvider (org.apache.accumulo.core.file.blockfile.impl.BasicCacheProvider)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 UncheckedIOException (java.io.UncheckedIOException)2 ArrayList (java.util.ArrayList)2 ConfigOpts (org.apache.accumulo.core.cli.ConfigOpts)2 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)2 ByteSequence (org.apache.accumulo.core.data.ByteSequence)2 CachableBlockFile (org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile)2 BCFile (org.apache.accumulo.core.file.rfile.bcfile.BCFile)2 Configuration (org.apache.hadoop.conf.Configuration)2 Path (org.apache.hadoop.fs.Path)2 Parameter (com.beust.jcommander.Parameter)1