コード例 #1
0
    public boolean getNextBlock() throws IOException {
      if (curRangeIndex < 0 || curRangeIndex >= indexes.size()) return false;

      /* seek to the correct offset to the data, and calculate the data size */
      IndexHelper.IndexInfo curColPosition = indexes.get(curRangeIndex);

      /* see if this read is really necessary. */
      if (reversed) {
        if ((finishColumn.length > 0
                && comparator.compare(finishColumn, curColPosition.lastName) > 0)
            || (startColumn.length > 0
                && comparator.compare(startColumn, curColPosition.firstName) < 0)) return false;
      } else {
        if ((startColumn.length > 0 && comparator.compare(startColumn, curColPosition.lastName) > 0)
            || (finishColumn.length > 0
                && comparator.compare(finishColumn, curColPosition.firstName) < 0)) return false;
      }

      boolean outOfBounds = false;

      // seek to current block
      // curIndexInfo.offset is the relative offset from the first block
      file.seek(firstBlockPos + curColPosition.offset);

      // read all columns of current block into memory!
      DataInputStream blockIn =
          ColumnFamily.serializer()
              .getBlockInputStream(file, curColPosition.sizeOnDisk, compressContext);
      try {
        int size = 0;
        while ((size < curColPosition.width) && !outOfBounds) {
          IColumn column = emptyColumnFamily.getColumnSerializer().deserialize(blockIn);
          size += column.serializedSize();
          if (reversed) blockColumns.addFirst(column);
          else blockColumns.addLast(column);

          /* see if we can stop seeking. */
          if (!reversed && finishColumn.length > 0)
            outOfBounds = comparator.compare(column.name(), finishColumn) >= 0;
          else if (reversed && startColumn.length > 0)
            outOfBounds = comparator.compare(column.name(), startColumn) >= 0;

          if (outOfBounds) break;
        }
      } catch (IOException e) {
        logger.error(e.toString());
        throw e;
      } finally {
        ColumnFamily.serializer().releaseBlockInputStream(blockIn, compressContext);
      }

      if (reversed) curRangeIndex--;
      else curRangeIndex++;
      return true;
    }
コード例 #2
0
 public IColumn pollColumn() {
   IColumn column = blockColumns.poll();
   if (column == null) {
     try {
       if (getNextBlock()) column = blockColumns.poll();
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
   return column;
 }
コード例 #3
0
    public boolean getNextBlock() throws IOException {
      if (curRangeIndex < 0 || curRangeIndex >= indexes.size()) return false;

      /* seek to the correct offset to the data, and calculate the data size */
      IndexHelper.IndexInfo curColPosition = indexes.get(curRangeIndex);

      /* see if this read is really necessary. */
      if (reversed) {
        if ((finishColumn.length > 0
                && comparator.compare(finishColumn, curColPosition.lastName) > 0)
            || (startColumn.length > 0
                && comparator.compare(startColumn, curColPosition.firstName) < 0)) return false;
      } else {
        if ((startColumn.length > 0 && comparator.compare(startColumn, curColPosition.lastName) > 0)
            || (finishColumn.length > 0
                && comparator.compare(finishColumn, curColPosition.firstName) < 0)) return false;
      }

      boolean outOfBounds = false;

      file.reset();
      long curOffset = file.skipBytes((int) curColPosition.offset);
      assert curOffset == curColPosition.offset;
      while (file.bytesPastMark() < curColPosition.offset + curColPosition.width && !outOfBounds) {
        IColumn column = emptyColumnFamily.getColumnSerializer().deserialize(file);
        if (reversed) blockColumns.addFirst(column);
        else blockColumns.addLast(column);

        /* see if we can stop seeking. */
        if (!reversed && finishColumn.length > 0)
          outOfBounds = comparator.compare(column.name(), finishColumn) >= 0;
        else if (reversed && startColumn.length > 0)
          outOfBounds = comparator.compare(column.name(), startColumn) >= 0;

        if (outOfBounds) break;
      }

      if (reversed) curRangeIndex--;
      else curRangeIndex++;
      return true;
    }