Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/java/org/apache/cassandra/db/filter/IndexHints.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public static final IndexHints NONE = new IndexHints(Collections.emptySet(), Collections.emptySet())
{
Expand Down Expand Up @@ -386,10 +384,10 @@ public static IndexHints fromCQLNames(Set<QualifiedName> included,
TableMetadata table,
IndexRegistry indexRegistry)
{
if (included != null && included.size() > maxIncludedOrExcludedIndexCount())
if (included != null && included.size() > Short.MAX_VALUE)
throw new InvalidRequestException(TOO_MANY_INDEXES_ERROR + included.size());

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

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

private static int maxIncludedOrExcludedIndexCount()
{
int guardrail = DatabaseDescriptor.getGuardrailsConfig().getSecondaryIndexesPerTableFailThreshold();

// If no guardrail is configured, use a value that safely fits in a single byte for serialization:
return guardrail > 0 ? guardrail : 128;
}

private static Set<IndexMetadata> fetchIndexes(Set<QualifiedName> indexNames, TableMetadata table, IndexRegistry indexRegistry)
{
if (indexNames == null || indexNames.isEmpty())
Expand Down Expand Up @@ -598,7 +588,7 @@ private void serialize(Set<IndexMetadata> indexes, DataOutputPlus out, int versi
return;

int n = indexes.size();
assert n <= maxIncludedOrExcludedIndexCount() : TOO_MANY_INDEXES_ERROR + n;
assert n < Short.MAX_VALUE : TOO_MANY_INDEXES_ERROR + n;

out.writeVInt32(n);
for (IndexMetadata index : indexes)
Expand Down