TechBuzzPro

Cassandra Error: Service Entered Failed State

· 6 min read · Apps & Browsers

In this article
  1. What Does "Entered Failed State" Mean?
  2. Common Causes of the Failure
  3. How to Diagnose the Exact Cause
  4. Step-by-Step Fixes for the Most Common Issues
  5. Preventing Future Failures
  6. Frequently Asked Questions

The error "cassandra.service: Main process exited, code=exited, status=1/FAILURE" or "Unit cassandra.service entered failed state" means the Cassandra systemd service has crashed or failed to start. This is a common issue on Linux servers running Apache Cassandra, and it usually points to a configuration error, a permission problem, or a corrupted data directory.

What Does "Entered Failed State" Mean?

When you run a command like systemctl start cassandra or systemctl status cassandra, systemd reports the service's state. A "failed" state means the main process (the Cassandra Java process) exited with a non-zero exit code, or it timed out during startup. This is different from a "stopped" state, where the service was intentionally stopped. The failed state is a clear signal that something went wrong during startup or runtime, and systemd will not automatically restart it unless you have configured that.

Common Causes of the Failure

Several issues can cause Cassandra to fail to start. Here are the most frequent ones, based on real-world deployments:

  • Configuration errors in cassandra.yaml - A typo, a wrong IP address, or an invalid value for a setting like cluster_name or listen_address can cause the process to abort.
  • Insufficient permissions - Cassandra runs as a specific user (often cassandra). If the data directories, log files, or configuration files are owned by root or have wrong permissions, the process cannot write to them and fails.
  • Corrupted data or commit log - If the node was killed abruptly (e.g., power loss), the data files or commit log may be corrupted, causing Cassandra to refuse to start.
  • Out of memory (OOM) - Cassandra is a Java application and needs enough heap and off-heap memory. If the system doesn't have enough RAM or the heap size is set too high, the JVM may fail to start.
  • Port conflicts - Cassandra uses ports 7000 (inter-node), 9042 (CQL), and 9160 (Thrift). If another process is using these ports, Cassandra cannot bind to them and exits.
  • Java version mismatch - Cassandra requires a specific Java version (usually Java 8 or 11). If the wrong version is installed, the startup script may fail.

How to Diagnose the Exact Cause

To find out why the service failed, you need to check the logs. The systemd journal and Cassandra's own log files are your primary sources of information.

  1. First, check the systemd journal for the service: journalctl -u cassandra -n 100 (shows the last 100 lines). This will show the exact error message that caused the failure.
  2. Look at Cassandra's system log: usually /var/log/cassandra/system.log. This file contains detailed stack traces and error messages.
  3. Check the startup script output: cassandra -f (run in the foreground) to see the error directly in the terminal.

Common error messages you might see include Unable to create directory, Invalid yaml, Address already in use, or OutOfMemoryError. Each points to a specific fix.

Step-by-Step Fixes for the Most Common Issues

Here are the typical resolutions for each cause. Always back up your configuration and data before making changes.

  • Fix configuration errors: Open /etc/cassandra/cassandra.yaml and verify that cluster_name matches across all nodes, listen_address and rpc_address are set to valid IPs (use localhost for testing), and seeds is correct. Use a YAML parser to validate the file.
  • Fix permissions: Run chown -R cassandra:cassandra /var/lib/cassandra /var/log/cassandra /etc/cassandra to give the Cassandra user ownership. Ensure the user has write access to these directories.
  • Fix corrupted data: If the data directory is corrupted, you may need to delete the contents of /var/lib/cassandra/commitlog and /var/lib/cassandra/data (only if you have backups or can rebuild the node). This is a last resort because it loses data.
  • Fix memory issues: Edit /etc/cassandra/cassandra-env.sh and reduce MAX_HEAP_SIZE and HEAP_NEWSIZE to fit within your system's RAM. For example, set them to 2G and 400M respectively for a small server.
  • Fix port conflicts: Use netstat -tulpn | grep -E '7000|9042|9160' to see if any other process is using those ports. If so, stop that process or change Cassandra's ports in the YAML file.
  • Fix Java version: Verify with java -version. Cassandra 3.x and 4.x require Java 8 or 11. Install the correct JDK if needed.

Preventing Future Failures

Once you have the service running again, take these steps to avoid a repeat:

  • Set up monitoring for disk space, memory, and service status (e.g., with systemd's Restart=on-failure in the unit file).
  • Regularly test your backup and restore process.
  • Keep Cassandra and Java updated to the latest stable versions.
  • Use a configuration management tool (like Ansible or Puppet) to ensure consistent settings across nodes.
  • Enable auto_snapshot in cassandra.yaml (it is true by default) to protect against accidental data loss.

Frequently Asked Questions

What does "Job for cassandra.service failed because the control process exited with error code" mean?

This is the systemd message that accompanies the "failed state" error. It means the main process of the service exited with a non-zero exit code, which indicates an error. The exact error is usually printed in the journal or the Cassandra log. You can see it with journalctl -u cassandra -n 50.

Will I lose my data if I fix the service?

In most cases, no. Configuration errors, permission issues, and port conflicts do not affect your data. However, if the data directory is corrupted, you might need to delete it, which will cause data loss unless you have backups. Always back up your data before attempting major repairs.

How do I restart Cassandra after fixing the issue?

After making changes, run systemctl daemon-reload to reload systemd, then systemctl start cassandra. Check the status with systemctl status cassandra to ensure it is active and running. You can also use nodetool status to verify that the node joins the cluster.

Can I run Cassandra in the foreground to see the error?

Yes, you can run cassandra -f as the cassandra user. This will start Cassandra in the foreground and print all log output to the terminal, which makes it easier to see the exact error. Press Ctrl+C to stop it when done.

Is it safe to delete the commit log to fix the error?

Deleting the commit log is safe in the sense that it does not contain actual data; it only contains recent writes that haven't been flushed to SSTables. However, deleting it may cause the loss of recent writes (those that were not yet flushed). It is a common fix for corruption issues, but you should do it as a last resort and only if you can accept the potential loss of a few seconds of writes.

What if the error persists after trying all these fixes?

If the issue remains, it could be a deeper problem like a hardware issue, a bug in Cassandra, or a conflict with system libraries. Check the full stack trace in the log file and search for the specific error message online. You can also ask for help on the Cassandra user mailing list or Stack Overflow, providing your Cassandra version, Java version, and the full error log.