private int discardHead(
      ColumnFamily cf,
      int toDiscard,
      ColumnFamily copy,
      Iterator<Column> iter,
      DeletionInfo.InOrderTester tester) {
    ColumnCounter counter = columnCounter();

    List<Column> staticColumns = new ArrayList<>(cfm.staticColumns().size());

    // Discard the first 'toDiscard' live, non-static columns
    while (iter.hasNext()) {
      Column c = iter.next();

      // if it's a static column, don't count it and save it to add to the trimmed results
      ColumnDefinition columnDef = cfm.getColumnDefinitionFromColumnName(c.name());
      if (columnDef != null && columnDef.type == ColumnDefinition.Type.STATIC) {
        staticColumns.add(c);
        continue;
      }

      counter.count(c, tester);

      // once we've discarded the required amount, add the rest
      if (counter.live() > toDiscard) {
        for (Column staticColumn : staticColumns) copy.addColumn(staticColumn);

        copy.addColumn(c);
        while (iter.hasNext()) copy.addColumn(iter.next());
      }
    }
    return Math.min(counter.live(), toDiscard);
  }
Esempio n. 2
0
 public int lastCounted() {
   // If we have a slice limit set, columnCounter.live() can overcount by one because we have to
   // call
   // columnCounter.count() before we can tell if we've exceeded the slice limit (and accordingly,
   // should not
   // add the cells to returned container).  To deal with this overcounting, we take the min of the
   // slice
   // limit and the counter's count.
   return columnCounter == null ? 0 : Math.min(columnCounter.live(), count);
 }
  private int discardTail(
      ColumnFamily cf,
      int toDiscard,
      ColumnFamily copy,
      Iterator<Column> iter,
      DeletionInfo.InOrderTester tester) {
    // Redoing the counting like that is not extremely efficient.
    // This is called only for reversed slices or in the case of a race between
    // paging and a deletion (pretty unlikely), so this is probably acceptable.
    int liveCount = columnCounter().countAll(cf).live();

    ColumnCounter counter = columnCounter();
    // Discard the last 'toDiscard' live (so stop adding as sound as we're past 'liveCount -
    // toDiscard')
    while (iter.hasNext()) {
      Column c = iter.next();
      counter.count(c, tester);
      if (counter.live() > liveCount - toDiscard) break;

      copy.addColumn(c);
    }
    return Math.min(liveCount, toDiscard);
  }
 private int nextPageSize(int pageSize) {
   return Math.min(remaining, pageSize) + (lastWasRecorded ? 1 : 0);
 }
Esempio n. 5
0
 public static void assertMaxTimestamp(ColumnFamilyStore cfs, long maxTimestampExpected) {
   long maxTimestampObserved = Long.MIN_VALUE;
   for (SSTableReader sstable : cfs.getSSTables())
     maxTimestampObserved = Math.max(sstable.getMaxTimestamp(), maxTimestampObserved);
   assertEquals(maxTimestampExpected, maxTimestampObserved);
 }