コード例 #1
0
ファイル: SuperColumn.java プロジェクト: jbellis/helenus
 public byte[] value(String key) {
   IColumn column = columns_.get(key);
   if (column instanceof SuperColumn)
     throw new UnsupportedOperationException("A super column cannot hold other super columns.");
   if (column != null) return column.value();
   throw new IllegalArgumentException("Value was requested for a column that does not exist.");
 }
コード例 #2
0
  public SuperColumn get_super_column(
      String table, String key, SuperColumnPath super_column_path, int consistency_level)
      throws InvalidRequestException, NotFoundException {
    if (logger.isDebugEnabled()) logger.debug("get_superColumn");
    ThriftValidation.validateSuperColumnPath(table, super_column_path);

    ColumnFamily cfamily =
        readColumnFamily(
            new SliceByNamesReadCommand(
                table,
                key,
                new QueryPath(super_column_path.column_family),
                Arrays.asList(super_column_path.super_column)),
            consistency_level);
    if (cfamily == null) {
      throw new NotFoundException();
    }
    Collection<IColumn> columns = cfamily.getSortedColumns();
    if (columns == null || columns.size() == 0) {
      throw new NotFoundException();
    }

    assert columns.size() == 1;
    IColumn column = columns.iterator().next();
    if (column.getSubColumns().size() == 0) {
      throw new NotFoundException();
    }

    return new SuperColumn(column.name(), thriftifyColumns(column.getSubColumns()));
  }
コード例 #3
0
ファイル: SuperColumn.java プロジェクト: jbellis/helenus
 public String name(String key) {
   IColumn column = columns_.get(key);
   if (column instanceof SuperColumn)
     throw new UnsupportedOperationException("A super column cannot hold other super columns.");
   if (column != null) return column.name();
   return null;
 }
コード例 #4
0
ファイル: NodeColumns.java プロジェクト: nextjava/craken
 public boolean contains(String key) {
   for (IColumn col : columnList) {
     if (key.equalsIgnoreCase(col.getLabel())) {
       return true;
     }
   }
   return false;
 }
コード例 #5
0
ファイル: SuperColumn.java プロジェクト: jbellis/helenus
 /** This calculates the exact size of the sub columns on the fly */
 int getSizeOfAllColumns() {
   int size = 0;
   Collection<IColumn> subColumns = getSubColumns();
   for (IColumn subColumn : subColumns) {
     size += subColumn.serializedSize();
   }
   return size;
 }
コード例 #6
0
  private boolean hasLeftColumn() {
    for (IColumn column : columns) {
      if (column.getLocation().getAlignment().equals(Alignment.LEFT)) {
        return true;
      }
    }

    return false;
  }
コード例 #7
0
ファイル: SuperColumn.java プロジェクト: jbellis/helenus
 public byte[] digest() {
   Set<IColumn> columns = columns_.getSortedColumns();
   byte[] xorHash = new byte[0];
   if (name_ == null) return xorHash;
   xorHash = name_.getBytes();
   for (IColumn column : columns) {
     xorHash = FBUtilities.xor(xorHash, column.digest());
   }
   return xorHash;
 }
コード例 #8
0
ファイル: QueryFilter.java プロジェクト: njanani/src
 public static boolean isRelevant(IColumn column, IColumnContainer container, int gcBefore) {
   // the column itself must be not gc-able (it is live, or a still relevant tombstone, or has live
   // subcolumns), (1)
   // and if its container is deleted, the column must be changed more recently than the container
   // tombstone (2)
   // (since otherwise, the only thing repair cares about is the container tombstone)
   long maxChange = column.mostRecentNonGCableChangeAt(gcBefore);
   return (column.getLocalDeletionTime() >= gcBefore
           || maxChange > column.getMarkedForDeleteAt()) // (1)
       && (!container.isMarkedForDelete() || maxChange > container.getMarkedForDeleteAt()); // (2)
 }
コード例 #9
0
ファイル: SuperColumn.java プロジェクト: jbellis/helenus
  private void fillSuperColumn(IColumn superColumn, DataInputStream dis) throws IOException {
    if (dis.available() == 0) return;

    /* read the number of columns */
    int size = dis.readInt();
    /* read the size of all columns */
    dis.readInt();
    for (int i = 0; i < size; ++i) {
      IColumn subColumn = Column.serializer().deserialize(dis);
      superColumn.addColumn(subColumn.name(), subColumn);
    }
  }
コード例 #10
0
ファイル: NodeColumns.java プロジェクト: nextjava/craken
  private RowSetMetaData getMetaType(ReadNode node) throws SQLException {
    RowSetMetaData meta = new RowSetMetaDataImpl();

    int sumSize = getColumnSize(node);

    meta.setColumnCount(sumSize);
    int appendIndex = 0;
    for (int i = 1; i <= size(); i++) {
      IColumn column = columnList.get(i - 1);
      appendIndex += column.setMeta(node, appendIndex + i, meta, TypeMappingMap);
    }

    return meta;
  }
コード例 #11
0
 public static void assertColumns(ColumnFamily cf, String... columnNames) {
   Collection<IColumn> columns = cf == null ? new TreeSet<IColumn>() : cf.getSortedColumns();
   List<String> L = new ArrayList<String>();
   for (IColumn column : columns) {
     L.add(new String(column.name()));
   }
   assert Arrays.equals(L.toArray(new String[columns.size()]), columnNames)
       : "Columns ["
           + ((cf == null) ? "" : cf.getComparator().getColumnsString(columns))
           + "]"
           + " is not expected ["
           + StringUtils.join(columnNames, ",")
           + "]";
 }
コード例 #12
0
  /** @see AbstractTree#onBeforeAttach() */
  @Override
  protected void onBeforeAttach() {
    // has the header been added yet?
    if (get("sideColumns") == null) {
      // no. initialize columns first
      if (columns != null) {
        for (IColumn column : columns) {
          column.setTreeTable(this);
        }
      }

      // add the tree table header
      addHeader();
    }
  }
コード例 #13
0
ファイル: NodeColumns.java プロジェクト: nextjava/craken
  private RowSetMetaData defaultMetaType() throws SQLException {
    RowSetMetaData meta = new RowSetMetaDataImpl();
    meta.setColumnCount(size());

    for (int i = 1; i <= size(); i++) {
      IColumn column = columnList.get(i - 1);

      meta.setColumnName(i, column.getLabel());
      meta.setColumnLabel(i, column.getLabel());
      meta.setColumnType(i, Types.OTHER);
      meta.setColumnTypeName(i, "other");
    }

    return meta;
  }
コード例 #14
0
ファイル: BriskServer.java プロジェクト: thepaul/brisk
  private IColumn validateAndGetColumn(List<Row> rows, ByteBuffer columnName)
      throws NotFoundException {
    if (rows.isEmpty()) throw new NotFoundException();

    if (rows.size() > 1) throw new RuntimeException("Block id returned more than one row");

    Row row = rows.get(0);
    if (row.cf == null) throw new NotFoundException();

    IColumn col = row.cf.getColumn(columnName);

    if (col == null || !col.isLive()) throw new NotFoundException();

    return col;
  }
コード例 #15
0
  /** for resultsets of standard columns */
  private List<Column> getSlice(ReadCommand command, int consistency_level)
      throws InvalidRequestException {
    ColumnFamily cfamily = readColumnFamily(command, consistency_level);
    boolean reverseOrder = false;

    if (command instanceof SliceFromReadCommand)
      reverseOrder = !((SliceFromReadCommand) command).isAscending;

    if (cfamily == null || cfamily.getColumnsMap().size() == 0) {
      return EMPTY_COLUMNS;
    }
    if (cfamily.isSuper()) {
      IColumn column = cfamily.getColumnsMap().values().iterator().next();
      return thriftifyColumns(column.getSubColumns(), reverseOrder);
    }
    return thriftifyColumns(cfamily.getSortedColumns(), reverseOrder);
  }
コード例 #16
0
ファイル: SuperColumn.java プロジェクト: jbellis/helenus
  public IColumn deserialize(DataInputStream dis, IFilter filter) throws IOException {
    if (dis.available() == 0) return null;

    IColumn superColumn = defreezeSuperColumn(dis);
    superColumn = filter.filter(superColumn, dis);
    if (superColumn != null) {
      if (!superColumn.isMarkedForDelete()) fillSuperColumn(superColumn, dis);
      return superColumn;
    } else {
      /* read the number of columns stored */
      dis.readInt();
      /* read the size of all columns to skip */
      int size = dis.readInt();
      dis.skip(size);
      return null;
    }
  }
コード例 #17
0
  @Test
  public void testGetColumn() throws IOException, ColumnFamilyNotDefinedException {
    Table table = Table.open("Keyspace1");
    RowMutation rm;

    // add data
    rm = new RowMutation("Keyspace1", "key1");
    rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), "abcd".getBytes(), 0);
    rm.apply();

    ReadCommand command =
        new SliceByNamesReadCommand(
            "Keyspace1", "key1", new QueryPath("Standard1"), Arrays.asList("Column1".getBytes()));
    Row row = command.getRow(table);
    IColumn col = row.cf.getColumn("Column1".getBytes());
    assert Arrays.equals(col.value(), "abcd".getBytes());
  }
コード例 #18
0
ファイル: BriskServer.java プロジェクト: thepaul/brisk
  private LocalOrRemoteBlock getRemoteSubBlock(
      ByteBuffer blockId, ByteBuffer sblockId, int offset, ColumnParent subBlockDataPath)
      throws TimedOutException, UnavailableException, InvalidRequestException, NotFoundException {
    // The column name is the SubBlock id (UUID)
    ReadCommand rc =
        new SliceByNamesReadCommand(
            cfsKeyspace, blockId, subBlockDataPath, Arrays.asList(sblockId));

    try {
      // CL=ONE as there are NOT multiple versions of the blocks.
      List<Row> rows = StorageProxy.read(Arrays.asList(rc), ConsistencyLevel.ONE);

      IColumn col = null;
      try {
        col = validateAndGetColumn(rows, sblockId);
      } catch (NotFoundException e) {
        // This is a best effort to get the value. Sometimes due to the size of
        // the sublocks, the normal replication may time out leaving a replicate without
        // the piece of data. Hence we re try with higher CL.
        rows = StorageProxy.read(Arrays.asList(rc), ConsistencyLevel.QUORUM);
      }

      col = validateAndGetColumn(rows, sblockId);

      ByteBuffer value = col.value();

      if (value.remaining() < offset)
        throw new InvalidRequestException("Invalid offset for block of size: " + value.remaining());

      LocalOrRemoteBlock block = new LocalOrRemoteBlock();
      if (offset > 0) {
        ByteBuffer offsetBlock = value.duplicate();
        offsetBlock.position(offsetBlock.position() + offset);
        block.setRemote_block(offsetBlock);
      } else {
        block.setRemote_block(value);
      }

      return block;
    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (TimeoutException e) {
      throw new TimedOutException();
    }
  }
コード例 #19
0
  /** Adds the header to the TreeTable. */
  protected void addHeader() {
    // create the view for side columns
    SideColumnsView sideColumns = new SideColumnsView("sideColumns", null);
    add(sideColumns);
    if (columns != null) {
      for (int i = 0; i < columns.length; i++) {
        IColumn column = columns[i];
        if ((column.getLocation().getAlignment() == Alignment.LEFT)
            || (column.getLocation().getAlignment() == Alignment.RIGHT)) {
          TreeTableItem component = new TreeTableItem(i);
          Component cell = column.newHeader(sideColumns, TreeTableItem.ID);
          component.add(cell);
          sideColumns.addColumn(column, component, null);
        }
      }
    }

    // create the view for middle columns
    MiddleColumnsView middleColumns = new MiddleColumnsView("middleColumns", null, hasLeftColumn());
    add(middleColumns);
    if (columns != null) {
      for (int i = 0; i < columns.length; i++) {
        IColumn column = columns[i];
        if (column.getLocation().getAlignment() == Alignment.MIDDLE) {
          TreeTableItem component = new TreeTableItem(i);
          Component cell = column.newHeader(middleColumns, TreeTableItem.ID);
          component.add(cell);
          middleColumns.addColumn(column, component, null);
        }
      }
    }
  }
コード例 #20
0
  public Column get_column(String table, String key, ColumnPath column_path, int consistency_level)
      throws InvalidRequestException, NotFoundException {
    if (logger.isDebugEnabled()) logger.debug("get_column");
    ThriftValidation.validateColumnPath(table, column_path);

    QueryPath path = new QueryPath(column_path.column_family, column_path.super_column);
    ColumnFamily cfamily =
        readColumnFamily(
            new SliceByNamesReadCommand(table, key, path, Arrays.asList(column_path.column)),
            consistency_level);
    // TODO can we leverage getSlice here and just check that it returns one column?
    if (cfamily == null) {
      throw new NotFoundException();
    }
    Collection<IColumn> columns = null;
    if (column_path.super_column != null) {
      IColumn column = cfamily.getColumn(column_path.super_column);
      if (column != null) {
        columns = column.getSubColumns();
      }
    } else {
      columns = cfamily.getSortedColumns();
    }
    if (columns == null || columns.size() == 0) {
      throw new NotFoundException();
    }

    assert columns.size() == 1;
    IColumn column = columns.iterator().next();
    if (column.isMarkedForDelete()) {
      throw new NotFoundException();
    }

    return new Column(column.name(), column.value(), column.timestamp());
  }
コード例 #21
0
ファイル: SuperColumn.java プロジェクト: jbellis/helenus
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(name_);
    sb.append(":");
    sb.append(isMarkedForDelete());
    sb.append(":");

    Collection<IColumn> columns = getSubColumns();
    sb.append(columns.size());
    sb.append(":");
    sb.append(size());
    sb.append(":");
    for (IColumn subColumn : columns) {
      sb.append(subColumn.toString());
    }
    sb.append(":");
    return sb.toString();
  }
コード例 #22
0
  public List<Column> thriftifyColumns(Collection<IColumn> columns, boolean reverseOrder) {
    if (columns == null || columns.isEmpty()) {
      return EMPTY_COLUMNS;
    }

    ArrayList<Column> thriftColumns = new ArrayList<Column>(columns.size());
    for (IColumn column : columns) {
      if (column.isMarkedForDelete()) {
        continue;
      }
      Column thrift_column = new Column(column.name(), column.value(), column.timestamp());
      thriftColumns.add(thrift_column);
    }

    // we have to do the reversing here, since internally we pass results around in ColumnFamily
    // objects, which always sort their columns in the "natural" order
    if (reverseOrder) Collections.reverse(thriftColumns);
    return thriftColumns;
  }
コード例 #23
0
  private List<SuperColumn> thriftifySuperColumns(
      Collection<IColumn> columns, boolean reverseOrder) {
    if (columns == null || columns.isEmpty()) {
      return EMPTY_SUPERCOLUMNS;
    }

    ArrayList<SuperColumn> thriftSuperColumns = new ArrayList<SuperColumn>(columns.size());
    for (IColumn column : columns) {
      List<Column> subcolumns = thriftifyColumns(column.getSubColumns());
      if (subcolumns.isEmpty()) {
        continue;
      }
      thriftSuperColumns.add(new SuperColumn(column.name(), subcolumns));
    }

    if (reverseOrder) Collections.reverse(thriftSuperColumns);

    return thriftSuperColumns;
  }
コード例 #24
0
ファイル: SuperColumn.java プロジェクト: jbellis/helenus
  /*
   * Deserialize a particular column since the name is in the form of
   * superColumn:column.
   */
  public IColumn deserialize(DataInputStream dis, String name, IFilter filter) throws IOException {
    if (dis.available() == 0) return null;

    String[] names = RowMutation.getColumnAndColumnFamily(name);
    if (names.length == 1) {
      IColumn superColumn = defreezeSuperColumn(dis);
      if (name.equals(superColumn.name())) {
        if (!superColumn.isMarkedForDelete()) {
          /* read the number of columns stored */
          int size = dis.readInt();
          /* read the size of all columns */
          dis.readInt();
          IColumn column = null;
          for (int i = 0; i < size; ++i) {
            column = Column.serializer().deserialize(dis, filter);
            if (column != null) {
              superColumn.addColumn(column.name(), column);
              column = null;
              if (filter.isDone()) {
                break;
              }
            }
          }
        }
        return superColumn;
      } else {
        /* read the number of columns stored */
        dis.readInt();
        /* read the size of all columns to skip */
        int size = dis.readInt();
        dis.skip(size);
        return null;
      }
    }

    SuperColumn superColumn = defreezeSuperColumn(dis);
    if (!superColumn.isMarkedForDelete()) {
      int size = dis.readInt();
      /* skip the size of the columns */
      dis.readInt();
      if (size > 0) {
        for (int i = 0; i < size; ++i) {
          IColumn subColumn = Column.serializer().deserialize(dis, names[1], filter);
          if (subColumn != null) {
            superColumn.addColumn(subColumn.name(), subColumn);
            break;
          }
        }
      }
    }
    return superColumn;
  }
コード例 #25
0
  public int get_column_count(
      String table, String key, ColumnParent column_parent, int consistency_level)
      throws InvalidRequestException {
    if (logger.isDebugEnabled()) logger.debug("get_column_count");
    // validateColumnParent assumes we require simple columns; g_c_c is the only
    // one of the columnParent-taking apis that can also work at the SC level.
    // so we roll a one-off validator here.
    String cfType = ThriftValidation.validateColumnFamily(table, column_parent.column_family);
    if (cfType.equals("Standard") && column_parent.super_column != null) {
      throw new InvalidRequestException(
          "columnfamily alone is required for standard CF " + column_parent.column_family);
    }

    ColumnFamily cfamily;
    cfamily =
        readColumnFamily(
            new SliceFromReadCommand(
                table,
                key,
                column_parent,
                ArrayUtils.EMPTY_BYTE_ARRAY,
                ArrayUtils.EMPTY_BYTE_ARRAY,
                true,
                Integer.MAX_VALUE),
            consistency_level);
    if (cfamily == null) {
      return 0;
    }
    Collection<IColumn> columns = null;
    if (column_parent.super_column != null) {
      IColumn column = cfamily.getColumn(column_parent.super_column);
      if (column != null) {
        columns = column.getSubColumns();
      }
    } else {
      columns = cfamily.getSortedColumns();
    }
    if (columns == null || columns.size() == 0) {
      return 0;
    }
    return columns.size();
  }
コード例 #26
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);
    }
  }
コード例 #27
0
ファイル: SuperColumn.java プロジェクト: jbellis/helenus
  public void repair(IColumn column) {
    Collection<IColumn> columns = column.getSubColumns();

    for (IColumn subColumn : columns) {
      IColumn columnInternal = columns_.get(subColumn.name());
      if (columnInternal == null) columns_.put(subColumn.name(), subColumn);
      else columnInternal.repair(subColumn);
    }
  }
コード例 #28
0
  /**
   * Adds a column to be rendered at the right side of the table.
   *
   * @param column The column to add
   * @param component The component
   * @param renderable The renderer
   * @param position where to put the column - at the right or left side
   */
  public void addColumn(
      final IColumn column, Component component, final IRenderable renderable, Position position) {
    if (component != null) {
      add(component);
    }

    if (column.isVisible()) {
      if (position == Position.APPEND) {
        columns.add(column);
        components.add(component);
        renderables.add(renderable);
      } else {
        columns.add(0, column);
        components.add(0, component);
        renderables.add(0, renderable);
      }
    }
  }
コード例 #29
0
ファイル: SuperColumn.java プロジェクト: jbellis/helenus
  /*
   * Go through each sub column if it exists then as it to resolve itself if the
   * column does not exist then create it.
   */
  public boolean putColumn(IColumn column) {
    if (!(column instanceof SuperColumn))
      throw new UnsupportedOperationException("Only Super column objects should be put here");
    if (!name_.equals(column.name()))
      throw new IllegalArgumentException(
          "The name should match the name of the current column or super column");
    Collection<IColumn> columns = column.getSubColumns();

    for (IColumn subColumn : columns) {
      IColumn columnInternal = columns_.get(subColumn.name());
      if (columnInternal == null) {
        addColumn(subColumn.name(), subColumn);
      } else {
        columnInternal.putColumn(subColumn);
      }
    }
    return false;
  }
コード例 #30
0
ファイル: ColumnIndexer.java プロジェクト: AkihiroSuda/PCheck
  /**
   * Create a bloom filter that contains the subcolumns and the columns that make up this Column
   * Family.
   *
   * @param columns columns of the ColumnFamily
   * @return BloomFilter with the summarized information.
   */
  private static BloomFilter createColumnBloomFilter(Collection<IColumn> columns) {
    int columnCount = 0;
    for (IColumn column : columns) {
      columnCount += column.getObjectCount();
    }

    BloomFilter bf = BloomFilter.getFilter(columnCount, 4);
    for (IColumn column : columns) {
      bf.add(column.name());
      /* If this is SuperColumn type Column Family we need to get the subColumns too. */
      if (column instanceof SuperColumn) {
        Collection<IColumn> subColumns = column.getSubColumns();
        for (IColumn subColumn : subColumns) {
          bf.add(subColumn.name());
        }
      }
    }
    return bf;
  }