nodetool setdefaultrf
Cassandra 4.1+
This command is available in Cassandra 4.1 and later.
Sets the default replication factor used by NetworkTopologyStrategy auto-expansion.
Synopsis
Section titled “Synopsis”nodetool [connection_options] setdefaultrf <replication_factor>See connection options for connection options.
Description
Section titled “Description”nodetool setdefaultrf configures the cluster-wide default replication factor that is applied when creating or altering keyspaces using NetworkTopologyStrategy with the replication_factor shorthand instead of explicit datacenter mappings.
How Auto-Expansion Works
Section titled “How Auto-Expansion Works”When a keyspace is created using NetworkTopologyStrategy with the generic replication_factor parameter, Cassandra automatically expands this to all known datacenters:
-- Using replication_factor shorthandCREATE KEYSPACE my_keyspace WITH replication = { 'class': 'NetworkTopologyStrategy', 'replication_factor': 3};
-- Cassandra expands this to explicit datacenter mappings:-- 'dc1': 3, 'dc2': 3, 'dc3': 3 (for all datacenters in the cluster)The value set by setdefaultrf becomes the default when replication_factor is not explicitly specified in the CQL statement.
Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
replication_factor | The default replication factor to apply. Must be a positive integer. |
When to Use
Section titled “When to Use”Standardizing Replication Across Teams
Section titled “Standardizing Replication Across Teams”In multi-tenant or multi-team environments, setting a cluster-wide default ensures new keyspaces follow organizational standards without requiring explicit specification:
# Set production standard of RF=3nodetool setdefaultrf 3This prevents accidental creation of under-replicated keyspaces when developers omit explicit replication settings.
Preparing for Cluster Expansion
Section titled “Preparing for Cluster Expansion”Before adding new datacenters, set the default RF to ensure auto-expansion applies the correct replication factor:
# Before adding dc3 to the clusternodetool setdefaultrf 3
# When dc3 joins, keyspaces using auto-expansion will include dc3 with RF=3Automation and Infrastructure-as-Code
Section titled “Automation and Infrastructure-as-Code”When using automation tools that create keyspaces, setdefaultrf provides a safety net:
# Ensure minimum replication regardless of script defaultsnodetool setdefaultrf 3Behavior Details
Section titled “Behavior Details”Node-Level Setting
Section titled “Node-Level Setting”This setting is per-node and is not persisted across restarts. Each node in the cluster maintains its own default RF value. For consistent behavior:
- Run the command on all nodes
- Or configure
default_keyspace_rfincassandra.yamlfor persistence
Does Not Affect Existing Keyspaces
Section titled “Does Not Affect Existing Keyspaces”Changing the default RF does not alter existing keyspaces. It only affects:
- New keyspaces created with
replication_factorshorthand ALTER KEYSPACEcommands usingreplication_factorshorthand
Interaction with Explicit Settings
Section titled “Interaction with Explicit Settings”Explicit datacenter settings always override the default:
-- DC1 gets RF=5, DC2 uses the default from setdefaultrf (e.g., 3)CREATE KEYSPACE mixed_rf WITH replication = { 'class': 'NetworkTopologyStrategy', 'replication_factor': 3, 'dc1': 5};Examples
Section titled “Examples”Set Default RF to Production Standard
Section titled “Set Default RF to Production Standard”nodetool setdefaultrf 3Verify the Setting
Section titled “Verify the Setting”nodetool getdefaultrfOutput:
3Applying Across All Nodes
Section titled “Applying Across All Nodes”# Run on each node or use parallel executionfor host in node1 node2 node3; do ssh "$host" "nodetool setdefaultrf 3"doneBest Practices
Section titled “Best Practices”Recommendations
- Set on all nodes - The setting is per-node; ensure consistency across the cluster
- Use with cassandra.yaml - For persistence, also configure
default_keyspace_rfin cassandra.yaml - Match node count - The default RF should not exceed the number of nodes in the smallest datacenter
- Production standard: RF=3 - Provides fault tolerance for one node failure while maintaining QUORUM availability
Limitations
- Does not affect keyspaces created with explicit datacenter mappings
- Does not retroactively change existing keyspaces
- Resets to default (1) on node restart unless configured in cassandra.yaml
Related Configuration
Section titled “Related Configuration”The persistent equivalent in cassandra.yaml:
# Default replication factor for auto-expanding keyspacesdefault_keyspace_rf: 3Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| getdefaultrf | View current default RF |
| describecluster | View cluster topology and datacenter information |
| status | Check node count per datacenter |
Related Documentation
Section titled “Related Documentation”- Keyspace DDL - Creating and altering keyspaces
- Replication - Replication concepts and strategies