[
https://issues.apache.org/jira/browse/CASSANDRA-19367?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17814488#comment-17814488
]
David Capwell commented on CASSANDRA-19367:
-------------------------------------------
What we do in Accord at the moment is
{code}
public class RoutingKeyIndex extends StorageAttachedIndex
{
public RoutingKeyIndex(ColumnFamilyStore baseCfs, IndexMetadata
indexMetadata)
{
super(baseCfs, indexMetadata);
}
@Override
protected Strategy createStrategy(ColumnFamilyStore baseCfs,
IndexMetadata indexMetadata,
IndexTermType indexTermType,
IndexIdentifier indexIdentifier)
{
if
(!baseCfs.getKeyspaceName().equals(SchemaConstants.ACCORD_KEYSPACE_NAME))
throw new IllegalArgumentException("Attempted to use an internal
index on the wrong table: " + baseCfs.metadata());
return new AbstractStrategy(this)
{
@Override
public MemoryIndex createMemoryIndex()
{
return new RoutingKeyMemoryIndex(index);
}
@Override
public Flusher flusher()
{
return (memtable, indexDescriptor, rowMapping) -> {
RoutingKeyMemoryIndex index = memtable.getBacking();
SegmentMetadata.ComponentMetadataMap metadataMap =
index.writeDirect(indexDescriptor, indexIdentifier, rowMapping::get);
return new SegmentMetadata(0,
rowMapping.size(),
0,
rowMapping.maxSSTableRowId,
rowMapping.minKey,
rowMapping.maxKey,
index.getMinTerm(),
index.getMaxTerm(),
metadataMap);
};
}
@Override
public SegmentBuilder createSegmentBuilder(NamedMemoryLimiter
limiter)
{
return new AccordRangeSegmentBuilder(index, limiter);
}
@Override
public IndexSegmentSearcher createSearcher(PrimaryKeyMap.Factory
primaryKeyMapFactory, PerColumnIndexFiles indexFiles, SegmentMetadata
segmentMetadata) throws IOException
{
return new
RoutingKeyDiskIndexSegmentSearcher(primaryKeyMapFactory, indexFiles,
segmentMetadata, index);
}
};
}
{code}
{code}
public static final TableMetadata Commands =
parse(COMMANDS,
"accord commands",
"CREATE TABLE %s ("
+ "store_id int,"
+ "domain int," // this is stored as part of txn_id, used
currently for cheaper scans of the table
+ format("txn_id %s,", TIMESTAMP_TUPLE)
...
+ "route blob,"
...
+ "PRIMARY KEY((store_id, domain, txn_id))"
+ ')')
.partitioner(new
LocalPartitioner(CompositeType.getInstance(Int32Type.instance,
Int32Type.instance, TIMESTAMP_TYPE)))
.indexes(Indexes.builder()
.add(IndexMetadata.fromSchemaMetadata("route",
IndexMetadata.Kind.CUSTOM, ImmutableMap.of("class_name",
RoutingKeyIndex.class.getCanonicalName(), "target", "route")))
.build())
.build();
{code}
> Refactor SAI so the selection of the index type is not scattered to multiple
> places
> -----------------------------------------------------------------------------------
>
> Key: CASSANDRA-19367
> URL: https://issues.apache.org/jira/browse/CASSANDRA-19367
> Project: Cassandra
> Issue Type: Improvement
> Components: Feature/2i Index
> Reporter: David Capwell
> Assignee: David Capwell
> Priority: Normal
> Fix For: 5.x
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> For Accord we want to write an internal index and finding plugging into SAI
> is a bit more channeling than it could be… we need to find multiple places
> where the SAI code “infer” the index type so it can delegate… this logic
> should be done once and made pluggable so custom SAI indexes can be defined
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]