Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

nodetool invalidatecountercache

Invalidates the counter cache on the node.


Terminal window
nodetool [connection_options] invalidatecountercache

See connection options for connection options.

nodetool invalidatecountercache clears all entries from the counter cache on the node. The counter cache stores counter cell values, allowing faster access to frequently read counters by avoiding disk reads for their current values.

After invalidation, the cache is empty and will be repopulated as subsequent counter read operations occur.

Counter-Specific Cache

This cache only affects counter columns. If the workload does not use counters, this cache will be empty and invalidation has no effect.


Terminal window
nodetool invalidatecountercache
Terminal window
nodetool invalidatecountercache
watch -n 5 'nodetool info | grep "Counter Cache"'

Cached DataDescription
Counter cell locationReference to counter column
Current counter valueMost recent counter value
Merge informationData for counter merges
Without Counter Cache:
Counter Read → Read all counter shards from disk → Merge → Return value
With Counter Cache Hit:
Counter Read → Return cached merged value
(Avoids disk reads and merge computation)

Counters in Cassandra are distributed and require merging values from multiple sources:

  1. Local shard value
  2. Remote shard values
  3. Historical values for consistency

The counter cache stores the merged result, avoiding repeated computation.


Clear potentially inconsistent cached values:

Terminal window
# After running repair on counter tables
nodetool invalidatecountercache

If counter values appear incorrect:

Terminal window
# Clear counter cache
nodetool invalidatecountercache
# Re-read counters to get fresh values

Following restore from backup:

Terminal window
# After restoring counter data
nodetool invalidatecountercache

Release memory if counter cache is large:

Terminal window
# Check current size
nodetool info | grep "Counter Cache"
# Clear if necessary
nodetool invalidatecountercache

AspectImpact
Counter cache entriesAll cleared
Memory usageTemporarily reduced
Counter read latencyTemporarily increases
Disk I/O for countersIncreases
PhaseDurationCache State
Immediately after0Empty
Warming upMinutesPartially filled
Fully warmHoursOptimally filled

Impact Scope

Impact is limited to counter column workloads. Non-counter reads are unaffected.


Terminal window
# Check cache status before
echo "Before invalidation:"
nodetool info | grep -A 5 "Counter Cache"
# Invalidate
nodetool invalidatecountercache
# Check immediately after
echo "After invalidation:"
nodetool info | grep -A 5 "Counter Cache"
monitor_countercache_refill.sh
#!/bin/bash
echo "=== Counter Cache Refill Monitor ==="
echo "Press Ctrl+C to stop"
echo ""
while true; do
info=$(nodetool info 2>/dev/null | grep -A 2 "Counter Cache")
entries=$(echo "$info" | grep "entries" | awk '{print $4}')
hit_rate=$(echo "$info" | grep "hit rate" | awk '{print $4}')
size=$(echo "$info" | grep "size" | awk '{print $4}')
echo "$(date '+%H:%M:%S') - Entries: $entries, Hit Rate: $hit_rate, Size: $size"
sleep 10
done

counter_cache_management.sh
#!/bin/bash
echo "=== Counter Cache Management ==="
# 1. Check current state
echo "1. Current counter cache status:"
nodetool info | grep -A 3 "Counter Cache"
# 2. Check if counters are in use
entries=$(nodetool info 2>/dev/null | grep -A 1 "Counter Cache" | grep "entries" | awk '{print $4}')
if [ "$entries" = "0" ]; then
echo ""
echo "Counter cache is empty - no counters in use or caching disabled."
echo "Invalidation would have no effect."
exit 0
fi
# 3. Proceed with invalidation
echo ""
echo "2. Invalidating counter cache..."
nodetool invalidatecountercache
# 4. Verify
echo ""
echo "3. Cache status after invalidation:"
nodetool info | grep -A 3 "Counter Cache"
# 5. Monitor refill
echo ""
echo "4. Monitoring refill (30 seconds)..."
for i in {1..6}; do
sleep 5
entries=$(nodetool info 2>/dev/null | grep -A 1 "Counter Cache" | grep "entries" | awk '{print $4}')
echo " Entries: $entries"
done
echo ""
echo "=== Complete ==="

invalidate_countercache_cluster.sh
#!/bin/bash
echo "Invalidating counter cache cluster-wide..."# Get list of node IPs from local nodetool status
nodes=$(nodetool status | grep "^UN" | awk '{print $2}')
for node in $nodes; do
echo -n "$node: "
ssh "$node" "nodetool invalidatecountercache 2>/dev/null && echo "invalidated" || echo "FAILED""
done
echo ""
echo "Monitor recovery with: nodetool info | grep 'Counter Cache'"
#!/bin/bash
# rolling_countercache_invalidate.sh# Get list of node IPs from local nodetool status
nodes=$(nodetool status | grep "^UN" | awk '{print $2}')
WAIT_TIME=120 # 2 minutes between nodes
for node in $nodes; do
echo "$(date): Invalidating counter cache on $node..."
ssh "$node" "nodetool invalidatecountercache"
echo "Waiting ${WAIT_TIME}s for cache warmup..."
sleep $WAIT_TIME
hit_rate=$(ssh "$node" "nodetool info 2>/dev/null | grep -A 2 "Counter Cache" | grep "hit rate" | awk '{print $4}')"
echo " Hit rate: $hit_rate"
done
echo "Rolling invalidation complete."

cassandra.yaml
counter_cache_size_in_mb: # Default: min(2.5% of heap, 50MB)
counter_cache_save_period: 7200 # Save interval in seconds
counter_cache_keys_to_save: # Keys to save on shutdown
Terminal window
# View current counter cache configuration
nodetool info | grep "Counter Cache"
# Check cassandra.yaml
grep counter_cache /etc/cassandra/cassandra.yaml

Terminal window
# Check if any tables use counters
cqlsh -e "SELECT keyspace_name, table_name FROM system_schema.columns WHERE type = 'counter' ALLOW FILTERING;"
# If no counter tables, cache will be empty
Terminal window
# Check cache size vs counter working set
nodetool info | grep "Counter Cache"
# Consider increasing cache size if entries are at capacity
# but hit rate is low

Counter Values Incorrect After Invalidation

Section titled “Counter Values Incorrect After Invalidation”
Terminal window
# Run repair on counter tables
nodetool repair -pr my_keyspace counter_table
# Then allow cache to rebuild with correct values

Counter Cache Guidelines

  1. Understand counter workload - Only useful if using counter columns
  2. Invalidate after repair - Ensure cached values are consistent
  3. Monitor hit rates - Low hit rate may indicate sizing issue
  4. Consider alternatives - For simple counting, regular columns may be better
  5. Test impact - Measure latency impact before production invalidation

Counter Limitations

Remember that Cassandra counters have specific limitations:

  • Cannot be part of primary key
  • Can only increment/decrement (no set)
  • Subject to consistency challenges
  • Counter cache helps mitigate read overhead

CommandRelationship
invalidatekeycacheInvalidate key cache
invalidaterowcacheInvalidate row cache
infoView cache statistics
setcachecapacityAdjust cache sizes
repairRepair data including counters