Apache Cassandra Documentation

repository·trunk·Indexed 27 days ago

https://github.com/apache/cassandra

A highly scalable, distributed NoSQL database designed for large amounts of data across commodity servers. This documentation covers server management via the cassandra CLI, cluster monitoring with nodetool, and the CQL shell (cqlsh). It includes detailed guides on Storage-Attached Indexing (SAI), a high-performance local secondary indexing implementation, as well as instructions for building HTML documentation and RPM packages.

Tokens
152.1K
Snippets
225
Records
958
Agent score
93%

What's inside Apache Cassandra

  1. Overview of InMemoryTrie design

    trunk

    The InMemoryTrie is a mutable, in-memory trie implementation designed for high-performance concurrent operations. It is optimized for fast modifications and reads, allowing multiple readers to execute concurrently with writes from a single mutator thread.

    Key characteristics include:

    • Full implementation of the Trie interface.
    • Use of specialized node types to optimize memory and performance.
    • Support for storing content on any node, including intermediate prefix nodes.
    • A maximum trie size of 2GB.
  2. Overview of Virtual Tables in Cassandra 4.0

    trunk

    Virtual tables are tables backed by an API instead of SSTables. They allow users to expose metrics and YAML configuration information through CQL.

    Key Characteristics:

    • Local Only: Virtual tables are specific to each node, non-distributed, and not replicated.
    • Read-Only: Users cannot run DDL to create/modify them or DML to modify existing ones (though aggregation functions can be used in SELECT statements).
    • No SSTables: They do not have associated SSTables.
    • Partitioning: They use LocalPartitioner, meaning the partitioner sorts by partition keys rather than by hash.
    • Consistency: Consistency levels sent to virtual tables are ignored.
    • Querying: Advanced queries using ALLOW FILTERING and aggregation functions can be executed, though it is not recommended for normal tables.
  3. Overview of Storage-Attached Indexing (SAI)

    trunk

    Storage-attached indexing (SAI) is a column-based local secondary index implementation for Apache Cassandra. It improves upon previous implementations like SASI by using a byte-ordered trie for string data and a block-oriented balanced tree for numeric data.

    Key features include:

    • Reduced Footprint: Uses a row-based storage design at the column index level to minimize on-disk usage when multiple columns in a table are indexed.
    • Operational Support: Supports tracing, metrics, virtual table-based metadata, and snapshot-based backup/restore.
    • Streaming & Backups: On-disk index components can be streamed during SSTable streaming and are included in snapshots.
    • Consistency: Supports the full set of Cassandra consistency levels for both reads and writes.
    • Synchronous Updates: Index updates are synchronous with mutations and do not require read-before-write.
    • Management: Single-node management operations (e.g., stop and rebuild_index) are available via nodetool.
  4. Overview of Storage-Attached Indexing (SASI)

    trunk

    SASI (SASIIndex) is an implementation of Cassandra's Index interface designed to provide superior performance for queries that would otherwise require filtering. It is optimized to be less resource-intensive in terms of memory, disk, and CPU usage compared to existing indexing implementations.

    Key capabilities include:

    • Improved performance for complex queries.
    • Support for prefix queries on strings (e.g., LIKE 'foo*').
    • Support for contains queries on strings (e.g., LIKE '%foo%').
  5. Overview of Secondary Indexes (2i) in Cassandra

    trunk

    Secondary indexes (2i) allow you to create one or multiple indexes on the same database table, where each index is based on a different column. This enables querying data based on non-primary key columns.

    Important Restriction: You do not need to define a secondary index on a column that is already a single-column partition key, as the partition key is already indexed for lookups.

  6. Use Cassandra 4.0 improved read repair features

    trunk

    Cassandra 4.0 introduced several improvements to read repair performance and observability:

    Speculative Retry

    Cassandra 4.0 uses speculative retry for full data read requests. If a response is not received quickly from the initial set of replicas, it speculatively sends additional read requests to un-contacted replicas to satisfy the consistency level.

    Improved Blocking Behavior

    The coordinator only blocks for the amount of full data responses required to resolve digest mismatches and meet the requested consistency level. It does not wait for all speculative or repair attempts if the required number of agreeing nodes is reached.

    Diagnostic Events

    Cassandra 4.0 provides diagnostic events to monitor read repair activity, including:

    • Contacted endpoints
    • Digest responses by endpoint
    • Affected partition keys
    • Speculated reads / writes
    • Update oversized
  7. Understand BTI Row Index Implementation

    trunk

    The BTI row index maps clustering keys or prefixes to data positions at the start of an index block.

    Key Mechanisms:

    • Separators: Instead of storing full keys for every block, the index stores a "separator" (a key greater than the previous block's last key but $\le$ the current block's first key). This reduces index size.
    • Lookup Process: Finding a candidate block involves walking the byte-ordered representation of the clustering key in the trie to find the closest less-than-or-equal value. This is followed by a linear walk within the data file to find the exact matching data.
    • Reverse Lookups: To support backward iteration, the index provides an iterator of index blocks in reverse order. For each block, the machinery walks forward, creates a stack of row positions, and pops them to issue rows.