コード例 #1
0
  public boolean announceMigration(boolean isLocalOnly) throws RequestValidationException {
    CFMetaData cfm = Schema.instance.getCFMetaData(keyspace(), columnFamily()).copy();
    IndexTarget target = rawTarget.prepare(cfm);
    logger.debug("Updating column {} definition for index {}", target.column, indexName);
    ColumnDefinition cd = cfm.getColumnDefinition(target.column);

    if (cd.getIndexType() != null && ifNotExists) return false;

    if (properties.isCustom) {
      cd.setIndexType(IndexType.CUSTOM, properties.getOptions());
    } else if (cfm.comparator.isCompound()) {
      Map<String, String> options = Collections.emptyMap();
      // For now, we only allow indexing values for collections, but we could later allow
      // to also index map keys, so we record that this is the values we index to make our
      // lives easier then.
      if (cd.type.isCollection() && cd.type.isMultiCell())
        options =
            ImmutableMap.of(
                target.isCollectionKeys
                    ? SecondaryIndex.INDEX_KEYS_OPTION_NAME
                    : SecondaryIndex.INDEX_VALUES_OPTION_NAME,
                "");
      cd.setIndexType(IndexType.COMPOSITES, options);
    } else {
      cd.setIndexType(IndexType.KEYS, Collections.<String, String>emptyMap());
    }

    cd.setIndexName(indexName);
    cfm.addDefaultIndexNames();
    MigrationManager.announceColumnFamilyUpdate(cfm, false, isLocalOnly);
    return true;
  }