How to Resolve Kafka’s InconsistentClusterIdException When Starting with ZooKeeper on Windows


2 views

When attempting to start Apache Kafka on Windows after launching ZooKeeper, you encounter this critical error:

ERROR Fatal error during KafkaServer startup. Prepare to shutdown
kafka.common.InconsistentClusterIdException: The Cluster ID Reu8ClK3TTywPiNLIQIm1w 
doesn't match stored clusterId Some(BaPSk1bCSsKFxQQ4717R6Q) in meta.properties.

This mismatch occurs when:

  • You previously ran Kafka with different ZooKeeper configurations
  • The cluster IDs in meta.properties became desynchronized
  • ZooKeeper data wasn't properly cleaned between sessions

Here's the definitive fix that works on Windows systems:

1. Stop all Kafka and ZooKeeper processes
2. Navigate to your Kafka logs directory (typically /tmp/kafka-logs)
3. Delete or rename the meta.properties file
4. Clean ZooKeeper data:
   del /q /s %TMP%\zookeeper\version-2\*
5. Restart ZooKeeper first
6. Then start Kafka server:
   .\bin\windows\kafka-server-start.bat .\config\server.properties

For development environments, add these cleanup commands to your startup script:

@echo off
SET KAFKA_HOME=C:\kafka_2.13-3.2.0
SET ZK_DATA=%TMP%\zookeeper

:: Clean previous sessions
rmdir /s /q "%KAFKA_HOME%\logs"
mkdir "%KAFKA_HOME%\logs"
rmdir /s /q "%ZK_DATA%"
mkdir "%ZK_DATA%"

:: Start fresh instance
start "%KAFKA_HOME%\bin\windows\zookeeper-server-start.bat" "%KAFKA_HOME%\config\zookeeper.properties"
timeout /t 5
start "%KAFKA_HOME%\bin\windows\kafka-server-start.bat" "%KAFKA_HOME%\config\server.properties"

If you need to preserve existing data, manually synchronize the cluster IDs:

  1. Get ZooKeeper's cluster ID:
    bin\windows\zookeeper-shell.bat localhost:2181 get /cluster/id
  2. Update meta.properties with matching value

When trying to start Kafka after launching ZooKeeper on Windows, you encounter this critical error:

ERROR Fatal error during KafkaServer startup. Prepare to shutdown
kafka.common.InconsistentClusterIdException: The Cluster ID Reu8ClK3TTywPiNLIQIm1w 
doesn't match stored clusterId Some(BaPSk1bCSsKFxQQ4717R6Q) in meta.properties.

Meanwhile, ZooKeeper logs show this activity:

INFO [SyncThread:0:FileTxnLog@216] - Creating new log file: log.1

The root cause stems from metadata inconsistency between what Kafka expects and what's stored in ZooKeeper. This typically occurs when:

  • You've previously run Kafka with different configurations
  • The ZooKeeper data directory wasn't properly cleaned between runs
  • There was an improper shutdown of previous Kafka instances

Step 1: Stop all running Kafka and ZooKeeper instances

.\bin\windows\kafka-server-stop.bat
.\bin\windows\zookeeper-server-stop.bat

Step 2: Clean ZooKeeper data

Navigate to your ZooKeeper dataDir (specified in zookeeper.properties) and delete all contents:

rd /s /q C:\kafka\zookeeper-data
mkdir C:\kafka\zookeeper-data

Step 3: Clean Kafka logs

Delete the Kafka log directory (specified in server.properties):

rd /s /q C:\kafka\kafka-logs
mkdir C:\kafka\kafka-logs

Step 4: Delete meta.properties

Find and remove any existing meta.properties file:

del /f /q C:\kafka\kafka-logs\meta.properties

To avoid this issue in the future:

# Add this to your server.properties to automatically delete topics
delete.topic.enable=true

# Consider adding these cleanup parameters
log.retention.hours=4
log.cleanup.policy=delete

When you restart your services:

.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
.\bin\windows\kafka-server-start.bat .\config\server.properties

Check that:

  1. ZooKeeper creates new log files without errors
  2. Kafka starts without Cluster ID complaints
  3. A new meta.properties is generated with a matching Cluster ID

For production systems where you can't simply wipe data:

# 1. Identify the correct Cluster ID from ZooKeeper:
.\bin\windows\zookeeper-shell.bat localhost:2181 get /cluster/id

# 2. Manually update meta.properties to match:
echo cluster.id=correct_id_here > C:\kafka\kafka-logs\meta.properties