Search in sources :

Example 1 with IndexEntry

use of org.apache.accumulo.core.file.rfile.MultiLevelIndex.IndexEntry in project accumulo by apache.

the class MultiLevelIndexTest method runTest.

private void runTest(int maxBlockSize, int num) throws IOException {
    AccumuloConfiguration aconf = DefaultConfiguration.getInstance();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    FSDataOutputStream dos = new FSDataOutputStream(baos, new FileSystem.Statistics("a"));
    BCFile.Writer _cbw = new BCFile.Writer(dos, null, "gz", hadoopConf, CryptoServiceFactory.newInstance(aconf, JAVA));
    BufferedWriter mliw = new BufferedWriter(new Writer(_cbw, maxBlockSize));
    for (int i = 0; i < num; i++) mliw.add(new Key(String.format("%05d000", i)), i, 0, 0, 0);
    mliw.addLast(new Key(String.format("%05d000", num)), num, 0, 0, 0);
    BCFile.Writer.BlockAppender root = _cbw.prepareMetaBlock("root");
    mliw.close(root);
    root.close();
    _cbw.close();
    dos.close();
    baos.close();
    byte[] data = baos.toByteArray();
    SeekableByteArrayInputStream bais = new SeekableByteArrayInputStream(data);
    FSDataInputStream in = new FSDataInputStream(bais);
    CachableBuilder cb = new CachableBuilder().input(in, "source-1").length(data.length).conf(hadoopConf).cryptoService(CryptoServiceFactory.newInstance(aconf, JAVA));
    CachableBlockFile.Reader _cbr = new CachableBlockFile.Reader(cb);
    Reader reader = new Reader(_cbr, RFile.RINDEX_VER_8);
    CachableBlockFile.CachedBlockRead rootIn = _cbr.getMetaBlock("root");
    reader.readFields(rootIn);
    rootIn.close();
    IndexIterator liter = reader.lookup(new Key("000000"));
    int count = 0;
    while (liter.hasNext()) {
        assertEquals(count, liter.nextIndex());
        assertEquals(count, liter.peek().getNumEntries());
        assertEquals(count, liter.next().getNumEntries());
        count++;
    }
    assertEquals(num + 1, count);
    while (liter.hasPrevious()) {
        count--;
        assertEquals(count, liter.previousIndex());
        assertEquals(count, liter.peekPrevious().getNumEntries());
        assertEquals(count, liter.previous().getNumEntries());
    }
    assertEquals(0, count);
    // go past the end
    liter = reader.lookup(new Key(String.format("%05d000", num + 1)));
    assertFalse(liter.hasNext());
    random.ints(100, 0, num * 1_000).forEach(k -> {
        int expected;
        if (k % 1000 == 0)
            // end key is inclusive
            expected = k / 1000;
        else
            expected = k / 1000 + 1;
        try {
            IndexEntry ie = reader.lookup(new Key(String.format("%08d", k))).next();
            assertEquals(expected, ie.getNumEntries());
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
}
Also used : Reader(org.apache.accumulo.core.file.rfile.MultiLevelIndex.Reader) IndexEntry(org.apache.accumulo.core.file.rfile.MultiLevelIndex.IndexEntry) UncheckedIOException(java.io.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IndexIterator(org.apache.accumulo.core.file.rfile.MultiLevelIndex.Reader.IndexIterator) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BCFile(org.apache.accumulo.core.file.rfile.bcfile.BCFile) BufferedWriter(org.apache.accumulo.core.file.rfile.MultiLevelIndex.BufferedWriter) FileSystem(org.apache.hadoop.fs.FileSystem) SeekableByteArrayInputStream(org.apache.accumulo.core.file.rfile.RFileTest.SeekableByteArrayInputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) CachableBlockFile(org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) CachableBuilder(org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile.CachableBuilder) BufferedWriter(org.apache.accumulo.core.file.rfile.MultiLevelIndex.BufferedWriter) Writer(org.apache.accumulo.core.file.rfile.MultiLevelIndex.Writer) Key(org.apache.accumulo.core.data.Key) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 2 with IndexEntry

use of org.apache.accumulo.core.file.rfile.MultiLevelIndex.IndexEntry in project accumulo by apache.

the class BlockIndexTest method test1.

@Test
public void test1() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    Key prevKey = null;
    int num = 1000;
    for (int i = 0; i < num; i++) {
        Key key = new Key(RFileTest.formatString("", i), "cf1", "cq1");
        new RelativeKey(prevKey, key).write(out);
        new Value().write(out);
        prevKey = key;
    }
    out.close();
    final byte[] data = baos.toByteArray();
    CacheEntry ce = new MyCacheEntry(data);
    CachableBlockFile.CachedBlockRead cacheBlock = new CachableBlockFile.CachedBlockRead(ce, data);
    BlockIndex blockIndex = null;
    for (int i = 0; i < 129; i++) blockIndex = BlockIndex.getIndex(cacheBlock, new IndexEntry(prevKey, num, 0, 0, 0));
    BlockIndexEntry[] indexEntries = blockIndex.getIndexEntries();
    for (int i = 0; i < indexEntries.length; i++) {
        int row = Integer.parseInt(indexEntries[i].getPrevKey().getRowData().toString());
        BlockIndexEntry bie;
        bie = blockIndex.seekBlock(new Key(RFileTest.formatString("", row), "cf1", "cq1"), cacheBlock);
        if (i == 0)
            assertSame(null, bie);
        else
            assertSame(indexEntries[i - 1], bie);
        assertSame(bie, blockIndex.seekBlock(new Key(RFileTest.formatString("", row - 1), "cf1", "cq1"), cacheBlock));
        bie = blockIndex.seekBlock(new Key(RFileTest.formatString("", row + 1), "cf1", "cq1"), cacheBlock);
        assertSame(indexEntries[i], bie);
        RelativeKey rk = new RelativeKey();
        rk.setPrevKey(bie.getPrevKey());
        rk.readFields(cacheBlock);
        assertEquals(rk.getKey(), new Key(RFileTest.formatString("", row + 1), "cf1", "cq1"));
    }
    cacheBlock.close();
}
Also used : DataOutputStream(java.io.DataOutputStream) BlockIndexEntry(org.apache.accumulo.core.file.rfile.BlockIndex.BlockIndexEntry) BlockIndexEntry(org.apache.accumulo.core.file.rfile.BlockIndex.BlockIndexEntry) IndexEntry(org.apache.accumulo.core.file.rfile.MultiLevelIndex.IndexEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheEntry(org.apache.accumulo.core.spi.cache.CacheEntry) Value(org.apache.accumulo.core.data.Value) CachableBlockFile(org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 3 with IndexEntry

use of org.apache.accumulo.core.file.rfile.MultiLevelIndex.IndexEntry in project accumulo by apache.

the class BlockIndexTest method testSame.

@Test
public void testSame() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    Key prevKey = null;
    int num = 1000;
    for (int i = 0; i < num; i++) {
        Key key = new Key(RFileTest.formatString("", 1), "cf1", "cq1");
        new RelativeKey(prevKey, key).write(out);
        new Value().write(out);
        prevKey = key;
    }
    for (int i = 0; i < num; i++) {
        Key key = new Key(RFileTest.formatString("", 3), "cf1", "cq1");
        new RelativeKey(prevKey, key).write(out);
        new Value().write(out);
        prevKey = key;
    }
    for (int i = 0; i < num; i++) {
        Key key = new Key(RFileTest.formatString("", 5), "cf1", "cq1");
        new RelativeKey(prevKey, key).write(out);
        new Value().write(out);
        prevKey = key;
    }
    out.close();
    final byte[] data = baos.toByteArray();
    CacheEntry ce = new MyCacheEntry(data);
    CachableBlockFile.CachedBlockRead cacheBlock = new CachableBlockFile.CachedBlockRead(ce, data);
    BlockIndex blockIndex = null;
    for (int i = 0; i < 257; i++) blockIndex = BlockIndex.getIndex(cacheBlock, new IndexEntry(prevKey, num, 0, 0, 0));
    assertSame(null, blockIndex.seekBlock(new Key(RFileTest.formatString("", 0), "cf1", "cq1"), cacheBlock));
    assertSame(null, blockIndex.seekBlock(new Key(RFileTest.formatString("", 1), "cf1", "cq1"), cacheBlock));
    for (int i = 2; i < 6; i++) {
        Key seekKey = new Key(RFileTest.formatString("", i), "cf1", "cq1");
        BlockIndexEntry bie = blockIndex.seekBlock(seekKey, cacheBlock);
        assertTrue(bie.getPrevKey().compareTo(seekKey) < 0);
        RelativeKey rk = new RelativeKey();
        rk.setPrevKey(bie.getPrevKey());
        rk.readFields(cacheBlock);
        assertTrue(rk.getKey().compareTo(seekKey) <= 0);
    }
    cacheBlock.close();
}
Also used : DataOutputStream(java.io.DataOutputStream) BlockIndexEntry(org.apache.accumulo.core.file.rfile.BlockIndex.BlockIndexEntry) BlockIndexEntry(org.apache.accumulo.core.file.rfile.BlockIndex.BlockIndexEntry) IndexEntry(org.apache.accumulo.core.file.rfile.MultiLevelIndex.IndexEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheEntry(org.apache.accumulo.core.spi.cache.CacheEntry) Value(org.apache.accumulo.core.data.Value) CachableBlockFile(org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Key (org.apache.accumulo.core.data.Key)3 CachableBlockFile (org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile)3 IndexEntry (org.apache.accumulo.core.file.rfile.MultiLevelIndex.IndexEntry)3 DataOutputStream (java.io.DataOutputStream)2 Value (org.apache.accumulo.core.data.Value)2 BlockIndexEntry (org.apache.accumulo.core.file.rfile.BlockIndex.BlockIndexEntry)2 CacheEntry (org.apache.accumulo.core.spi.cache.CacheEntry)2 Test (org.junit.jupiter.api.Test)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)1 CachableBuilder (org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile.CachableBuilder)1 BufferedWriter (org.apache.accumulo.core.file.rfile.MultiLevelIndex.BufferedWriter)1 Reader (org.apache.accumulo.core.file.rfile.MultiLevelIndex.Reader)1 IndexIterator (org.apache.accumulo.core.file.rfile.MultiLevelIndex.Reader.IndexIterator)1 Writer (org.apache.accumulo.core.file.rfile.MultiLevelIndex.Writer)1 SeekableByteArrayInputStream (org.apache.accumulo.core.file.rfile.RFileTest.SeekableByteArrayInputStream)1 BCFile (org.apache.accumulo.core.file.rfile.bcfile.BCFile)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1