Examples of FileDataInput


Examples of at.jku.sii.sqlitereader.io.FileDataInput

  private final SqliteMasterTable sql_master_table;

  private final SimpleAnnotator annotator;

  public SqliteDataBase(File dbFile) {
    FileDataInput file = null;
    this.annotator = new SimpleAnnotator();

    try {
      file = new FileDataInput(dbFile, this.annotator);

      this.fileName = dbFile.getAbsolutePath();

      file.annotate(0, (int) HEADER_SIZE, "Header");
      // start of header
      readMagicHeader(file);
      this.pageSize = readPageSize(file);
      this.fileFormatWrite = file.readByte() == 1 ? FileFormat.LEGACY : FileFormat.WAL;
      file.annotateLastByte("writeFileFormat", this.fileFormatWrite);
      this.fileFormatRead = file.readByte() == 1 ? FileFormat.LEGACY : FileFormat.WAL;
      file.annotateLastByte("readFileFormat", this.fileFormatRead);

      this.reservedPageSpace = file.readByte("reservedPageSpace");

      byte maxEmbedded = file.readByte("maxEmbedded");
      assert (maxEmbedded == 64);
      byte minEmbedded = file.readByte("minEmbedded");
      assert (minEmbedded == 32);
      byte leafPayload = file.readByte("leafPayload");
      assert (leafPayload == 32);
      this.fileChangeCounter = file.readInt("fileChangeCounter");
      int storedNumPages = file.readInt("storedNumPages");

      this.firstFreeListPage = file.readInt("firstFreeListPage");
      this.numFreeListPages = file.readInt("numFreeListPages");

      this.schemaCookie = file.readInt("schemaCookie");
      this.schemaFormat = file.readInt("schemaForamt"); // one of 1..4
      this.defaultPageCacheSize = file.readInt("defaultPageCacheSize");

      this.largestBTreePage = file.readInt("largestBTreePage");

      this.encoding = readEncoding(file);
      file.annotateLastInt("Encoding", this.encoding);

      this.userVersion = file.readInt("userVersion");
      this.incrementalVacuumMode = file.readInt() > 0;
      file.annotateLastInt("incrementalVacuumMode", this.incrementalVacuumMode);
      // reserved
      byte[] reserved = new byte[24];
      file.readFully(reserved);
      file.annotateLast(reserved.length, "reserved");

      this.versionValid4Number = file.readInt("versionValid4Number");
      this.versionSqlite = file.readInt("versionSqlite");
      // end of header

      // compute the num of Pages
      if (isValidNumPages(storedNumPages, this.fileChangeCounter, this.versionValid4Number)) {
        this.numPages = storedNumPages;
      } else {
        this.numPages = file.size() / this.pageSize;
      }

      // read all pages
      this.pages = readPages(file, this.numPages, this.pageSize);
    } finally {
      if (file != null)
        file.close();
      file = null;
    }

    // read root btree page
    BTreePage<TableCell> sql_master_btree = BTreePages.readMaster(this);
View Full Code Here

Examples of org.apache.cassandra.io.util.FileDataInput

        // scan the on-disk index, starting at the nearest sampled position
        Iterator<FileDataInput> segments = ifile.iterator(sampledPosition.indexPosition, INDEX_FILE_BUFFER_BYTES);
        while (segments.hasNext())
        {
            FileDataInput input = segments.next();
            try
            {
                while (!input.isEOF())
                {
                    // read key & data position from index entry
                    DecoratedKey indexDecoratedKey = decodeKey(partitioner, descriptor, ByteBufferUtil.readWithShortLength(input));
                    long dataPosition = input.readLong();

                    int comparison = indexDecoratedKey.compareTo(decoratedKey);
                    int v = op.apply(comparison);
                    if (v == 0)
                    {
View Full Code Here

Examples of org.apache.cassandra.io.util.FileDataInput

        // check that all our keys are found correctly
        SSTableReader sstable = store.getSSTables().iterator().next();
        for (int j = 0; j < 100; j += 2)
        {
            DecoratedKey dk = Util.dk(String.valueOf(j));
            FileDataInput file = sstable.getFileDataInput(dk, DatabaseDescriptor.getIndexedReadBufferSizeInKB() * 1024);
            DecoratedKey keyInDisk = SSTableReader.decodeKey(sstable.partitioner,
                                                             sstable.descriptor,
                                                             ByteBufferUtil.readWithShortLength(file));
            assert keyInDisk.equals(dk) : String.format("%s != %s in %s", keyInDisk, dk, file.getPath());
        }

        // check no false positives
        for (int j = 1; j < 110; j += 2)
        {
View Full Code Here

Examples of org.apache.cassandra.io.util.FileDataInput

    {
        assert columns != null;
        this.columns = columns;
        this.key = key;

        FileDataInput file = sstable.getFileDataInput(key, DatabaseDescriptor.getIndexedReadBufferSizeInKB() * 1024);
        if (file == null)
            return;

        try
        {
            DecoratedKey keyInDisk = SSTableReader.decodeKey(sstable.partitioner,
                                                             sstable.descriptor,
                                                             ByteBufferUtil.readWithShortLength(file));
            assert keyInDisk.equals(key) : String.format("%s != %s in %s", keyInDisk, key, file.getPath());
            SSTableReader.readRowSize(file, sstable.descriptor);
            read(sstable, file);
        }
        catch (IOException e)
        {
View Full Code Here

Examples of org.apache.cassandra.io.util.FileDataInput

        // check that all our keys are found correctly
        SSTableReader sstable = store.getSSTables().iterator().next();
        for (int j = 0; j < 100; j += 2)
        {
            DecoratedKey dk = Util.dk(String.valueOf(j));
            FileDataInput file = sstable.getFileDataInput(sstable.getPosition(dk, SSTableReader.Operator.EQ).position);
            DecoratedKey keyInDisk = SSTableReader.decodeKey(sstable.partitioner,
                                                             sstable.descriptor,
                                                             ByteBufferUtil.readWithShortLength(file));
            assert keyInDisk.equals(dk) : String.format("%s != %s in %s", keyInDisk, dk, file.getPath());
        }

        // check no false positives
        for (int j = 1; j < 110; j += 2)
        {
View Full Code Here

Examples of org.apache.cassandra.io.util.FileDataInput

    {
        assert columns != null;
        this.columns = columns;
        this.key = key;

        FileDataInput file = sstable.getFileDataInput(key);
        if (file == null)
            return;

        try
        {
            DecoratedKey keyInDisk = SSTableReader.decodeKey(sstable.partitioner,
                                                             sstable.descriptor,
                                                             ByteBufferUtil.readWithShortLength(file));
            assert keyInDisk.equals(key) : String.format("%s != %s in %s", keyInDisk, key, file.getPath());
            SSTableReader.readRowSize(file, sstable.descriptor);
            read(sstable, file);
        }
        catch (IOException e)
        {
View Full Code Here

Examples of org.apache.cassandra.io.util.FileDataInput

    {
        assert columns != null;
        this.columns = columns;
        this.key = key;

        FileDataInput file = sstable.getFileDataInput(key, DatabaseDescriptor.getIndexedReadBufferSizeInKB() * 1024);
        if (file == null)
            return;

        try
        {
            DecoratedKey keyInDisk = SSTableReader.decodeKey(sstable.partitioner,
                                                             sstable.descriptor,
                                                             ByteBufferUtil.readWithShortLength(file));
            assert keyInDisk.equals(key) : String.format("%s != %s in %s", keyInDisk, key, file.getPath());
            SSTableReader.readRowSize(file, sstable.descriptor);
            read(sstable, file);
        }
        catch (IOException e)
        {
View Full Code Here

Examples of org.apache.cassandra.io.util.FileDataInput

                return info;
        }

        // scan the on-disk index, starting at the nearest sampled position
        long p = sampledPosition.position;
        FileDataInput input;
        if (indexBuffers == null)
        {
            input = new BufferedRandomAccessFile(indexFilename(), "r");
            ((BufferedRandomAccessFile)input).seek(p);
        }
        else
        {
            input = new MappedFileDataInput(indexBuffers[bufferIndex(p)], indexFilename(), (int)(p % BUFFER_SIZE));
        }
        try
        {
            int i = 0;
            do
            {
                DecoratedKey indexDecoratedKey;
                try
                {
                    indexDecoratedKey = partitioner.convertFromDiskFormat(input.readUTF());
                }
                catch (EOFException e)
                {
                    return null;
                }
                long position = input.readLong();
                int v = indexDecoratedKey.compareTo(decoratedKey);
                if (v == 0)
                {
                    PositionSize info;
                    if (!input.isEOF())
                    {
                        int utflen = input.readUnsignedShort();
                        if (utflen != input.skipBytes(utflen))
                            throw new EOFException();
                        info = new PositionSize(position, input.readLong() - position);
                    }
                    else
                    {
                        info = new PositionSize(position, length() - position);
                    }
                    if (keyCache != null && keyCache.getCapacity() > 0)
                        keyCache.put(unifiedKey, info);
                    return info;
                }
                if (v > 0)
                    return null;
            } while  (++i < INDEX_INTERVAL);
        }
        finally
        {
            input.close();
        }
        return null;
    }
View Full Code Here

Examples of org.apache.cassandra.io.util.FileDataInput

        assert columnNames != null;
        this.columns = columnNames;

        DecoratedKey decoratedKey = ssTable.getPartitioner().decorateKey(key);

        FileDataInput file = ssTable.getFileDataInput(decoratedKey, DatabaseDescriptor.getIndexedReadBufferSizeInKB() * 1024);
        if (file == null)
            return;
        try
        {
            DecoratedKey keyInDisk = ssTable.getPartitioner().convertFromDiskFormat(file.readUTF());
            assert keyInDisk.equals(decoratedKey) : keyInDisk;
            file.readInt(); // data size

            /* Read the bloom filter summarizing the columns */
            BloomFilter bf = IndexHelper.defreezeBloomFilter(file);
            List<byte[]> filteredColumnNames = new ArrayList<byte[]>(columnNames.size());
            for (byte[] name : columnNames)
            {
                if (bf.isPresent(name))
                {
                    filteredColumnNames.add(name);
                }
            }
            if (filteredColumnNames.isEmpty())
            {
                return;
            }

            List<IndexHelper.IndexInfo> indexList = IndexHelper.deserializeIndex(file);

            cf = ColumnFamily.serializer().deserializeFromSSTableNoColumns(ssTable.makeColumnFamily(), file);
            file.readInt(); // column count

            /* get the various column ranges we have to read */
            AbstractType comparator = ssTable.getColumnComparator();
            SortedSet<IndexHelper.IndexInfo> ranges = new TreeSet<IndexHelper.IndexInfo>(IndexHelper.getComparator(comparator));
            for (byte[] name : filteredColumnNames)
            {
                int index = IndexHelper.indexFor(name, indexList, comparator, false);
                if (index == indexList.size())
                    continue;
                IndexHelper.IndexInfo indexInfo = indexList.get(index);
                if (comparator.compare(name, indexInfo.firstName) < 0)
                   continue;
                ranges.add(indexInfo);
            }

            file.mark();
            for (IndexHelper.IndexInfo indexInfo : ranges)
            {
                file.reset();
                long curOffsert = file.skipBytes((int)indexInfo.offset);
                assert curOffsert == indexInfo.offset;
                // TODO only completely deserialize columns we are interested in
                while (file.bytesPastMark() < indexInfo.offset + indexInfo.width)
                {
                    final IColumn column = cf.getColumnSerializer().deserialize(file);
                    // we check vs the original Set, not the filtered List, for efficiency
                    if (columnNames.contains(column.name()))
                    {
                        cf.addColumn(column);
                    }
                }
            }
        }
        finally
        {
            file.close();
        }

        iter = cf.getSortedColumns().iterator();
    }
View Full Code Here

Examples of org.apache.cassandra.io.util.FileDataInput

    {
        this.reversed = reversed;

        /* Morph key into actual key based on the partition type. */
        DecoratedKey decoratedKey = ssTable.getPartitioner().decorateKey(key);
        FileDataInput fdi = ssTable.getFileDataInput(decoratedKey, DatabaseDescriptor.getSlicedReadBufferSizeInKB() * 1024);
        this.comparator = ssTable.getColumnComparator();
        this.startColumn = startColumn;
        this.finishColumn = finishColumn;
        if (fdi != null)
            reader = new ColumnGroupReader(ssTable, decoratedKey, fdi);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.