A counter is a special column for storing a number that is changed in increments.
A counter is a special column used to store an integer that is changed in increments.
- To keep track of the number of web page views received on a company website
- To keep track of the number of games played online or the number of players who have joined an online game
Tracking count in a distributed database presents an interesting challenge. In Cassandra, at any given moment, the counter value may be stored in the Memtable, commit log, and/or one or more SSTables. Replication between nodes can cause consistency issues in certain edge cases. Cassandra counters were redesigned in Cassandra 2.1 to alleviate some of the difficulties. Read "What’s New in Cassandra 2.1: Better Implementation of Counters" to discover the improvements made in the counters.
- The primary key (can be one or more columns)
- The counter column
Many counter-related settings can be set in the cassandra.yaml file.
A counter column cannot be indexed or deleted.. To load data into a counter column, or to
increase or decrease the value of the counter, use the
USING TIMESTAMP or
USING TTL when
updating a counter column.
- Use CREATE TABLE to define the counter and non-counter columns. Use all non-counter columns as part of the PRIMARY KEY definition.