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);
}
}
}
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[] { "" };
}
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;
}
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();
}
}
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;
}
Aggregations