コード例 #1
0
ファイル: BriskServer.java プロジェクト: thepaul/brisk
  private Integer seekToSubColumn(
      CFMetaData metadata,
      FileDataInput file,
      ByteBuffer sblockId,
      List<IndexHelper.IndexInfo> indexList)
      throws IOException {
    file.readInt(); // column count

    /* get the various column ranges we have to read */
    AbstractType comparator = metadata.comparator;

    int index = IndexHelper.indexFor(sblockId, indexList, comparator, false);
    if (index == indexList.size()) return null;

    IndexHelper.IndexInfo indexInfo = indexList.get(index);
    if (comparator.compare(sblockId, indexInfo.firstName) < 0) return null;

    FileMark mark = file.mark();

    FileUtils.skipBytesFully(file, indexInfo.offset);

    while (file.bytesPastMark(mark) < indexInfo.offset + indexInfo.width) {
      Integer dataLength = isSubBlockFound(metadata, file, sblockId);

      if (dataLength == null) return null;

      if (dataLength < 0) continue;

      return dataLength;
    }

    return null;
  }
コード例 #2
0
ファイル: ReversedType.java プロジェクト: N3xtHub/cassandra
  public int compare(ByteBuffer o1, ByteBuffer o2) {
    // An empty byte buffer is always smaller
    if (o1.remaining() == 0) {
      return o2.remaining() == 0 ? 0 : -1;
    }
    if (o2.remaining() == 0) {
      return 1;
    }

    return baseType.compare(o2, o1);
  }
コード例 #3
0
ファイル: ColumnIndexer.java プロジェクト: AkihiroSuda/PCheck
  /**
   * Given the collection of columns in the Column Family, the name index is generated and written
   * into the provided stream
   *
   * @param columns for whom the name index needs to be generated
   * @param dos stream into which the serialized name index needs to be written.
   * @throws IOException
   */
  private static void doIndexing(
      AbstractType comparator, Collection<IColumn> columns, DataOutput dos) throws IOException {
    if (columns.isEmpty()) {
      dos.writeInt(0);
      return;
    }

    /*
     * Maintains a list of ColumnIndexInfo objects for the columns in this
     * column family. The key is the column name and the position is the
     * relative offset of that column name from the start of the list.
     * We do this so that we don't read all the columns into memory.
     */
    List<IndexHelper.IndexInfo> indexList = new ArrayList<IndexHelper.IndexInfo>();

    int endPosition = 0, startPosition = -1;
    int indexSizeInBytes = 0;
    IColumn column = null, firstColumn = null;
    /* column offsets at the right thresholds into the index map. */
    for (Iterator<IColumn> it = columns.iterator(); it.hasNext(); ) {
      column = it.next();
      if (firstColumn == null) {
        firstColumn = column;
        startPosition = endPosition;
      }
      endPosition += column.serializedSize();
      /* if we hit the column index size that we have to index after, go ahead and index it. */
      if (endPosition - startPosition >= DatabaseDescriptor.getColumnIndexSize()) {
        IndexHelper.IndexInfo cIndexInfo =
            new IndexHelper.IndexInfo(
                firstColumn.name(), column.name(), startPosition, endPosition - startPosition);
        indexList.add(cIndexInfo);
        indexSizeInBytes += cIndexInfo.serializedSize();
        firstColumn = null;
      }
    }
    // the last column may have fallen on an index boundary already.  if not, index it explicitly.
    if (indexList.isEmpty()
        || comparator.compare(indexList.get(indexList.size() - 1).lastName, column.name()) != 0) {
      IndexHelper.IndexInfo cIndexInfo =
          new IndexHelper.IndexInfo(
              firstColumn.name(), column.name(), startPosition, endPosition - startPosition);
      indexList.add(cIndexInfo);
      indexSizeInBytes += cIndexInfo.serializedSize();
    }

    assert indexSizeInBytes > 0;
    dos.writeInt(indexSizeInBytes);
    for (IndexHelper.IndexInfo cIndexInfo : indexList) {
      cIndexInfo.serialize(dos);
    }
  }
コード例 #4
0
ファイル: IndexedSliceReader.java プロジェクト: njanani/src
 private boolean isColumnNeeded(IColumn column) {
   if (startColumn.remaining() == 0 && finishColumn.remaining() == 0) return true;
   else if (startColumn.remaining() == 0 && !reversed)
     return comparator.compare(column.name(), finishColumn) <= 0;
   else if (startColumn.remaining() == 0 && reversed)
     return comparator.compare(column.name(), finishColumn) >= 0;
   else if (finishColumn.remaining() == 0 && !reversed)
     return comparator.compare(column.name(), startColumn) >= 0;
   else if (finishColumn.remaining() == 0 && reversed)
     return comparator.compare(column.name(), startColumn) <= 0;
   else if (!reversed)
     return comparator.compare(column.name(), startColumn) >= 0
         && comparator.compare(column.name(), finishColumn) <= 0;
   else // if reversed
   return comparator.compare(column.name(), startColumn) <= 0
         && comparator.compare(column.name(), finishColumn) >= 0;
 }
コード例 #5
0
ファイル: ListType.java プロジェクト: daidong/GraphTrek
  static int compareListOrSet(AbstractType<?> elementsComparator, ByteBuffer o1, ByteBuffer o2) {
    // Note that this is only used if the collection is inside an UDT
    if (!o1.hasRemaining() || !o2.hasRemaining())
      return o1.hasRemaining() ? 1 : o2.hasRemaining() ? -1 : 0;

    ByteBuffer bb1 = o1.duplicate();
    ByteBuffer bb2 = o2.duplicate();

    int size1 = CollectionSerializer.readCollectionSize(bb1, 3);
    int size2 = CollectionSerializer.readCollectionSize(bb2, 3);

    for (int i = 0; i < Math.min(size1, size2); i++) {
      ByteBuffer v1 = CollectionSerializer.readValue(bb1, 3);
      ByteBuffer v2 = CollectionSerializer.readValue(bb2, 3);
      int cmp = elementsComparator.compare(v1, v2);
      if (cmp != 0) return cmp;
    }

    return size1 == size2 ? 0 : (size1 < size2 ? -1 : 1);
  }
コード例 #6
0
 @Override
 public int compareTo(Token<byte[]> o) {
   return comparator.compare(token, o.token);
 }