Ankusa.Intake.Kafka (ankusa_kafka v0.7.0)

Copy Markdown View Source

The Kafka adapter of wal: :dual (Ankusa.Intake, ADR 0002): every acked hook is also a record in a replicated Kafka topic, so a lost host loses nothing.

"Confirmed" means a produce sent with required_acks: -1 and ack_timeout: intake.publish_timeout_ms that brod reports as acked: every in-sync replica has the batch, and the in-sync set was at least the topic's min.insync.replicas (the broker, not this client, refuses with not_enough_replicas when it is smaller).

The adapter has a brod client of its own, :"ankusa_kafka.<instance>.intake", never the sink's. Its producer is configured for one attempt per call:

  • partition_onwire_limit: 1 — one produce on the wire per partition, so seq order is log order
  • max_retries: 0 — the reconciler owns every retry, which keeps the attempt deadline real
  • allow_topic_auto_creation: false — the topic is the operator's

Every record goes to one explicit partition, the node's stamped m:intake_partition: phash2(node_id) rem partition_count, chosen at the node's first dual boot and never recomputed, so growing the topic never remaps a node. The record key is the node id.

brod has no idempotent producer: a produce whose ack is lost and which the reconciler then retries can land twice, and a record may land behind newer ones. Every reader applies a record through the seq-and-id rule of Ankusa.Intake.Recovery, so a duplicate or reordered record changes nothing.

Record

The value is the hooks column family value (Ankusa.Envelope.to_binary/2). Headers: ankusa_intake_v ("1"), ankusa_intake_kind ("hook"), ankusa_intake_node, ankusa_intake_seq, ankusa_intake_id, ankusa_intake_incarnation, ankusa_intake_tenant, ankusa_intake_source.

Errors

A broker error code, wherever brod nests it, is one of the four classes of Ankusa.Intake: unknown_topic_or_partition is :not_found; message_too_large, invalid_message, invalid_record and topic_authorization_failed are :permanent; throttling_quota_exceeded is :throttled; everything else (not_enough_replicas, not_enough_replicas_after_append — the record was appended, so the republish is what resolves it —, leader_not_available, request_timed_out, a missed deadline, a client that is down) is :unavailable. brod does not surface a produce response's throttle_time_ms, so a quota that only delays shows as latency.

verify/1

Boot refuses a topic the promise does not hold on (DescribeConfigs and metadata, through kafka_protocol, with a connection of its own so it works before the client is up): replication factor at least 3, min.insync.replicas at least 2, unclean.leader.election.enable false, retention.ms at least twice backup.max_age_ms (or infinite) and max.message.bytes at least intake.max_record_bytes.

Options (intake.kafka)

  • :brokers — required, "host:port" strings
  • :ssl, :sasl — as Ankusa.Sink.Kafka
  • :health_interval_ms — how often ready?/1 is refreshed, default 1_000

Summary

Functions

Returns a specification to start this module under a supervisor.

The class a broker or client failure belongs to (Ankusa.Intake.class/0). brod nests an error code anywhere in its reason; the first class that matches, most specific first, wins.

The brod client of an instance's intake.

The partition a node id maps to in a topic of count partitions (the same hash as Ankusa.Sink.Kafka).

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

classify(reason)

@spec classify(term()) :: Ankusa.Intake.class()

The class a broker or client failure belongs to (Ankusa.Intake.class/0). brod nests an error code anywhere in its reason; the first class that matches, most specific first, wins.

client(instance)

@spec client(atom()) :: atom()

The brod client of an instance's intake.

partition_for(node_id, count)

@spec partition_for(String.t(), pos_integer()) :: non_neg_integer()

The partition a node id maps to in a topic of count partitions (the same hash as Ankusa.Sink.Kafka).

start_link(opts)