Cassandra Schema Disagreement
Schema disagreement occurs when nodes in a cluster have different versions of the schema. This can cause query failures, inconsistent behavior, and operational issues.
Symptoms
Section titled “Symptoms”nodetool describeclustershows multiple schema versions- DDL operations fail or hang
- Queries return inconsistent results
- Errors mentioning "schema disagreement" in logs
- New nodes fail to join cluster
Diagnosis
Section titled “Diagnosis”Step 1: Check Schema Versions
Section titled “Step 1: Check Schema Versions”nodetool describeclusterExpected output (healthy):
Schema versions: <schema-uuid>: [node1, node2, node3]Problem output:
Schema versions: <schema-uuid-1>: [node1, node2] <schema-uuid-2>: [node3] UNREACHABLE: [node4]Step 2: Identify Affected Nodes
Section titled “Step 2: Identify Affected Nodes”# Check gossip info for schema version per nodenodetool gossipinfo | grep -E "SCHEMA|STATUS"Step 3: Check for Pending Schema Changes
Section titled “Step 3: Check for Pending Schema Changes”# Look for schema-related messagesgrep -i "schema" /var/log/cassandra/system.log | tail -50Step 4: Check Node Connectivity
Section titled “Step 4: Check Node Connectivity”# Verify all nodes can communicatefor node in node1 node2 node3; do nc -zv $node 7000 && echo "$node: OK" || echo "$node: FAILED"doneResolution
Section titled “Resolution”Option 1: Wait for Convergence (Minor Disagreement)
Section titled “Option 1: Wait for Convergence (Minor Disagreement)”Schema changes propagate via gossip. For recent changes, wait 30-60 seconds:
# Monitor schema convergencewatch -n 5 'nodetool describecluster | grep -A 20 "Schema versions"'Option 2: Force Schema Refresh
Section titled “Option 2: Force Schema Refresh”On each node with outdated schema:
# Reload schema from peersnodetool reloadlocalschemaOption 3: Reset Local Schema (Single Node)
Section titled “Option 3: Reset Local Schema (Single Node)”If one node has corrupted schema:
# Warning: This drops local schema and reloads from peersnodetool resetlocalschemaUse with Caution
resetlocalschema should only be used on a single node that has diverged from the cluster. Never run on multiple nodes simultaneously.
Option 4: Rolling Restart
Section titled “Option 4: Rolling Restart”If schema disagreement persists:
# On each node, one at a time:nodetool drainsudo systemctl restart cassandra
# Wait for node to rejoin before proceeding to nextnodetool statusOption 5: Force Schema Rebuild (Last Resort)
Section titled “Option 5: Force Schema Rebuild (Last Resort)”If all else fails, use nodetool resetlocalschema on the problematic node:
# This drops local schema and reloads from cluster peersnodetool resetlocalschemaExtreme Last Resort: Clear Schema Files
Only if the node cannot start and all other options fail:
# 1. Stop Cassandrasudo systemctl stop cassandra
# 2. Remove local schema SSTables (forces reload from peers on restart)sudo rm -rf /var/lib/cassandra/data/system_schema/*
# 3. Restart and let it rebuild from peerssudo systemctl start cassandraThis should only be used when the node cannot start due to schema corruption.
Recovery
Section titled “Recovery”Verify Resolution
Section titled “Verify Resolution”# All nodes should show same schema versionnodetool describecluster
# Test DDL operationscqlsh -e "CREATE KEYSPACE IF NOT EXISTS test_schema WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"cqlsh -e "DROP KEYSPACE test_schema;"Prevention
Section titled “Prevention”- Avoid concurrent DDL - Only run schema changes from one client
- Wait between DDL operations - Allow 10+ seconds between changes
- Monitor schema versions - Alert on disagreement
- Keep cluster healthy - Address node issues promptly
Common Causes
Section titled “Common Causes”| Cause | Prevention |
|---|---|
| Concurrent DDL from multiple clients | Use single schema management tool |
| Network partition during DDL | Ensure network stability |
| Node crash during schema change | Monitor node health |
| Gossip issues | Check firewall rules for port 7000 |
| Clock skew | Synchronize clocks with NTP (Clock Skew Failure Modes) |
Related Commands
Section titled “Related Commands”| Command | Purpose |
|---|---|
nodetool describecluster | View schema versions |
nodetool gossipinfo | Check gossip state |
nodetool reloadlocalschema | Refresh schema from peers |
nodetool resetlocalschema | Reset and reload schema |
Related Documentation
Section titled “Related Documentation”- Gossip Failures - Gossip troubleshooting
- Cluster Management - Cluster operations