Search in sources :

Example 1 with RowIndexSupport

use of com.tuplejump.stargate.cassandra.RowIndexSupport in project stargate-core by tuplejump.

the class IndexEventHandler method onEvent.

@Override
public void onEvent(IndexEntryEvent event, long sequence, boolean endOfBatch) throws Exception {
    if ((sequence % numberOfConsumers) == ordinal) {
        ByteBuffer rowkeyBuffer = event.getRowKey();
        ColumnFamily columnFamily = event.getColumnFamily();
        final RowIndexSupport rowIndexSupport = indexingService.support.get(columnFamily.metadata().cfName);
        try {
            rowIndexSupport.indexRow(rowkeyBuffer, columnFamily);
        } catch (Exception e) {
            logger.error("Error occurred while indexing row of [" + columnFamily.metadata().cfName + "]", e);
        } finally {
            event.setData(null, null);
            long readGen = indexingService.reads.incrementAndGet();
            if (logger.isDebugEnabled())
                logger.debug("Read gen:" + readGen);
        }
    }
}
Also used : RowIndexSupport(com.tuplejump.stargate.cassandra.RowIndexSupport) ByteBuffer(java.nio.ByteBuffer) ColumnFamily(org.apache.cassandra.db.ColumnFamily)

Example 2 with RowIndexSupport

use of com.tuplejump.stargate.cassandra.RowIndexSupport in project stargate-core by tuplejump.

the class Stargate method indexShards.

@Override
public String[] indexShards(String indexName) {
    RowIndexSupport indexSupport = getRowIndexSupportByIndexName(indexName);
    if (indexSupport != null && indexSupport.indexContainer instanceof PerVNodeIndexContainer) {
        PerVNodeIndexContainer indexContainer = (PerVNodeIndexContainer) indexSupport.indexContainer;
        Set<Range<Token>> indexShards = indexContainer.indexers.keySet();
        String[] indexRanges = new String[indexShards.size()];
        int i = 0;
        for (Range<Token> indexRange : indexShards) {
            indexRanges[i++] = indexRange.toString();
        }
        return indexRanges;
    }
    return new String[] { "" };
}
Also used : RowIndexSupport(com.tuplejump.stargate.cassandra.RowIndexSupport) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range)

Example 3 with RowIndexSupport

use of com.tuplejump.stargate.cassandra.RowIndexSupport in project stargate-core by tuplejump.

the class Stargate method index.

public long index(ByteBuffer rowKey, ColumnFamily columnFamily) {
    final RowIndexSupport rowIndexSupport = indexingService.support.get(columnFamily.metadata().cfName);
    try {
        rowIndexSupport.indexRow(rowKey, columnFamily);
    } catch (Exception e) {
        logger.error("Error occurred while indexing row of [" + columnFamily.metadata().cfName + "]", e);
    } finally {
        indexingService.reads.incrementAndGet();
    }
    long writeGen = indexingService.writes.incrementAndGet();
    if (logger.isDebugEnabled())
        logger.debug("Write gen:" + writeGen);
    return writeGen;
}
Also used : RowIndexSupport(com.tuplejump.stargate.cassandra.RowIndexSupport) IOException(java.io.IOException)

Example 4 with RowIndexSupport

use of com.tuplejump.stargate.cassandra.RowIndexSupport in project stargate-core by tuplejump.

the class RowIndex method init.

@Override
public void init() {
    writeLock.lock();
    final Boolean isInfoLoggingEnabled = logger.isInfoEnabled();
    try {
        assert baseCfs != null;
        assert columnDefs != null;
        assert columnDefs.size() > 0;
        columnDefinition = columnDefs.iterator().next();
        //null comparator since this is a custom index.
        keyspace = baseCfs.metadata.ksName;
        indexName = columnDefinition.getIndexName();
        tableName = baseCfs.name;
        cfMetaData = baseCfs.metadata;
        primaryColumnName = columnDefinition.name.toString().toLowerCase();
        String optionsJson = columnDefinition.getIndexOptions().get(Constants.INDEX_OPTIONS_JSON);
        this.options = CassandraUtils.getOptions(primaryColumnName, baseCfs, optionsJson);
        this.nearRealTime = options.primary.isNearRealTime();
        if (isInfoLoggingEnabled) {
            logger.info("Creating new RowIndex for {}", indexName);
        }
        //            indexContainer = new PerVNodeIndexContainer(options.analyzer, keyspace, tableName, indexName);
        indexContainer = new MonolithIndexContainer(options.analyzer, keyspace, tableName, indexName);
        this.tableMapper = new TableMapper(baseCfs, options.primary.isMetaColumn(), columnDefinition);
        rowIndexSupport = new RowIndexSupport(keyspace, indexContainer, options, tableMapper);
        Stargate.getInstance().register(rowIndexSupport);
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                if (isInfoLoggingEnabled) {
                    logger.info("Closing RowIndex for {}", indexName);
                }
                if (indexContainer != null)
                    indexContainer.close();
            }
        });
    } finally {
        writeLock.unlock();
    }
}
Also used : RowIndexSupport(com.tuplejump.stargate.cassandra.RowIndexSupport) TableMapper(com.tuplejump.stargate.cassandra.TableMapper)

Example 5 with RowIndexSupport

use of com.tuplejump.stargate.cassandra.RowIndexSupport in project stargate-core by tuplejump.

the class Stargate method allIndexes.

@Override
public String[] allIndexes() {
    String[] allIndexes = new String[indexingService.support.size()];
    int i = 0;
    for (Map.Entry<String, RowIndexSupport> entry : indexingService.support.entrySet()) {
        RowIndexSupport rowIndexSupport = entry.getValue();
        allIndexes[i++] = rowIndexSupport.indexContainer.indexName();
    }
    return allIndexes;
}
Also used : RowIndexSupport(com.tuplejump.stargate.cassandra.RowIndexSupport) Map(java.util.Map)

Aggregations

RowIndexSupport (com.tuplejump.stargate.cassandra.RowIndexSupport)5 TableMapper (com.tuplejump.stargate.cassandra.TableMapper)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1 ColumnFamily (org.apache.cassandra.db.ColumnFamily)1 Range (org.apache.cassandra.dht.Range)1 Token (org.apache.cassandra.dht.Token)1