Cassandra (CQL) implementation reference
This page describes how the CQL native-protocol wire is built: frames and protocol versions, the login handshake, every opcode and statement, how CQL tables map onto SQL tables, roles and permissions, errors, limits and tests. For the port, proof scores, how to connect and how to re-run the differential suite, see the operator page Cassandra (CQL). Authentication policy across all wires is in Security.
Code lives in src/protocol/cassandra/:
| File | Contents |
|---|---|
mod.rs |
Listener, frame loop, opcode dispatch, STARTUP and AUTH_RESPONSE, PREPARE, EXECUTE, BATCH, system tables |
cql.rs |
Frame header, opcodes, consistency levels, data type ids, error codes, query parameters, result encoding |
exec.rs |
CQL statement parser and executor (execute_cql), DDL, DML, LWT, TTL, vector search |
schema.rs |
CQL keyspace and table catalog, CQL to SQL type mapping, tokenizer |
collections.rs |
list, set, map, frozen, tuples and user-defined types |
roles.rs |
Roles, GRANT and REVOKE, permission checks, system_auth
|
token.rs |
Murmur3Partitioner tokens |
vector.rs |
vector<float, n>, Storage-Attached Index options, similarity functions |
Listener
- Default port 9042 (
cassandra_portinsrc/config.rs). (source:src/config.rs,cassandra_port) - The server builds the handler with
CassandraHandler::with_storage, orwith_tlswhen TLS is configured. TLS is implicit: every connection on the port is wrapped at accept, so plaintext clients cannot share a TLS port. (source:src/server/mod.rs;src/protocol/cassandra/mod.rs,CassandraHandler::with_tls) Not verified: no Rust test covers CQL over TLS. -
with_storageloads the CQL catalog from storage (load_catalog), resyncs vector indexes into the vector service (resync_all_vector_tables) and registers a catalog listener so replicated schema changes reach this node's catalog. (source:src/protocol/cassandra/mod.rs,CassandraHandler::with_storage;src/protocol/cassandra/exec.rs,load_catalog,resync_all_vector_tables) - The address reported in
system.localandsystem.peerscomes fromSYNERGYDB_CASSANDRA_BROADCAST_ADDRESS, else the host's local IP, else loopback. (source:src/protocol/cassandra/mod.rs,CassandraHandler::advertised_ip)
Framing
Frame header
Every frame has a 9-byte header: version byte (high bit set on responses), flags, stream id (i16), opcode, body length (u32). (source: src/protocol/cassandra/cql.rs, FrameHeader)
| Flag | Value | Handling |
|---|---|---|
| COMPRESSION | 0x01 |
Not supported. OPTIONS advertises an empty COMPRESSION list, so drivers do not compress. (source: src/protocol/cassandra/mod.rs, handle_options) |
| TRACING | 0x02 |
Defined; no tracing is produced. (source: src/protocol/cassandra/cql.rs, FrameFlags) Not verified
|
| CUSTOM_PAYLOAD | 0x04 |
Defined; not read. (source: src/protocol/cassandra/cql.rs, FrameFlags) Not verified
|
| WARNING | 0x08 |
Defined. (source: src/protocol/cassandra/cql.rs, FrameFlags) |
| USE_BETA | 0x10 |
Defined. (source: src/protocol/cassandra/cql.rs, FrameFlags) |
- A frame whose body is larger than 256 MiB closes the connection. (source:
src/protocol/cassandra/mod.rs,MAX_CQL_FRAME_BODY) - Frames on one connection are read and answered one at a time, in order; stream ids are echoed but requests are not run concurrently. (source:
src/protocol/cassandra/mod.rs,CassandraHandler::handle_connection)
Protocol versions
Only native protocol v3 and v4 are accepted. Any other version, v5 included, gets a PROTOCOL_ERROR in a v4 frame with the text "Invalid or unsupported protocol version (N); supported versions are (3/v3, 4/v4)", which is how a Cassandra 3.x node refuses v5; drivers then retry with v4. (source: src/protocol/cassandra/mod.rs, CassandraHandler::handle_connection; docs/status/2026-11-24-cassandra-lwt-batch-v5.md) Tested by the protocol-negotiation probes in the proof-pack differential (cassandra-three-phase-diff.txt).
Not implemented: v5 segment framing, checksums, int flags and result metadata ids. (source: docs/status/2026-11-24-cassandra-lwt-batch-v5.md)
Handshake and authentication
Sequence
- OPTIONS answers SUPPORTED with
CQL_VERSION = [3.4.5]andCOMPRESSION = []. (source:src/protocol/cassandra/mod.rs,handle_options) Tested bytest_options_response. - STARTUP answers AUTHENTICATE naming
org.apache.cassandra.auth.PasswordAuthenticatorwhen authentication is required, else READY. (source:src/protocol/cassandra/mod.rs,handle_startup) Tested bytest_startup_demands_auth_when_requiredandtest_startup_response_no_auth. - AUTH_RESPONSE carries a SASL PLAIN token,
authzid\0user\0passwordoruser\0password. On success the server answers AUTH_SUCCESS with a null token. (source:src/protocol/cassandra/mod.rs,handle_auth_response) Tested byauth_success_body_is_a_null_bytes_token.
Before a session is authenticated, only OPTIONS, STARTUP and AUTH_RESPONSE are dispatched. Any other opcode gets AuthenticationError "Authentication required: send STARTUP then AUTH_RESPONSE before issuing requests". (source: src/protocol/cassandra/mod.rs, CassandraHandler::dispatch) Tested by test_dispatch_gate_rejects_unauthenticated_query.
Default and credential check
-
CassandraAuthConfig::newsetsrequire_auth = !dev_insecure_auth_enabled(), so authentication is required unless the server runs with the development opt-inSYNERGYDB_DEV_INSECURE_AUTH. (source:src/protocol/cassandra/mod.rs,CassandraAuthConfig::new;src/auth/wire_auth.rs,dev_insecure_auth_enabled) Tested bynew_requires_auth_by_defaultintests/protocol_cassandra.rs. - The username and password are checked against the shared SynergyDB role catalog with
wire_auth::verify_credential(Argon2id, timing-safe), and failures feed the shared back-off (note_auth_result). (source:src/protocol/cassandra/mod.rs,handle_auth_response;src/auth/wire_auth.rs,verify_credential,note_auth_result) - The check does not call
verify_wire_credential, so membership insynergy_wire_cassandraorsynergy_wire_allis not required on this wire. (source:src/protocol/cassandra/mod.rs,handle_auth_response;src/auth/wire_auth.rs,verify_wire_credential) Not verified: no test asserts this either way. - Error texts follow Cassandra: "Provided username X and/or password are incorrect", and "X is not permitted to log in" for a role without
LOGIN. (source:src/protocol/cassandra/mod.rs,handle_auth_response;docs/status/2026-11-30-cassandra-roles-grant.md) -
CassandraAuthConfigalso has a legacy in-memory user map (users,add_user,validate, andwith_auth, which seedscassandra/cassandra). The connection path does not read it; onlyCassandraHandler::with_authand tests use it. (source:src/protocol/cassandra/mod.rs,CassandraAuthConfig::with_auth,CassandraAuthConfig::validate) Most oftests/protocol_cassandra.rs(thevalidate_*,add_user*andwith_auth_*tests) exercises this legacy map, not the wire login.
Opcodes
The dispatch match in CassandraHandler::dispatch is the list below. (source: src/protocol/cassandra/mod.rs, CassandraHandler::dispatch; src/protocol/cassandra/cql.rs, Opcode)
| Opcode | Hex | Direction | Handling |
|---|---|---|---|
| ERROR | 0x00 |
response | Error body: code, message, plus code-specific fields |
| STARTUP | 0x01 |
request | handle_startup |
| READY | 0x02 |
response | |
| AUTHENTICATE | 0x03 |
response | Names PasswordAuthenticator
|
| OPTIONS | 0x05 |
request | handle_options |
| SUPPORTED | 0x06 |
response | |
| QUERY | 0x07 |
request |
handle_query: system tables, then execute_cql
|
| RESULT | 0x08 |
response | Kinds Void 0x0001, Rows 0x0002, SetKeyspace 0x0003, Prepared 0x0004, SchemaChange 0x0005
|
| PREPARE | 0x09 |
request | handle_prepare |
| EXECUTE | 0x0A |
request | handle_execute |
| REGISTER | 0x0B |
request | Answers READY; no events are ever pushed |
| EVENT | 0x0C |
response | Never sent |
| BATCH | 0x0D |
request | handle_batch |
| AUTH_CHALLENGE | 0x0E |
response | Never sent (PLAIN completes in one step) |
| AUTH_RESPONSE | 0x0F |
request | handle_auth_response |
| AUTH_SUCCESS | 0x10 |
response | Null token |
Any other opcode gets ProtocolError "Unsupported opcode". (source: src/protocol/cassandra/mod.rs, CassandraHandler::dispatch)
QUERY parameters
QueryParameters decodes the consistency level, values, skip_metadata, page_size, paging_state, serial consistency and default timestamp flags. (source: src/protocol/cassandra/cql.rs, QueryParameters::decode) The consistency level is accepted and has no effect, since there is one replica set. (source: src/protocol/cassandra/mod.rs, handle_query) Not verified.
Not implemented: paging. page_size and paging_state are decoded, but no code in mod.rs or exec.rs reads them; every SELECT returns all its rows in one RESULT without HAS_MORE_PAGES. (source: src/protocol/cassandra/cql.rs, QueryParameters, ResultMetadataFlags::with_has_more_pages; src/protocol/cassandra/mod.rs, handle_query)
PREPARE and EXECUTE
- The prepared id is the MD5 of
keyspace\0query. Prepared statements live in an in-memory map on the handler, so they are lost on restart; an EXECUTE for an unknown id getsUnprepared(0x2500) and drivers re-prepare. (source:src/protocol/cassandra/mod.rs,handle_prepare,handle_execute) Tested bytest_prepare. - The PREPARED result carries bind metadata with flags 0 and
pk_indexes_count = 0, andNO_METADATAresult metadata for statements other than SELECT. (source:src/protocol/cassandra/mod.rs,handle_prepare) - EXECUTE does not bind values into a plan.
substitute_paramsreplaces each?marker in the stored query text with a CQL literal built from the bound value and its type, and the text then runs throughexecute_cql. (source:src/protocol/cassandra/mod.rs,substitute_params;src/protocol/cassandra/collections.rs,bound_literal)
BATCH
- The batch type byte (LOGGED, UNLOGGED, COUNTER) is read and ignored. (source:
src/protocol/cassandra/mod.rs,handle_batch) - Only INSERT, UPDATE and DELETE are allowed; anything else gets "Invalid statement in batch". (source:
src/protocol/cassandra/mod.rs,handle_batch) - An unconditional batch runs inside one SQL
BEGINandCOMMIT. (source:src/protocol/cassandra/mod.rs,handle_batch) - A batch with
IFconditions goes throughexecute_conditional_batch: every condition is checked against the data as it was before the batch, then every statement is applied or none are. The reply is one[applied] = truerow, or[applied] = falseplus the current value of each checked row. Conditions across partitions or tables fail with "Batch with conditions cannot span multiple partitions". Conditional work is serialized by one handler-widelwt_lock. (source:src/protocol/cassandra/exec.rs,execute_conditional_batch;src/protocol/cassandra/mod.rs,lwt_lock;docs/status/2026-11-24-cassandra-lwt-batch-v5.md) Tested bycassandra_errors_and_semanticsand the LWT batch probes in the proof-pack differential. - Text batches (
BEGIN BATCH ... APPLY BATCHin a QUERY) go through the same paths. (source:src/protocol/cassandra/exec.rs,execute_cql)
Statements
execute_cql first runs cql_authorize, then dispatches on the first two keywords. (source: src/protocol/cassandra/exec.rs, execute_cql; src/protocol/cassandra/roles.rs, cql_authorize)
| Statement | Notes |
|---|---|
USE ks |
Returns SetKeyspace. Tested by test_query_use_keyspace. |
SELECT |
WHERE, IN, ORDER BY, LIMIT, PER PARTITION LIMIT, ALLOW FILTERING, DISTINCT, aggregates, token(), writetime(), ttl(), collection element selection, similarity_* functions, ORDER BY col ANN OF [...]
|
INSERT |
IF NOT EXISTS, USING TTL n, USING TIMESTAMP t
|
UPDATE |
IF conditions, IF EXISTS, collection operations (+, -, element set), counter col = col + n
|
DELETE |
Rows, columns, collection elements, IF conditions |
BEGIN BATCH ... APPLY BATCH |
See BATCH |
CREATE / ALTER / DROP KEYSPACE (or SCHEMA) |
Replication options are stored and reported; there is no replication |
CREATE / ALTER / DROP TABLE (or COLUMNFAMILY) |
ALTER TABLE supports a subset of actions, including default_time_to_live; others get "ALTER TABLE … X is not supported" |
TRUNCATE |
|
CREATE INDEX, CREATE CUSTOM INDEX, DROP INDEX
|
A plain index becomes a SQL index; an SAI index on a vector column is mirrored into the vector service |
CREATE / ALTER / DROP TYPE |
User-defined types |
CREATE / ALTER / DROP ROLE, ... USER
|
See Roles |
GRANT, REVOKE, LIST ROLES, LIST USERS, LIST ... PERMISSIONS
|
See Roles |
(source: src/protocol/cassandra/exec.rs, execute_cql; src/protocol/cassandra/vector.rs, is_sai_class; docs/status/2026-11-30-cassandra-per-partition-limit.md)
Any other CREATE, DROP, ALTER, GRANT, REVOKE or LIST form (materialized views, functions, aggregates, triggers) gets Invalid "X Y is not supported by SynergyDB's CQL interface". Anything else gets SyntaxError "no viable alternative". (source: src/protocol/cassandra/exec.rs, execute_cql)
Selected behaviours:
-
Filtering. A query that needs filtering without
ALLOW FILTERINGgets Cassandra's "Cannot execute this query as it might involve data filtering…" error; a non-EQ, non-IN relation on the partition key gets the matching Cassandra error. (source:src/protocol/cassandra/exec.rs, filtering check) -
token(). Tokens are Murmur3Partitioner values: Cassandra's MurmurHash3 x64-128 variant with sign-extended tail bytes, first 64 bits, composite keys serialized as[u16 length][bytes][0]per component. Full scans return partitions in token order. (source:src/protocol/cassandra/token.rs,murmur3_h1,token_of) -
Vector search.
vector<float, n>columns; SAI classessai,StorageAttachedIndexand the full class name; optionssimilarity_functionand the other Cassandra 5.0 SAI options. Scores are cosine(1 + cos) / 2, euclidean1 / (1 + d²)and dot product(1 + dot) / 2in 32-bit floats; the search is exact.ANN OFrequires aLIMITof at most 1000. (source:src/protocol/cassandra/vector.rs, module comment,SAI_OPTIONS;src/protocol/cassandra/exec.rs, ANN handling) Tested bytest_sai_vector_index_mirrors_into_vector_service. -
Counters.
countermaps to BIGINT and is updated withcol = col + n; TTL on a counter table andwritetime()on a counter column are refused with Cassandra's messages. (source:src/protocol/cassandra/exec.rs, update path) Not verified by a Rust test.
Not implemented: SELECT JSON and INSERT JSON (Invalid "not supported"); duration columns ("Type … is not supported … yet"); user-defined functions and aggregates; materialized views; triggers; schema-change and topology events. (source: src/protocol/cassandra/exec.rs, execute_cql; src/protocol/cassandra/schema.rs, type mapping; src/protocol/cassandra/mod.rs, handle_register)
System tables
QUERY intercepts reads of these tables before execute_cql. (source: src/protocol/cassandra/mod.rs, handle_query)
| Keyspace | Tables |
|---|---|
system |
local, peers, peers_v2
|
system_schema |
keyspaces, tables, columns, indexes, types; other tables return empty |
system_virtual_schema |
keyspaces, tables, columns, all empty |
system_auth |
roles, role_members, role_permissions; reading needs SELECT on the table or on system_auth
|
system.versions answers "unconfigured table", as Cassandra does. (source: src/protocol/cassandra/mod.rs, handle_query; src/protocol/cassandra/roles.rs, cql_authorize_system) Tested by system_versions_is_unconfigured_like_cassandra.
The reserved keyspaces are system, system_schema, system_virtual_schema, system_distributed, system_auth, system_traces and system_views. (source: src/protocol/cassandra/mod.rs, SYSTEM_KEYSPACES)
Data mapping onto storage
Keyspaces and tables
- A CQL table
ks.tis the SQL tableks__t, so keyspaces are separate namespaces. (source:src/protocol/cassandra/schema.rs, physical table naming) Tested bykeyspaces_are_separate_namespaces. - The CQL catalog is stored under
__catalog__:cqlks:and__catalog__:cqltable:keys and reloaded at start. (source:src/protocol/cassandra/schema.rs, catalog keys;src/protocol/cassandra/exec.rs,load_catalog) Tested bycatalog_survives_reopen. - Rows are written through the SQL engine, so they share the SQL engine's WAL and durability. (source:
src/protocol/cassandra/exec.rs,run_sql)
Column types
| CQL type | SQL column | Type id on the wire |
|---|---|---|
ascii |
TEXT | 0x0001 |
bigint |
BIGINT | 0x0002 |
blob |
BYTEA | 0x0003 |
boolean |
BOOLEAN | 0x0004 |
counter |
BIGINT | 0x0005 |
decimal |
NUMERIC | 0x0006 |
double |
DOUBLE PRECISION | 0x0007 |
float |
REAL | 0x0008 |
int |
INT | 0x0009 |
timestamp |
TIMESTAMPTZ | 0x000B |
uuid |
UUID | 0x000C |
text, varchar
|
TEXT | 0x000D |
varint |
TEXT | 0x000E |
timeuuid |
UUID | 0x000F |
inet |
TEXT | 0x0010 |
date |
DATE | 0x0011 |
time |
TIME | 0x0012 |
smallint, tinyint
|
SMALLINT |
0x0013, 0x0014
|
list, set, map, frozen<...>, tuple, UDT, vector<float, n>
|
TEXT holding JSON |
0x0020, 0x0022, 0x0021, 0x0031, 0x0030, custom |
duration |
Not supported |
0x0015 defined only |
(source: src/protocol/cassandra/schema.rs, type mapping; src/protocol/cassandra/cql.rs, DataType; src/protocol/cassandra/collections.rs, module) Tested by varint_round_trips, decimal_round_trips, timestamps_parse_cassandra_formats, timeuuid_is_version_1 and the collections.rs unit tests.
Collections are stored as one JSON text cell per column; element operations read, change and rewrite the whole cell (collections::apply). Ordering of set elements and map keys follows the element type's Cassandra ordering (collections::compare). User-defined types are kept in a process-wide registry filled from the catalog. (source: src/protocol/cassandra/collections.rs, apply, compare, register_udt)
TTL
-
USING TTLanddefault_time_to_liveadd expiry columns to the SQL table on first use: one row-expiry column plus one per regular column (ensure_ttl_columns). (source:src/protocol/cassandra/exec.rs,ensure_ttl_columns) - Reads add a filter that hides expired rows and cells (
live_filter). Expired data stays in the table; nothing purges it. (source:src/protocol/cassandra/exec.rs,live_filter) Tested byttl_expires_cells_and_rows.
Roles and permissions
- CQL roles are the shared SynergyDB roles (
pg_authid):CREATE ROLEover CQL creates a role that can log in on other wires, andPASSWORD,LOGINandSUPERUSERchanges apply to it. (source:src/protocol/cassandra/roles.rs, module;docs/status/2026-11-30-cassandra-roles-grant.md) - Role membership and CQL permissions are stored under
__cqlrole__:<name>and survive restarts. (source:src/protocol/cassandra/roles.rs, role record key) - Permissions are CREATE, ALTER, DROP, SELECT, MODIFY, AUTHORIZE, DESCRIBE and EXECUTE, on
ALL KEYSPACES, a keyspace, a table,ALL ROLESor a role. A keyspace grant covers its tables; roles inherit from granted roles; creators get Cassandra's automatic grants; dropping a resource removes its permissions. Refusals areUnauthorized(0x2100). (source:src/protocol/cassandra/roles.rs,cql_authorize;docs/status/2026-11-30-cassandra-roles-grant.md) - A login with no
__cqlrole__record is not checked by the CQL model; it keeps its SQL table privileges. The CQL model applies once a role is created over CQL or receives a grant over CQL. (source:src/protocol/cassandra/roles.rs,cql_authorize) Not verified by a Rust test; the status entry reports a 457-probe roles differential, which is not in the proof pack.
Not implemented: function, aggregate and MBean resources; Cassandra's 5 s password-change delay and 2 s role cache. (source: docs/status/2026-11-30-cassandra-roles-grant.md)
Errors
| Code | Name | Raised for |
|---|---|---|
0x0000 |
ServerError | Internal failures |
0x000A |
ProtocolError | Bad frame, unsupported version or opcode |
0x0100 |
AuthenticationError | Bad login, request before login |
0x1000 to 0x1500
|
Unavailable, Overloaded, IsBootstrapping, TruncateError, WriteTimeout, ReadTimeout, ReadFailure, FunctionFailure, WriteFailure | Defined in ErrorCode
|
0x2000 |
SyntaxError | Parse errors, unknown statement |
0x2100 |
Unauthorized | Permission refusals |
0x2200 |
Invalid | Semantic errors, unsupported features |
0x2300 |
ConfigError | Defined |
0x2400 |
AlreadyExists | Keyspace, table, type or index exists |
0x2500 |
Unprepared | Unknown prepared id |
(source: src/protocol/cassandra/cql.rs, ErrorCode; src/protocol/cassandra/exec.rs, CqlError::from_engine) CqlError::from_engine maps SQL-engine parse errors to SyntaxError and other engine errors to Invalid. Tested by cassandra_errors_and_semantics.
Limits and configuration
| Item | Value | Source |
|---|---|---|
| Port | 9042 |
src/config.rs, cassandra_port
|
| Maximum frame body | 256 MiB, connection closed |
mod.rs, MAX_CQL_FRAME_BODY
|
| Protocol versions | v3, v4 |
mod.rs, handle_connection
|
| CQL version reported | 3.4.5 |
mod.rs, handle_options
|
ANN OF limit |
1000 rows |
exec.rs, ANN handling |
SYNERGYDB_CASSANDRA_BROADCAST_ADDRESS |
Address in system.local and system.peers
|
mod.rs, advertised_ip
|
SYNERGYDB_DEV_INSECURE_AUTH |
Turns login off (development only) |
src/auth/wire_auth.rs, dev_insecure_auth_enabled
|
Shared read, write and idle timeouts and buffer limits apply as on the other wires; see Security.
Test coverage
-
Unit tests in
mod.rs(15): handler and session creation, OPTIONS, STARTUP with and without auth, the pre-login gate,USE, PREPARE, AUTH_SUCCESS body,system.versions, keyspace namespaces, catalog reopen, TTL expiry, error semantics and conditional statements, SAI vector mirroring. (source:src/protocol/cassandra/mod.rs, tests module) -
Other unit tests:
exec.rs(4: varint, decimal, timestamp parsing, timeuuid),schema.rs(4, includingtokenizes_cql_literals),collections.rs(3),cql.rs(5),roles.rs(2),token.rs(1),vector.rs(1). (source: each file's tests module) -
tests/protocol_cassandra.rs(36): the legacyCassandraAuthConfiguser map, handler construction, and SQL statements run directly on the query engine. None of it speaks the CQL wire. -
Proof pack:
cassandra-three-phase-diff.txtcompares the wire with Cassandra 4.1 using the Python driver: 349/349 on one connection, 73/73 on a second connection, 73/73 after restart. (source:docs/proof/2026-11-30/proof-pack-a3232c9/logs/cassandra-three-phase-diff.txt)
Not verified by any Rust test or proof log: TLS, the absence of the wire-role check, paging behaviour with large results, counters, and the opt-in CQL permission model.
Not implemented (summary)
- Protocol v5 and its segment framing; frame compression (LZ4, Snappy); tracing.
- Result paging (
page_size,paging_state). - Server-pushed events (
REGISTERis acknowledged only). -
SELECT JSON,INSERT JSON,duration. - User-defined functions and aggregates, materialized views, triggers.
- Purging of expired TTL data.
- Function, aggregate and MBean permission resources.
- Consistency levels have no effect.