CASSANDRA MCQ 5 — Questions and Answers
Question 1: Which Cassandra feature enables compare-and-swap (CAS) operations to prevent race conditions?
- Batch statements
- Lightweight transactions (LWT) using IF clauses (Correct answer)
- Counter tables
- Materialized views
Correct answer: Lightweight transactions (LWT) using IF clauses
Lightweight transactions use the Paxos consensus protocol to implement conditional updates (INSERT IF NOT EXISTS, UPDATE IF col = val), providing linearizable consistency.
Question 2: What is the function of nodetool decommission?
- Removes all data from a node without streaming it to other nodes
- Gracefully removes a node from the ring after streaming its data to other replicas (Correct answer)
- Clears the commit log and memtable on the target node
- Forces the node to rebuild its SSTables from remote replicas
Correct answer: Gracefully removes a node from the ring after streaming its data to other replicas
`nodetool decommission` safely removes a node by streaming its token ranges to neighboring nodes before leaving the ring.
Question 3: What is a tombstone in Apache Cassandra?
- A deleted SSTable that has been compacted away
- A marker written to represent a deletion, which is purged after the gc_grace_seconds period (Correct answer)
- A stale Bloom filter entry pointing to a missing key
- A committed-log entry that references a rolled-back transaction
Correct answer: A marker written to represent a deletion, which is purged after the gc_grace_seconds period
Cassandra uses tombstones to flag deleted data; they are retained for gc_grace_seconds to prevent deleted data from reappearing via hinted handoff, then removed during compaction.
Question 4: Which CQL data type is used to store a universally unique identifier generated natively by Cassandra?
- text
- uuid
- timeuuid (Correct answer)
- blob
Correct answer: timeuuid
timeuuid (version 1 UUID) embeds a timestamp, enabling time-ordered sorting and the use of now() and dateOf() functions in CQL.
Question 5: What is the recommended approach to add a new datacenter to an existing Cassandra cluster without downtime?
- Stop all nodes, update cassandra.yaml, then restart the entire cluster
- Bootstrap new nodes in the datacenter, then run nodetool rebuild on each to stream data (Correct answer)
- Use ALTER KEYSPACE to add the datacenter, then run nodetool repair on existing nodes
- Run nodetool decommission on old datacenter nodes before adding the new ones
Correct answer: Bootstrap new nodes in the datacenter, then run nodetool rebuild on each to stream data
New nodes join the ring, and `nodetool rebuild` streams the required token ranges from an existing datacenter, allowing a live, zero-downtime datacenter addition.
Question 6: Which CQL keyword allows incrementing or decrementing a numeric column atomically in Cassandra?
- ATOMIC
- UPDATE ... SET col = col + n (counter table) (Correct answer)
- MERGE
- INCREMENT
Correct answer: UPDATE ... SET col = col + n (counter table)
Counter tables support `UPDATE tbl SET col = col + 1 WHERE key = ?` for distributed atomic increments/decrements without lightweight transactions.
Question 7: What does the gc_grace_seconds property control in a Cassandra table?
- How long Cassandra waits before evicting data from the memtable
- The minimum time tombstones are retained before compaction can purge them (Correct answer)
- The interval between automatic repair cycles
- The timeout before a coordinator retries a failed write
Correct answer: The minimum time tombstones are retained before compaction can purge them
gc_grace_seconds (default 864000 = 10 days) defines how long tombstones are kept to ensure deleted data does not resurface on nodes that were down during the deletion.
Which Cassandra feature enables compare-and-swap (CAS) operations to prevent race conditions?