Expand description
Formats the log directories of a krabka broker node.
A KRaft node will not boot against an unformatted directory: the broker
treats one as operator error and aborts startup. Formatting seeds Kafka’s
meta.properties, the bootstrap records, and the singleton VotersRecord,
and can provision seed SCRAM credentials at the same time. One run formats
every directory of the node, as kafka-storage format does, and writes the
cluster and directory ids in Kafka’s 22-character base64 form.
docs/format-divergences.md in the repository lists where the command
differs from kafka-storage format, and why.
MetaProperties reads and writes meta.properties byte for byte as
Kafka does. The broker reads the file through it, and so can any tool that
has to find the identity of a formatted directory.
run_with_records takes further MetadataRecords from the caller and
seeds them into the same stream. A restore tool that rebuilds a cluster from
tiered-storage archives hands over the topic and partition records it
recovered that way, and the broker then boots with those topics present.
This is the krabka format command from the monorepo’s krabka-cli. That
crate also drives the gres layer, which is why it could not follow the broker
into this repository; the command itself needs only krabka_metadata and
[krabka_security]. It is a library as well as a binary so krabka-cli can
call it rather than carry a second copy.
Structs§
- Cli
- The formatter’s command line.
- Cluster
Id - A Kafka cluster id: the identity that every node of a cluster shares.
- Directory
Id - A log directory’s stable id (KIP-858). The metadata directory’s id is also the node’s KIP-853 voter identity.
- Format
Args - Meta
Properties - The content of a version 1
meta.properties. - Scram
Spec
Enums§
- Kafka
Uuid Error - A string that is not a Kafka
Uuid. - Meta
Properties Error - Why a
meta.propertiesdoes not read. - Metadata
Record - The seed record type
run_with_recordsaccepts, re-exported so a caller building a bootstrap stream does not have to namekrabka_metadataitself.
Constants§
- FAIL_
AFTER_ ENV - The environment variable that makes a run fail after it writes the file of the given name. It is a test seam: it is how the tests interrupt a run partway through, to show that the next run recovers.
- LATEST_
PRODUCTION_ METADATA_ VERSION - The
metadata.versiona cluster formats at when neither--release-versionnor--feature metadata.versionnames one: Kafka 4.3’sMetadataVersion.LATEST_PRODUCTION,4.3-IV0. - META_
PROPERTIES - The file name, Kafka’s
MetaPropertiesEnsemble.META_PROPERTIES_NAME. - META_
PROPERTIES_ TMP - The name of the file while it is written, before the rename that
publishes it.
PropertiesUtils.writePropertiesFileadds.tmp. - META_
PROPERTIES_ VERSION - The version of the file that a
KRaftnode writes,MetaPropertiesVersion.V1.
Functions§
- parse_
node_ id - Parses a node id as Kafka’s
node.id: anintthat is not negative. - random_
uuid - Returns a random id, as Kafka’s
Uuid.randomUuiddoes: never the zero id or the id with value one, and never one whose string form starts with-, which a command-line parser would read as an option. - run
- Formats the metadata log directory and
args.log_dirs, returning the process exit code. - run_
from_ args - Run the formatter from an argv-style iterator, returning its exit code.
- run_
from_ args_ with_ records - Run the formatter from an argv-style iterator, seeding
extraalongside the records the flags produce, and return its exit code. - run_
from_ args_ with_ records_ to run_from_args_with_records, with the progress lines of a successful format written toprogressinstead of stdout;run_with_records_tosays why a caller wants that.- run_
with_ records - Formats the metadata log directory and
args.log_dirswithextraseeded alongside the records the flags produce, returning the process exit code. - run_
with_ records_ to run_with_records, with Kafka’s progress lines written toprogressinstead of stdout.- verify_
ensemble - Kafka’s
MetaPropertiesEnsemble.verify, over the readable files of the directories of one node, sorted by path.