Package org.xtreemfs.babudb.index.reader

Examples of org.xtreemfs.babudb.index.reader.DiskIndex


                }
            });
           
            for (String file : files) {
                int index = Integer.parseInt(file.substring(file.indexOf("IX") + 2, file.indexOf('V')));
                indexMap.put(index, new DiskIndex(dir + "/" + file, comps[index], compressed, mmaped));
            }
           
        } catch (IOException exc) {
            throw new BabuDBException(ErrorCode.IO_ERROR, "could not load index file", exc);
        }
View Full Code Here


    }
   
    @Override
    public byte[] directLookup(int indexId, byte[] key) throws BabuDBException {
       
        DiskIndex index = indexMap.get(indexId);
        if (index == null)
            throw new BabuDBException(ErrorCode.NO_SUCH_INDEX, "index " + indexId + " does not exist");
       
        return index.lookup(key);
    }
View Full Code Here

    }
   
    @Override
    public ResultSet<byte[], byte[]> directPrefixLookup(int indexId, byte[] key, boolean ascending) throws BabuDBException {
       
        DiskIndex index = indexMap.get(indexId);
        if (index == null)
            throw new BabuDBException(ErrorCode.NO_SUCH_INDEX, "index " + indexId + " does not exist");
       
        byte[][] range = index.getComparator().prefixToRange(key, true);
        return index.rangeLookup(range[0], range[1], ascending);
    }
View Full Code Here

    }
   
    @Override
    public ResultSet<byte[], byte[]> directRangeLookup(int indexId, byte[] from, byte[] to, boolean ascending) throws BabuDBException {
       
        DiskIndex index = indexMap.get(indexId);
        if (index == null)
            throw new BabuDBException(ErrorCode.NO_SUCH_INDEX, "index " + indexId + " does not exist");
       
        return index.rangeLookup(from, to, ascending);
    }
View Full Code Here

        this.useMMap = useMMap;
        this.mmapLimitBytes = mmapLimit * 1024 * 1024;
       
        overlay = new MultiOverlayBufferTree(NULL_ELEMENT, comp);
        totalOnDiskSize += indexFile == null ? 0 : getTotalDirSize(new File(indexFile));
        index = indexFile == null ? null : new DiskIndex(indexFile, comp, compressed, useMmap());
        lock = new Object();
    }
View Full Code Here

     *            the snapshot file
     * @throws IOException
     *             if an I/O error occurred while reading the snapshot file
     */
    public void linkToSnapshot(String snapshotFile) throws IOException {
        final DiskIndex oldIndex = index;
        synchronized (lock) {
            totalOnDiskSize -= index == null ? 0 : index.getSize();
            index = new DiskIndex(snapshotFile, comp, this.compressed, useMmap());
            totalOnDiskSize += index.getSize();
            if (oldIndex != null)
                oldIndex.destroy();
            overlay.cleanup();
        }
    }
View Full Code Here

   
    public void testLookup() throws Exception {
        // create an empty disk index
        byte[][] entries = new byte[][] {};
        populateDiskIndex(entries);
        DiskIndex diskIndex = new DiskIndex(PATH2, new DefaultByteRangeComparator(), COMPRESSED, MMAPED);
       
        assertEquals(entries.length, diskIndex.numKeys());
        diskIndex.destroy();
       
        // create a disk index with a single entry and look up the key
        entries = new byte[][] { "test".getBytes() };
        populateDiskIndex(entries);
        diskIndex = new DiskIndex(PATH2, new DefaultByteRangeComparator(), COMPRESSED, MMAPED);
       
        for (byte[] entry : entries)
            assertEquals(0, COMP.compare(entry, diskIndex.lookup(entry)));
        assertEquals(entries.length, diskIndex.numKeys());
        diskIndex.destroy();
       
        // create a new disk index and look up each key
        entries = new byte[][] { new byte[] { '\0' }, "word".getBytes(), new byte[] { '#' } };
       
        populateDiskIndex(entries);
        diskIndex = new DiskIndex(PATH2, DefaultByteRangeComparator.getInstance(), COMPRESSED, MMAPED);
       
        for (byte[] entry : entries)
            assertEquals(0, COMP.compare(entry, diskIndex.lookup(entry)));
        assertEquals(entries.length, diskIndex.numKeys());
        diskIndex.destroy();
       
        // create another disk index and look up each key
        entries = new byte[][] { "fdsaf".getBytes(), "blubberbla".getBytes(), "zzz".getBytes(),
            "aaa".getBytes(), "aab".getBytes() };
        populateDiskIndex(entries);
        diskIndex = new DiskIndex(PATH2, new DefaultByteRangeComparator(), COMPRESSED, MMAPED);
       
        for (byte[] entry : entries)
            assertEquals(0, COMP.compare(entry, diskIndex.lookup(entry)));
        assertEquals(entries.length, diskIndex.numKeys());
        diskIndex.destroy();
       
        // create a larger disk index and look up each key
        entries = createRandomByteArrays(NUM_ENTRIES);
        populateDiskIndex(entries);
        diskIndex = new DiskIndex(PATH2, new DefaultByteRangeComparator(), COMPRESSED, MMAPED);
       
        for (byte[] entry : entries)
            assertEquals(0, COMP.compare(entry, diskIndex.lookup(entry)));
        assertEquals(entries.length, diskIndex.numKeys());
        diskIndex.destroy();
    }
View Full Code Here

        // write the map to a disk index
        DiskIndexWriter index = new DiskIndexWriter(PATH1, MAX_BLOCK_ENTRIES, COMPRESSED, MAX_BLOCK_FILE_SIZE);
        index.writeIndex(getBufferIterator(map.entrySet().iterator()));
       
        // read the disk index
        DiskIndex diskIndex = new DiskIndex(PATH1, DefaultByteRangeComparator.getInstance(), COMPRESSED,
            MMAPED);
       
        // look up each element
        Iterator<Entry<byte[], byte[]>> it = map.entrySet().iterator();
        // long t0 = System.currentTimeMillis();
        // int count = 0;
        while (it.hasNext()) {
            // count++;
            Entry<byte[], byte[]> next = it.next();
            byte[] result = diskIndex.lookup(next.getKey());
            assertEquals(0, COMP.compare(result, next.getValue()));
            // if (count % 1000 == 0)
            // System.out.println(count);
        }
        // long time = System.currentTimeMillis() - t0;
        // System.out.println(time + " ms");
        // System.out.println(count * 1000 / time + " lookups/s");
       
        diskIndex.destroy();
    }
View Full Code Here

        FSUtils.delTree(new File(PATH2));
        DiskIndexWriter index = new DiskIndexWriter(PATH2, 4, COMPRESSED, MAX_BLOCK_FILE_SIZE);
        index.writeIndex(getBufferIterator(testMap.entrySet().iterator()));
       
        // read the disk index
        DiskIndex diskIndex = new DiskIndex(PATH2, DefaultByteRangeComparator.getInstance(), COMPRESSED,
            MMAPED);
       
        // create an iterator w/ matching start and end buffers
        Iterator<Entry<byte[], byte[]>> it = diskIndex.rangeLookup("brabbel".getBytes(), "yagga".getBytes(),
            true);
        assertIterator(it, keys, vals, 1, 4);
       
        // create an iterator with matching start buffer
        it = diskIndex.rangeLookup("brabbel".getBytes(), "g".getBytes(), true);
        assertIterator(it, keys, vals, 1, 2);
       
        // create an iterator with matching end buffer
        it = diskIndex.rangeLookup("b".getBytes(), "brabbel".getBytes(), true);
        assertIterator(it, keys, vals, 0, 0);
       
        // create an iterator w/o matching start and end buffers
        it = diskIndex.rangeLookup("blu".getBytes(), "yyz".getBytes(), true);
        assertIterator(it, keys, vals, 1, 6);
       
        // check ranges outside the boundaries; should be empty
        it = diskIndex.rangeLookup("A".getBytes(), "Z".getBytes(), true);
        assertFalse(it.hasNext());
       
        it = diskIndex.rangeLookup("1".getBytes(), "2".getBytes(), true);
        assertFalse(it.hasNext());
       
        diskIndex.destroy();
       
        // create a disk index from an empty index file
        FSUtils.delTree(new File(PATH1));
        index = new DiskIndexWriter(PATH1, 4, COMPRESSED, MAX_BLOCK_FILE_SIZE);
        index.writeIndex(EMPTY_RESULT_SET);
       
        diskIndex = new DiskIndex(PATH1, new DefaultByteRangeComparator(), COMPRESSED, MMAPED);
       
        // check ranges; should all be empty
        it = diskIndex.rangeLookup(new byte[0], new byte[0], true);
        assertFalse(it.hasNext());
       
        it = diskIndex.rangeLookup(null, null, true);
        assertFalse(it.hasNext());
       
        it = diskIndex.rangeLookup("b".getBytes(), null, true);
        assertFalse(it.hasNext());
       
        it = diskIndex.rangeLookup(null, "x".getBytes(), true);
        assertFalse(it.hasNext());
       
        it = diskIndex.rangeLookup("b".getBytes(), "x".getBytes(), true);
        assertFalse(it.hasNext());
       
        diskIndex.destroy();
    }
View Full Code Here

        FSUtils.delTree(new File(PATH2));
        DiskIndexWriter index = new DiskIndexWriter(PATH2, 4, COMPRESSED, MAX_BLOCK_FILE_SIZE);
        index.writeIndex(getBufferIterator(testMap.entrySet().iterator()));
       
        // read the disk index
        DiskIndex diskIndex = new DiskIndex(PATH2, DefaultByteRangeComparator.getInstance(), COMPRESSED,
            MMAPED);
       
        // create an iterator w/ matching start and end buffers
        Iterator<Entry<byte[], byte[]>> it = diskIndex.rangeLookup("brabbel".getBytes(), "yagga".getBytes(),
            false);
        assertIterator(it, keys, vals, 5, 2);
       
        // create an iterator with matching start buffer
        it = diskIndex.rangeLookup("brabbel".getBytes(), "g".getBytes(), false);
        assertIterator(it, keys, vals, 2, 2);
       
        // create an iterator with matching end buffer
        it = diskIndex.rangeLookup("b".getBytes(), "brabbel".getBytes(), false);
        assertIterator(it, keys, vals, 1, 0);
       
        // create an iterator w/o matching start and end buffers
        it = diskIndex.rangeLookup("blu".getBytes(), "yyz".getBytes(), false);
        assertIterator(it, keys, vals, 6, 1);
       
        // check ranges outside the boundaries; should be empty
        it = diskIndex.rangeLookup("A".getBytes(), "Z".getBytes(), false);
        assertFalse(it.hasNext());
       
        it = diskIndex.rangeLookup("1".getBytes(), "2".getBytes(), false);
        assertFalse(it.hasNext());
       
        diskIndex.destroy();
       
        // create a disk index from an empty index file
        FSUtils.delTree(new File(PATH1));
        index = new DiskIndexWriter(PATH1, 4, COMPRESSED, MAX_BLOCK_FILE_SIZE);
        index.writeIndex(EMPTY_RESULT_SET);
       
        diskIndex = new DiskIndex(PATH1, new DefaultByteRangeComparator(), COMPRESSED, MMAPED);
       
        // check ranges; should all be empty
        it = diskIndex.rangeLookup(new byte[0], new byte[0], false);
        assertFalse(it.hasNext());
       
        it = diskIndex.rangeLookup(null, null, false);
        assertFalse(it.hasNext());
       
        it = diskIndex.rangeLookup("b".getBytes(), null, false);
        assertFalse(it.hasNext());
       
        it = diskIndex.rangeLookup(null, "x".getBytes(), false);
        assertFalse(it.hasNext());
       
        it = diskIndex.rangeLookup("b".getBytes(), "x".getBytes(), false);
        assertFalse(it.hasNext());
       
        diskIndex.destroy();
    }
View Full Code Here

TOP

Related Classes of org.xtreemfs.babudb.index.reader.DiskIndex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.