[
https://issues.apache.org/jira/browse/CASSANDRA-19270?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17807665#comment-17807665
]
Nadav Har'El commented on CASSANDRA-19270:
------------------------------------------
Yes, I ran my test on the latest (or so I thought) GA version, Cassandra 4.1.3.
I didn't think of testing on Cassandra 5 before reporting it, sorry.
Here are reproducers (in Scylla's Python-based test framework, but I'm sure you
can figure out what it does):
{{@pytest.fixture(scope="module")}}
{{def table2(cql, test_keyspace):}}
{{ with new_test_table(cql, test_keyspace, "p1 text, p2 text, c1 text, c2
text, PRIMARY KEY ((p1, p2), c1, c2)") as table:}}
{{ yield table}}
{{def test_insert_65k_pk_compound(cql, table2):}}
{{ stmt = cql.prepare(f'INSERT INTO \{table2} (p1, p2, c1, c2) VALUES
(?,?,?,?)')}}
{{ big = 'x'*(65*1024)}}
{{ with pytest.raises(InvalidRequest, match='Key length'):}}
{{ cql.execute(stmt, [big, 'dog', 'cat', 'mouse'])}}
{{ with pytest.raises(InvalidRequest, match='Key length'):}}
{{ cql.execute(stmt, ['dog', big, 'cat', 'mouse'])}}
{{def test_insert_65535_compound_pk(cql, table2):}}
{{ stmt = cql.prepare(f'INSERT INTO \{table2} (p1, p2, c1, c2) VALUES
(?,?,?,?)')}}
{{ length = 65535}}
{{ p1 = "hello" # not particularly long}}
{{ c1 = unique_key_string() # not particularly long}}
{{ c2 = unique_key_string() # not particularly long}}
{{ p2 = random_string(length=(length-len(p1)-100))}}
{{ cql.execute(stmt, [p1, p2, c1, c2])}}
{{ stmt = cql.prepare(f'SELECT * FROM \{table2} WHERE p1=? AND p2=?')}}
{{ assert list(cql.execute(stmt, [p1, p2])) == [(p1, p2, c1, c2)] }}
The first test instead of a clean InvalidRequest as the test expects, get a
NoHostAvailable with the strange message "'H' format requires
# 0 <= number <= 65535"
The second test fails in an even stranger way, with
java.lang.IllegalArgumentException. The compound partition key is 100 bytes
(roughly) shorter than the maximum, and still it doesn't work.
> Incorrect error type on oversized compound partition key
> --------------------------------------------------------
>
> Key: CASSANDRA-19270
> URL: https://issues.apache.org/jira/browse/CASSANDRA-19270
> Project: Cassandra
> Issue Type: Bug
> Reporter: Nadav Har'El
> Priority: Normal
>
> Cassandra limits key lengths (partition and clustering) to 64 KB. If a user
> attempts to INSERT data with a partition key or clustering key exceeding that
> size, the result is a clear InvalidRequest error with a message like "{{{}Key
> length of 66560 is longer than maximum of 65535{}}}".
> There is one exception: If you have a *compound* partition key (i.e., two or
> more partition key components) and attempt to write one of them larger than
> 64 KB, then instead of an orderly InvalidRequest like you got when there was
> just one component, now you get a NoHostAvailable with the message:
> "{{{}error("'H' format requires 0 <= number <= 65535")}){}}}". This is not
> only uglier, it can also confuse the Cassandra driver to retry this request -
> because it doesn't realize that the request itself is broken and there is no
> point to repeat it.
> Interestingly, if there are multiple clustering key columns, this problem
> doesn't happen: we still get a nice InvalidRequest if any one of these is
> more than 64 KB.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]