Skip to content

Commit 14cef0c

Browse files
authored
CNDB-16289: switch index hints limit to use Short.MAX_VALUE (#2174)
### What is the issue Currently `maxIncludedOrExcludedIndexCount` is using `getSecondaryIndexesPerTableFailThreshold` but the coordinator will always validate that the indexes mentioned by the index hints exist in the schema, and there cannot be repeated index in the hints because the hints are disjoint sets. So the number of index hints is implicitly limited by the number of existing indexes, therefore we should use Short.MAX_VALUE like main does. ### What does this PR fix and why was it fixed Change the index hint limit to use Short.MAX_VALUE
1 parent f1223ec commit 14cef0c

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/java/org/apache/cassandra/db/filter/IndexHints.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.slf4j.Logger;
3333
import org.slf4j.LoggerFactory;
3434

35-
import org.apache.cassandra.config.DatabaseDescriptor;
3635
import org.apache.cassandra.exceptions.UnknownIndexException;
3736
import org.apache.cassandra.cql3.QualifiedName;
3837
import org.apache.cassandra.db.TypeSizes;
@@ -62,8 +61,7 @@ public class IndexHints
6261
public static final String WRONG_KEYSPACE_ERROR = "Index %s is not in the same keyspace as the queried table.";
6362
public static final String MISSING_INDEX_ERROR = "Table %s doesn't have an index named %s";
6463
public static final String NON_INCLUDABLE_INDEXES_ERROR = "It's not possible to use all the specified included indexes with this query.";
65-
// The limit is determined by maxIncludedOrExcludedIndexCount() which uses the guardrail or 128 by default
66-
public static final String TOO_MANY_INDEXES_ERROR = "Exceeded the maximum number of included/excluded indexes. Found ";
64+
public static final String TOO_MANY_INDEXES_ERROR = format("Cannot have more than %d included/excluded indexes, found ", Short.MAX_VALUE);
6765

6866
public static final IndexHints NONE = new IndexHints(Collections.emptySet(), Collections.emptySet())
6967
{
@@ -386,10 +384,10 @@ public static IndexHints fromCQLNames(Set<QualifiedName> included,
386384
TableMetadata table,
387385
IndexRegistry indexRegistry)
388386
{
389-
if (included != null && included.size() > maxIncludedOrExcludedIndexCount())
387+
if (included != null && included.size() > Short.MAX_VALUE)
390388
throw new InvalidRequestException(TOO_MANY_INDEXES_ERROR + included.size());
391389

392-
if (excluded != null && excluded.size() > maxIncludedOrExcludedIndexCount())
390+
if (excluded != null && excluded.size() > Short.MAX_VALUE)
393391
throw new InvalidRequestException(TOO_MANY_INDEXES_ERROR + excluded.size());
394392

395393
IndexHints hints = IndexHints.create(fetchIndexes(included, table, indexRegistry),
@@ -415,14 +413,6 @@ public static IndexHints fromCQLNames(Set<QualifiedName> included,
415413
return hints;
416414
}
417415

418-
private static int maxIncludedOrExcludedIndexCount()
419-
{
420-
int guardrail = DatabaseDescriptor.getGuardrailsConfig().getSecondaryIndexesPerTableFailThreshold();
421-
422-
// If no guardrail is configured, use a value that safely fits in a single byte for serialization:
423-
return guardrail > 0 ? guardrail : 128;
424-
}
425-
426416
private static Set<IndexMetadata> fetchIndexes(Set<QualifiedName> indexNames, TableMetadata table, IndexRegistry indexRegistry)
427417
{
428418
if (indexNames == null || indexNames.isEmpty())
@@ -598,7 +588,7 @@ private void serialize(Set<IndexMetadata> indexes, DataOutputPlus out, int versi
598588
return;
599589

600590
int n = indexes.size();
601-
assert n <= maxIncludedOrExcludedIndexCount() : TOO_MANY_INDEXES_ERROR + n;
591+
assert n < Short.MAX_VALUE : TOO_MANY_INDEXES_ERROR + n;
602592

603593
out.writeVInt32(n);
604594
for (IndexMetadata index : indexes)

0 commit comments

Comments
 (0)