Details
-
Improvement
-
Status: Resolved
-
Low
-
Resolution: Fixed
-
None
Description
Index validation is currently done in a per-cell basis. However, per-row secondary index developers can be interested in validating all the written columns at once, because some implementations need to check the validity of a row write by comparing some column values against others. For example, a per row 2i implementation indexing time ranges (composed by a start date column and an end date column) should check that the start date is before the stop date.
I'm attaching a patch adding a new method to PerRowSecondaryIndex:
public void validate(ByteBuffer key, ColumnFamily cf) throws InvalidRequestException {}
and a new method to SecondaryIndexManager:
public void validateRowLevelIndexes(ByteBuffer key, ColumnFamily cf) throws InvalidRequestException { for (SecondaryIndex index : rowLevelIndexMap.values()) { ((PerRowSecondaryIndex) index).validate(key, cf); } }
This method is invoked in CQL UpdateStatement#validateIndexedColumns. This way, PerRowSecondaryIndex could perform complex write validation.
I have tried to do the patch in the least invasive way possible. Maybe the current method SecondaryIndex#validate(ByteBuffer, Cell) should be moved to PerColumnSecondaryIndex, and the InvalidRequestException that informs about the particular 64k limitation should be thrown by AbstractSimplePerColumnSecondaryIndex. However, given the incoming CASSANDRA-9459, I think that the proposed patch is more than enough to provide rich validation features to 2i implementations based on 2.1.x and 2.2.x.