Example usage for org.apache.cassandra.schema IndexMetadata isCustom

List of usage examples for org.apache.cassandra.schema IndexMetadata isCustom

Introduction

In this page you can find the example usage for org.apache.cassandra.schema IndexMetadata isCustom.

Prototype

public boolean isCustom() 

Source Link

Usage

From source file:org.elassandra.action.admin.indices.rebuild.TransportShardRebuildAction.java

License:Apache License

@Override
protected Tuple<ActionWriteResponse, ShardRebuildRequest> shardOperationOnPrimary(MetaData metaData,
        ShardRebuildRequest shardRequest) throws Throwable {
    IndexService indexService = indicesService.indexServiceSafe(shardRequest.shardId().getIndex());
    List<String> tables = new ArrayList<String>();
    List<String> indexes = new ArrayList<String>();
    IndexMetaData indexMetaData = metaData.index(shardRequest.shardId().getIndex());
    String secondaryIndexClass = indexMetaData.getSettings().get(IndexMetaData.SETTING_SECONDARY_INDEX_CLASS,
            metaData.settings().get(InternalCassandraClusterService.SETTING_CLUSTER_SECONDARY_INDEX_CLASS,
                    InternalCassandraClusterService.defaultSecondaryIndexClass.getName()));
    for (ObjectCursor<MappingMetaData> it : indexMetaData.getMappings().values()) {
        MappingMetaData mapping = it.value;
        String table = InternalCassandraClusterService.typeToCfName(mapping.type());
        tables.add(table);/*from  w  ww. j  a  v a 2  s.  co m*/
        CFMetaData cfMetadata = InternalCassandraClusterService.getCFMetaData(indexService.keyspace(), table);
        for (IndexMetadata index : cfMetadata.getIndexes()) {
            if (index.isCustom() && secondaryIndexClass.equals(index.options.get("class_name"))) {
                indexes.add(index.name);
                break;
            }
        }
    }

    // Cassandra flush and rebuild_index for all mapped tables.
    StorageService.instance.forceKeyspaceFlush(indexService.keyspace(),
            tables.toArray(new String[tables.size()]));
    for (int i = 0; i < tables.size(); i++)
        StorageService.instance.rebuildSecondaryIndex(shardRequest.getRequest().numThreads(),
                indexService.keyspace(), tables.get(i), indexes.get(i));

    logger.trace("index=[{}] rebuild request executed on keyspace=[{}] tables={} with numThreads={}",
            shardRequest.shardId().getIndex(), indexService.keyspace(), tables,
            shardRequest.getRequest().numThreads());
    return new Tuple<>(new ActionWriteResponse(), shardRequest);
}