Package org.iq80.leveldb.util

Examples of org.iq80.leveldb.util.SliceInput


    }

    @Override
    public Level0Iterator iterator()
    {
        return new Level0Iterator(tableCache, files, internalKeyComparator);
    }
View Full Code Here


        List<InternalIterator> list = newArrayList();
        for (int which = 0; which < 2; which++) {
          if (!c.getInputs()[which].isEmpty()) {
            if (c.getLevel() + which == 0) {
                List<FileMetaData> files = c.getInputs()[which];
                list.add(new Level0Iterator(tableCache, files, internalKeyComparator));
            } else {
              // Create concatenating iterator for the files from this level
              list.add(Level.createLevelConcatIterator(tableCache, c.getInputs()[which], internalKeyComparator));
            }
          }
View Full Code Here

        return createLevelConcatIterator(tableCache, files, internalKeyComparator);
    }

    public static LevelIterator createLevelConcatIterator(TableCache tableCache, List<FileMetaData> files, InternalKeyComparator internalKeyComparator)
    {
        return new LevelIterator(tableCache, files, internalKeyComparator);
    }
View Full Code Here

              // Create concatenating iterator for the files from this level
              list.add(Level.createLevelConcatIterator(tableCache, c.getInputs()[which], internalKeyComparator));
            }
          }
        }
        return new MergingIterator(list, internalKeyComparator);
    }
View Full Code Here

        closed = true;
    }

    public static int crc32c(Slice data, CompressionType type)
    {
        PureJavaCrc32C crc32c = new PureJavaCrc32C();
        crc32c.update(data.getRawArray(), data.getRawOffset(), data.length());
        crc32c.update(type.persistentId() & 0xFF);
        return crc32c.getMaskedValue();
    }
View Full Code Here

    }

    public static int getChunkChecksum(int chunkTypeId, byte[] buffer, int offset, int length)
    {
        // Compute the crc of the record type and the payload.
        PureJavaCrc32C crc32C = new PureJavaCrc32C();
        crc32C.update(chunkTypeId);
        crc32C.update(buffer, offset, length);
        return crc32C.getMaskedValue();
    }
View Full Code Here

        return comparator.name();
    }

    @Override
    public Slice findShortestSeparator(Slice start, Slice limit) {
        return new Slice(comparator.findShortestSeparator(start.getBytes(), limit.getBytes()));
    }
View Full Code Here

        return new Slice(comparator.findShortestSeparator(start.getBytes(), limit.getBytes()));
    }

    @Override
    public Slice findShortSuccessor(Slice key) {
        return new Slice(comparator.findShortSuccessor(key.getBytes()));
    }
View Full Code Here

        // If we just wrote a block, we can now add the handle to index block
        if (pendingIndexEntry) {
            Preconditions.checkState(dataBlockBuilder.isEmpty(), "Internal error: Table has a pending index entry but data block builder is empty");

            Slice shortestSeparator = userComparator.findShortestSeparator(lastKey, key);

            Slice handleEncoding = BlockHandle.writeBlockHandle(pendingHandle);
            indexBlockBuilder.add(shortestSeparator, handleEncoding);
            pendingIndexEntry = false;
        }

        lastKey = key;
View Full Code Here

    private BlockHandle writeBlock(BlockBuilder blockBuilder)
            throws IOException
    {
        // close the block
        Slice raw = blockBuilder.finish();

        // attempt to compress the block
        Slice blockContents = raw;
        CompressionType blockCompressionType = CompressionType.NONE;
        if (compressionType == CompressionType.SNAPPY) {
            ensureCompressedOutputCapacity(maxCompressedLength(raw.length()));
            try {
                int compressedSize = Snappy.compress(raw.getRawArray(), raw.getRawOffset(), raw.length(), compressedOutput.getRawArray(), 0);

                // Don't use the compressed data if compressed less than 12.5%,
                if (compressedSize < raw.length() - (raw.length() / 8)) {
                    blockContents = compressedOutput.slice(0, compressedSize);
                    blockCompressionType = CompressionType.SNAPPY;
                }
            }
            catch (IOException ignored) {
                // compression failed, so just store uncompressed form
            }
        }

        // create block trailer
        BlockTrailer blockTrailer = new BlockTrailer(blockCompressionType, crc32c(blockContents, blockCompressionType));
        Slice trailer = BlockTrailer.writeBlockTrailer(blockTrailer);

        // create a handle to this block
        BlockHandle blockHandle = new BlockHandle(position, blockContents.length());

        // write data and trailer
        position += fileChannel.write(new ByteBuffer[]{blockContents.toByteBuffer(), trailer.toByteBuffer()});

        // clean up state
        blockBuilder.reset();

        return blockHandle;
View Full Code Here

TOP

Related Classes of org.iq80.leveldb.util.SliceInput

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.