コード例 #1
0
    public PagedRangeCommand deserialize(DataInput in, int version) throws IOException {
      String keyspace = in.readUTF();
      String columnFamily = in.readUTF();
      long timestamp = in.readLong();

      AbstractBounds<RowPosition> keyRange =
          AbstractBounds.serializer.deserialize(in, version).toRowBounds();

      SliceQueryFilter predicate = SliceQueryFilter.serializer.deserialize(in, version);

      ByteBuffer start = ByteBufferUtil.readWithShortLength(in);
      ByteBuffer stop = ByteBufferUtil.readWithShortLength(in);

      int filterCount = in.readInt();
      List<IndexExpression> rowFilter = new ArrayList<IndexExpression>(filterCount);
      for (int i = 0; i < filterCount; i++) {
        IndexExpression expr =
            new IndexExpression(
                ByteBufferUtil.readWithShortLength(in),
                IndexExpression.Operator.findByOrdinal(in.readInt()),
                ByteBufferUtil.readWithShortLength(in));
        rowFilter.add(expr);
      }

      int limit = in.readInt();
      return new PagedRangeCommand(
          keyspace, columnFamily, timestamp, keyRange, predicate, start, stop, rowFilter, limit);
    }
コード例 #2
0
 public static QueryPath deserialize(DataInput din) throws IOException {
   String cfName = din.readUTF();
   ByteBuffer scName = ByteBufferUtil.readWithShortLength(din);
   ByteBuffer cName = ByteBufferUtil.readWithShortLength(din);
   return new QueryPath(
       cfName.isEmpty() ? null : cfName,
       scName.remaining() == 0 ? null : scName,
       cName.remaining() == 0 ? null : cName);
 }
コード例 #3
0
ファイル: IndexedSliceReader.java プロジェクト: njanani/src
 private void setToRowStart(SSTableReader reader, RowIndexEntry indexEntry, FileDataInput input)
     throws IOException {
   if (input == null) {
     this.file = sstable.getFileDataInput(indexEntry.position);
   } else {
     this.file = input;
     input.seek(indexEntry.position);
   }
   sstable.decodeKey(ByteBufferUtil.readWithShortLength(file));
   SSTableReader.readRowSize(file, sstable.descriptor);
 }
コード例 #4
0
ファイル: BriskServer.java プロジェクト: thepaul/brisk
  /**
   * Checks if the current column is the one we are looking for
   *
   * @param metadata
   * @param file
   * @param sblockId
   * @return if > 0 the length to read from current file offset. if -1 not relevent. if null out of
   *     bounds
   */
  private Integer isSubBlockFound(CFMetaData metadata, FileDataInput file, ByteBuffer sblockId)
      throws IOException {
    ByteBuffer name = ByteBufferUtil.readWithShortLength(file);

    // Stop if we've gone too far (return null)
    if (metadata.comparator.compare(name, sblockId) > 0) return null;

    // verify column type;
    int b = file.readUnsignedByte();

    // skip ts (since we know block ids are unique)
    long ts = file.readLong();
    int sblockLength = file.readInt();

    if (!name.equals(sblockId)
        || (b & ColumnSerializer.DELETION_MASK) != 0
        || (b & ColumnSerializer.EXPIRATION_MASK) != 0) {
      FileUtils.skipBytesFully(file, sblockLength);
      return -1;
    }

    return sblockLength;
  }
コード例 #5
0
ファイル: BriskServer.java プロジェクト: thepaul/brisk
  /**
   * Retrieves a local subBlock
   *
   * @param blockId row key
   * @param sblockId SubBlock column name
   * @param offset inside the sblock
   * @return a local sublock
   * @throws TException
   */
  private LocalBlock getLocalSubBlock(
      String subBlockCFName, ByteBuffer blockId, ByteBuffer sblockId, int offset)
      throws TException {
    DecoratedKey<Token<?>> decoratedKey =
        new DecoratedKey<Token<?>>(StorageService.getPartitioner().getToken(blockId), blockId);

    Table table = Table.open(cfsKeyspace);
    ColumnFamilyStore sblockStore = table.getColumnFamilyStore(subBlockCFName);

    Collection<SSTableReader> sstables = sblockStore.getSSTables();

    for (SSTableReader sstable : sstables) {

      long position = sstable.getPosition(decoratedKey, Operator.EQ);

      if (position == -1) continue;

      String filename = sstable.descriptor.filenameFor(Component.DATA);
      RandomAccessFile raf = null;
      int mappedLength = -1;
      MappedByteBuffer mappedData = null;
      MappedFileDataInput file = null;
      try {
        raf = new RandomAccessFile(filename, "r");
        assert position < raf.length();

        mappedLength =
            (raf.length() - position) < Integer.MAX_VALUE
                ? (int) (raf.length() - position)
                : Integer.MAX_VALUE;

        mappedData = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, position, mappedLength);

        file = new MappedFileDataInput(mappedData, filename, 0);

        if (file == null) continue;

        // Verify key was found in data file
        DecoratedKey keyInDisk =
            SSTableReader.decodeKey(
                sstable.partitioner, sstable.descriptor, ByteBufferUtil.readWithShortLength(file));
        assert keyInDisk.equals(decoratedKey)
            : String.format("%s != %s in %s", keyInDisk, decoratedKey, file.getPath());

        long rowSize = SSTableReader.readRowSize(file, sstable.descriptor);

        assert rowSize > 0;
        assert rowSize < mappedLength;

        Filter bf = IndexHelper.defreezeBloomFilter(file, sstable.descriptor.usesOldBloomFilter);

        // verify this column in in this version of the row.
        if (!bf.isPresent(sblockId)) continue;

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

        // we can stop early if bloom filter says none of the
        // columns actually exist -- but,
        // we can't stop before initializing the cf above, in
        // case there's a relevant tombstone
        ColumnFamilySerializer serializer = ColumnFamily.serializer();
        try {
          ColumnFamily cf =
              serializer.deserializeFromSSTableNoColumns(
                  ColumnFamily.create(sstable.metadata), file);

          if (cf.isMarkedForDelete()) continue;

        } catch (Exception e) {
          e.printStackTrace();

          throw new IOException(
              serializer
                  + " failed to deserialize "
                  + sstable.getColumnFamilyName()
                  + " with "
                  + sstable.metadata
                  + " from "
                  + file,
              e);
        }

        Integer sblockLength = null;

        if (indexList == null) sblockLength = seekToSubColumn(sstable.metadata, file, sblockId);
        else sblockLength = seekToSubColumn(sstable.metadata, file, sblockId, indexList);

        if (sblockLength == null || sblockLength < 0) continue;

        int bytesReadFromStart = mappedLength - (int) file.bytesRemaining();

        if (logger.isDebugEnabled())
          logger.debug("BlockLength = " + sblockLength + " Availible " + file.bytesRemaining());

        assert offset <= sblockLength : String.format("%d > %d", offset, sblockLength);

        long dataOffset = position + bytesReadFromStart;

        if (file.bytesRemaining() == 0 || sblockLength == 0) continue;

        return new LocalBlock(file.getPath(), dataOffset + offset, sblockLength - offset);

      } catch (IOException e) {
        throw new TException(e);
      } finally {
        FileUtils.closeQuietly(raf);
      }
    }

    return null;
  }
コード例 #6
0
 public ByteBuffer deserialize(DataInput dis) throws IOException {
   return ByteBufferUtil.readWithShortLength(dis);
 }
コード例 #7
0
ファイル: Row.java プロジェクト: nunezro2/cassandra_cs597
 public Row deserialize(DataInput in, int version, ColumnSerializer.Flag flag)
     throws IOException {
   return new Row(
       StorageService.getPartitioner().decorateKey(ByteBufferUtil.readWithShortLength(in)),
       ColumnFamily.serializer.deserialize(in, flag, version));
 }