/**
  * Returns the first non-static cell in the ColumnFamily. This is necessary to avoid recording a
  * static column as the "last" cell seen in a reversed query. Because we will always query static
  * columns alongside the normal data for a page, they are not a good indicator of where paging
  * should resume. When we begin the next page, we need to start from the last non-static cell.
  */
 protected Column firstNonStaticColumn(ColumnFamily cf) {
   for (Column column : cf) {
     ColumnDefinition def = cfm.getColumnDefinitionFromColumnName(column.name());
     if (def == null || def.type != ColumnDefinition.Type.STATIC) return column;
   }
   return null;
 }
  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);
  }
  public IndexedEntry decodeEntry(DecoratedKey indexedValue, Column indexEntry) {
    int ckCount = baseCfs.metadata.clusteringKeyColumns().size();
    ByteBuffer[] components = getIndexComparator().split(indexEntry.name());

    ColumnNameBuilder builder = getBaseComparator().builder();
    for (int i = 0; i < ckCount; i++) builder.add(components[i + 1]);

    return new IndexedEntry(
        indexedValue, indexEntry.name(), indexEntry.timestamp(), components[0], builder);
  }
Ejemplo n.º 4
0
  public RowMutation toSchema(long timestamp) {
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, SystemTable.getSchemaKSKey(name));
    ColumnFamily cf = rm.addOrGet(SystemTable.SCHEMA_KEYSPACES_CF);

    cf.addColumn(Column.create(name, timestamp, "name"));
    cf.addColumn(Column.create(durableWrites, timestamp, "durable_writes"));
    cf.addColumn(Column.create(strategyClass.getName(), timestamp, "strategy_class"));
    cf.addColumn(Column.create(json(strategyOptions), timestamp, "strategy_options"));

    for (CFMetaData cfm : cfMetaData.values()) cfm.toSchema(rm, timestamp);

    return rm;
  }
 public Column reconcile(Column left, Column right) {
   ClockRelationship cr = left.clock().compare(right.clock());
   switch (cr) {
     case EQUAL:
       // tombstones take precedence.  (if both are tombstones, then it doesn't matter which one we
       // use.)
       if (left.isMarkedForDelete()) return left;
       if (right.isMarkedForDelete()) return right;
       // break ties by comparing values.
       return FBUtilities.compareByteArrays(left.value(), right.value()) < 0 ? right : left;
     case GREATER_THAN:
       return left;
     case LESS_THAN:
       return right;
     default:
       throw new IllegalArgumentException(
           "Timestamp clocks must either be equal, greater then or less than: " + cr);
   }
 }