Skip to content

Commit 944ce04

Browse files
SQUASH – fix IndexHintsTest failures
1 parent 53a91f3 commit 944ce04

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.google.common.collect.Iterables;
3131
import com.google.common.collect.Sets;
3232

33+
import org.apache.cassandra.config.DatabaseDescriptor;
3334
import org.apache.cassandra.cql3.QualifiedName;
3435
import org.apache.cassandra.db.TypeSizes;
3536
import org.apache.cassandra.exceptions.InvalidRequestException;
@@ -379,10 +380,10 @@ public static IndexHints fromCQLNames(Set<QualifiedName> included,
379380
TableMetadata table,
380381
IndexRegistry indexRegistry)
381382
{
382-
if (included != null && included.size() > Short.MAX_VALUE)
383+
if (included != null && included.size() > maxIncludedOrExcludedIndexCount())
383384
throw new InvalidRequestException(TOO_MANY_INDEXES_ERROR + included.size());
384385

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

388389
IndexHints hints = IndexHints.create(fetchIndexes(included, table, indexRegistry),
@@ -408,6 +409,14 @@ public static IndexHints fromCQLNames(Set<QualifiedName> included,
408409
return hints;
409410
}
410411

412+
private static int maxIncludedOrExcludedIndexCount()
413+
{
414+
int guardrail = DatabaseDescriptor.getGuardrailsConfig().getSecondaryIndexesPerTableFailThreshold();
415+
416+
// If no guardrail is configured, use a value that safely fits in a single byte for serialization:
417+
return guardrail > 0 ? guardrail : 128;
418+
}
419+
411420
private static Set<IndexMetadata> fetchIndexes(Set<QualifiedName> indexNames, TableMetadata table, IndexRegistry indexRegistry)
412421
{
413422
if (indexNames == null || indexNames.isEmpty())
@@ -583,9 +592,9 @@ private void serialize(Set<IndexMetadata> indexes, DataOutputPlus out, int versi
583592
return;
584593

585594
int n = indexes.size();
586-
assert n < Short.MAX_VALUE : TOO_MANY_INDEXES_ERROR + n;
595+
assert n < maxIncludedOrExcludedIndexCount() : TOO_MANY_INDEXES_ERROR + n;
587596

588-
out.writeVInt(n);
597+
out.writeVInt32(n);
589598
for (IndexMetadata index : indexes)
590599
IndexMetadata.serializer.serialize(index, out, version);
591600
}

src/java/org/apache/cassandra/net/MessagingService.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -798,13 +798,26 @@ public Set<InetAddressAndPort> endpointsWithConnectionsOnVersionBelow(String key
798798
Set<InetAddressAndPort> nodes = new HashSet<>();
799799
for (InetAddressAndPort node : StorageService.instance.getTokenMetadataForKeyspace(keyspace).getAllEndpoints())
800800
{
801-
ConnectionType.MESSAGING_TYPES.forEach(type -> {
802-
OutboundConnections connections = getOutbound(node, false);
803-
OutboundConnection connection = connections != null ? connections.connectionFor(type) : null;
804-
if (connection != null && connection.messagingVersion() < version)
805-
nodes.add(node);
806-
});
801+
if (hasConnectionWithVersionBelow(node, version))
802+
nodes.add(node);
807803
}
808804
return nodes;
809805
}
806+
807+
private boolean hasConnectionWithVersionBelow(InetAddressAndPort node, int version)
808+
{
809+
OutboundConnections connections = getOutbound(node, false);
810+
811+
if (connections == null)
812+
return false;
813+
814+
for (ConnectionType type : ConnectionType.MESSAGING_TYPES)
815+
{
816+
OutboundConnection connection = connections.connectionFor(type);
817+
if (connection != null && connection.messagingVersion() < version)
818+
return true;
819+
}
820+
821+
return false;
822+
}
810823
}

0 commit comments

Comments
 (0)