What is kafka-metadata-shell.sh used for, and when would you reach for it instead of kafka-metadata-quorum.sh?
answer
- virtual filesystem over __cluster_metadata
- ls / cd / cat over brokers, topics, configs, acls
- load a snapshot/checkpoint, even offline
- content/inspection vs quorum=health
- read-only post-mortem tool
basics
~10 skafka-metadata-shell.sh opens an interactive, filesystem-like shell over the contents of the KRaft __cluster_metadata log (or a snapshot). You browse the actual metadata records (topics, brokers, configs); kafka-metadata-quorum.sh instead reports quorum/replication health.
solid answer
~40 skafka-metadata-shell.sh is a debugging tool that loads the `__cluster_metadata` log (a `.log` segment or a snapshot file under the metadata log dir) and presents the resulting metadata image as a virtual filesystem you navigate with `ls`, `cd`, and `cat`. You can inspect what the cluster actually believes — registered brokers, topic/partition assignments, replicas, configs, ACLs, feature levels, producer IDs — straight from the persisted records. You reach for it when you need to see the *content* of metadata (e.g. 'is this broker still registered?', 'what does the controller think this partition's ISR is?', or to debug a corrupt/diverged metadata state). By contrast, kafka-metadata-quorum.sh answers *health/coordination* questions (who is leader, voter/observer lag). The shell can run offline against on-disk files even when the cluster is down, which makes it valuable for post-mortems.
code
bash · 10 lines# Browse a metadata snapshot offline (cluster can be down)
kafka-metadata-shell.sh --snapshot \
/var/lib/kafka/metadata/__cluster_metadata-0/00000000000000012345.checkpoint
# Inside the shell:
# ls /
# cd /brokers
# cat /brokers/1/registration
# cd /topics/orders/0
# cat datago deeper
Know it exists and that it lets you browse KRaft metadata like files.
Use it to inspect metadata content (brokers, topics, configs) and know it differs from the quorum tool.
Leverage it offline against snapshots for post-mortems and to confirm controller ground truth vs broker views.
Position it within a diagnostics toolkit and guidance (read-only, snapshot-based) and know its limits vs AdminClient/kafka-dump-log.
## What it is `kafka-metadata-shell.sh` (backed by `MetadataShell`) is an interactive diagnostic tool that **materializes the KRaft metadata** and exposes it as a **virtual filesystem**. You point it at the `__cluster_metadata` log directory (the `.log` segment files and/or a `.checkpoint`/snapshot), it replays the records to build the in-memory **metadata image**, and then drops you into a shell. ``` kafka-metadata-shell.sh --snapshot /path/to/metadata-0/00000000000000000123.checkpoint >> ls / brokers topics configs acls ... >> cd /topics >> ls orders payments __consumer_offsets >> cat /topics/orders/0/data ``` Navigation uses familiar commands: `ls`, `cd`, `cat`, `pwd`, `find`. Each path corresponds to a part of the metadata image — brokers and their registrations, topics and their partitions, replica assignments and ISR, configs, ACLs, SCRAM credentials, feature/version levels, and producer IDs. ## When to use it vs kafka-metadata-quorum.sh | Question | Tool | |---|---| | Who is the controller leader? What's voter lag? Is the quorum healthy? | `kafka-metadata-quorum.sh describe` | | What does the cluster actually *contain*? Is broker 3 still registered? What's the ISR/replica list for partition X according to the controller? What feature levels are active? | `kafka-metadata-shell.sh` | In short: **quorum tool = coordination/health**, **metadata shell = content/inspection**. ## Why it's powerful for debugging - **Offline / post-mortem**: it reads on-disk log/snapshot files, so you can inspect a cluster's last-known metadata even if the cluster won't start. This is invaluable when a checksum mismatch or corrupt record blocks startup. - **Ground truth**: it shows the persisted records, not a live API view, so you can confirm what the controller has actually committed versus what a broker reports. - **Snapshot inspection**: you can load a specific snapshot to see metadata as of that point. ## Edge cases and cautions - It is a **read-only diagnostic** — it does not (and should not) mutate metadata. - Pointing it at a live, actively-written log directory can be racy; prefer a snapshot or a copy of the segment for stability. - It's a lower-level tool than the admin client; for routine operations (describe topics, alter configs) use `kafka-topics.sh`/`kafka-configs.sh`/AdminClient. Reach for the shell when those higher-level views are insufficient or the cluster is unhealthy. - The available paths/structure can vary across Kafka versions as the metadata schema evolves.
- The cluster won't start due to a metadata problem. How can the metadata shell help?It reads the on-disk metadata log/snapshot files offline, so you can browse the last-committed metadata image even though the cluster is down — confirming broker registrations, topic state, feature levels, and spotting what diverged, all without a running controller.
- Why prefer running it against a snapshot rather than a live log directory?A live directory is being actively appended to, so reads can be racy or inconsistent. A snapshot (or a copied segment) is a stable, point-in-time image, giving consistent navigation and avoiding interference with the running node.
saying these in an interview costs you the question
- Saying it manages quorum/leadership — that's kafka-metadata-quorum.sh.
- Claiming it can edit/repair metadata — it's a read-only inspector.
- Thinking it requires a running cluster — it can read on-disk files offline.
- Confusing it with kafka-dump-log.sh; the shell builds the materialized image, not a raw record dump.