blob: d70593c65a2ff5402b96808642c207471db6a369 [file] [view]
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# Plan
Milestones, in order. Milestone 0 removes the main risks before anything is built on them. Each later
milestone is a vertical slice, from the wire up to the public API, and is done when its checks pass in CI. The
design is in [DESIGN.md](DESIGN.md).
## M0: Foundations and risks
Settle what everything else depends on.
- **Repository:** a Cargo workspace with `apache-pulsar`, `apache-pulsar-protocol` and `apache-pulsar-testkit`;
ASF license headers, `LICENSE`, `NOTICE`; CI on Linux and macOS; `cargo-deny`.
- **Protobuf:** generate with `buffa`, with an open enum for `BaseCommand.type`, add the proto2-default accessors
and the test that checks them against every `[default]` in the proto ([3](docs/3-protocol.md)). Vendor
`PulsarApi.proto` from a pinned `apache/pulsar` commit, commit the generated code, and add a script that
refreshes it and checks it in CI.
- **compio:** small programs that check, on Linux with io_uring, Linux with the polling driver, and macOS
([2](docs/2-architecture.md) §5):
- TLS through `compio-tls` and rustls;
- waking a loop from another thread;
- timers;
- dropping a future while its operation is in flight;
- DNS resolution.
- **First contact:** the codec and the `CONNECT` handshake against the `apachepulsar/pulsar:5.0.1` image, the
first release with scalable topics, reading the broker's feature flags. A released image keeps CI from building
one from master; the proto is still vendored from a pinned master commit, which only adds fields to 5.0.1's.
- **Vectors from Java:** a small Java program, run against the Pulsar 5.0.1 artifacts from Maven Central, generates
(`MessageIdV5`, `CheckpointV5`, `SegmentRouter` and `Murmur3_32Hash` are the same on master):
- routing vectors for keys (raw hash, segment hash, bucket hash, and the v4 partition for N partitions);
- golden bytes for `MessageIdV5` and `CheckpointV5`.
**Checks:** the handshake passes against the container in CI. Rust's Murmur3 matches every vector. The compio
checks pass on all three setups, or the design is adjusted where they don't.
## M1: Connections and the two client models
- The connection state machine: requests and responses, keepalive, feature-flag gating, token and mTLS
authentication, auth refresh ([3](docs/3-protocol.md)).
- The per-loop pool keyed by logical and physical address; lookup with redirects and proxies; reconnection with
backoff and coalescing ([4](docs/4-connections.md)).
- The simulated broker's skeleton in `apache-pulsar-testkit`.
- The local client, and the thread-safe client over N loops: the hop, close and drop
([2](docs/2-architecture.md) §4). Placement and the admission counters need producers, so they moved to M2.
**Checks:** lookups against the container, directly and through a Pulsar proxy. Disconnect and timeout scenarios
pass on the simulated broker.
## M2: Producer, one message per batch
- Every entry in the batch format, one message per batch, with its bucket stamp ([5](docs/5-segment-engine.md) §2).
Java sends a lone message as a plain entry; the batch format was kept anyway, for one encoding path.
- The layout watch, routing, and the scalable producer: lazy per-segment producers, access modes, dedup, send
timeout, the memory limit, flush and close ([6](docs/6-scalable-topics.md) §2–§3). As in Java V5, the memory
limit is the only bound on what producers hold: there is no pending-message limit.
- Per-key order across splits and merges: Java's retire, park and hold ([6](docs/6-scalable-topics.md) §3.3).
- Routing over a synthetic legacy layout, for `persistent://` topics.
- MessageId encoding, errors, and the producer in the default, local and blocking APIs ([7](docs/7-api.md)).
- Placement of producers on loops, and the memory admission counter ([2](docs/2-architecture.md) §4.1), moved
here from M1.
**Checks:** C1–C6 and the producer side of C12–C15. Ported scenarios from `ScalableTopicProducerTest`,
`ScalableTopicProducerOrderingTest`, `V5ProducerSegmentGoneTest`, `V5ProducerLayoutChangeOrderingTest`,
`V5ProducerAccessModeTest`, `V5ProducerBackpressureTest`, `V5ProducerClosingCompletionTest` and
`V5ScalableTopicAutoCreateTest`. Golden MessageId bytes round-trip with Java. A test confirms that the
pipelining patterns in the rustdoc (`buffered`, `FuturesOrdered`, `join_all`) keep send order
([7](docs/7-api.md) §3.1).
Ported so far: the ordering, segment-gone, access-mode and close scenarios on the simulated cluster
(`crates/apache-pulsar-testkit/tests/producer.rs`), backpressure and pipelining over loopback, and on the real
broker a split during traffic, auto-create and not-found, an exclusive conflict, a partitioned topic, and a Java
consumer reading what Rust produced. The Java tests of Java-only internals (executors, hooks) have no Rust
counterpart.
## M3: Queue consumer
- The segment consumer: Shared subscriptions, flow control, parsing of batched and compressed entries (other
clients produce them), grouped acks, negative acks and redelivery ([5](docs/5-segment-engine.md) §3).
- The Queue consumer: attach to every segment, keep that set in step with the layout, one receive queue, ack
routing by segment ([6](docs/6-scalable-topics.md) §4).
It lands in two pull requests: the segment consumer first, which M4 and M5 build on, then the Queue consumer.
**Checks:** C8. Ported scenarios from `ScalableQueueConsumerReconcileTest`, `ScalableQueueConsumerReceiveLoopTest`,
`V5QueueConsumerBasicTest`, `V5QueueConsumerMultiSegmentAckTest`, `V5SubscriptionInitialPositionTest` and
`V5DAGFollowingTest`, and the Queue consumer cases of the split, merge and layout-watch tests. Java producer ⇄ Rust
consumer, with each codec. `V5MultiTopicQueueConsumerTest` is the namespace consumer's, which comes after the first
release.
## M4: Stream consumer
- The assignment session: register, apply updates, reconnect within grace, unsubscribe on close.
- Exclusive per-segment subscriptions, position vectors, and cumulative ack fanned out across segments.
- The consumer side of entry-bucketing: `Key_Shared` attach, individual acks on shared segments, drain before a
mode flip or a release ([6](docs/6-scalable-topics.md) §5).
**Checks:** C7. Ported scenarios from `ScalableStreamConsumerReconcileTest`, `V5StreamConsumerAckWatermarkTest`
and `V5StreamConsumerDagReplayTest`, plus more consumers than segments, so that segments are shared.
It lands in three pull requests: the segment consumer's cumulative acks, `Key_Shared` attach and draining, with the
simulated broker's Exclusive and `Key_Shared` subscriptions; then the assignment session, the Stream consumer and the
simulated controller; then the driver and the API.
Ported: the reconcile scenarios against hand-made assignments
(`crates/apache-pulsar-protocol/tests/stream_consumer.rs`); on the simulated cluster, `V5StreamConsumerBasicTest`,
`V5StreamConsumerDagReplayTest`, `V5StreamConsumerOrderingTest`, `V5StreamConsumerAutoReconnectTest` and
`V5StreamConsumerAckWatermarkTest`, members that share a segment by bucket, a crashed member's messages handed to
another, and members beyond the buckets (`crates/apache-pulsar-testkit/tests/stream_consumer.rs`); against a 5.0.1
broker, the basic, DAG replay and ordering, sharing, ack watermark and clean leave cases, with a Java producer. The
broker's controller orders a key's segments itself: it hands out a segment once its ancestors are drained.
## M5: Checkpoint consumer
- Readers on every segment, parents first, checkpoint capture and restore, the grouped mode
([6](docs/6-scalable-topics.md) §6).
- Checkpoint encoding.
**Checks:** C9 and C10. Ported scenarios from `ScalableCheckpointConsumerTest`,
`ScalableCheckpointConsumerReconcileTest` and the `V5CheckpointConsumer*Test` classes. Checkpoints round-trip with
Java across a layout change.
It lands in three pull requests: checkpoint encoding with the ungrouped consumer's state machine and its scenarios
on the simulated cluster, then the driver and the API, then the grouped mode, on the Stream consumer's assignment
session from M4.
Done. Checkpoints match Java's golden bytes. The scenarios of the Java tests above pass on the simulated cluster:
those of a consumer on its own in `crates/apache-pulsar-testkit/tests/checkpoint_consumer.rs`, and those of a group's
members in `checkpoint_group.rs`. On the real broker: a resume across a split, a latest start across a split, a
deleted segment, a checkpoint round trip with the Java client across a split and a merge, two members of a group
sharing a topic's segments and handing them over as one leaves, and a member created after a split reading the
sealed backlog. The controller orders nothing for a Checkpoint group, so its members keep a key's order within a
segment only, as Java's do.
## M6: Batching and compression
- Multi-message batches: one open batch per entry bucket, with the stamp ([5](docs/5-segment-engine.md) §2).
- LZ4, ZSTD, ZLIB and Snappy on the producer side.
- A first round of benchmarks ([8](docs/8-quality.md) §6).
**Checks:** ported scenarios from `V5ProducerCompressionTest`. Key affinity holds with batched producers and shared
segments. A performance baseline is recorded.
It lands in three pull requests: batching, then compression, then the benchmarks.
Done. Batching, with Java V5's `BatchingPolicy` and its defaults, and `EntryBucketBatchContainer`'s rules,
on the simulated cluster (`crates/apache-pulsar-testkit/tests/producer_batching.rs`): the three triggers, one bucket
per entry and its stamp, entries in sequence order, the messages that go alone, and open batches on a flush, a close,
a reconnect, a split and a timeout. Key affinity holds on the simulated cluster and against a 5.0.1 broker: two
Stream members sharing a one-segment topic by bucket each get whole keys, in order, from entries of several messages.
Java's `V5EntryBucketDispatchTest` sends one message at a time, so its entries hold one; these pipeline the sends. A
Java consumer reads Rust's batches, and with deduplication on, a 5.0.1 broker takes the entries of every bucket.
Compression, with Java V5's `CompressionPolicy`: the scenarios of `V5ProducerCompressionTest` (a payload with each
codec, none, and no policy set) on the simulated cluster (`producer_compression.rs`) and against a 5.0.1 broker, a
batch compressed whole, and the broker's limit on the compressed entry. A Java consumer reads Rust's batches compressed
with each codec, the ZLIB ones finished streams.
A first round of benchmarks, and a baseline against Java's V5 client on a 5.0.1 broker ([8](docs/8-quality.md) §6):
micro-benchmarks of the producer's state machine and of the codecs, and `tools/perf`, which measures the producer's and
the Queue consumer's throughput and latency against a broker as Java's `pulsar-perf` does. The client side, the
producer and `perf` driving it, is bound by its CPU, most of a send's spent outside the state machine, and the
thread-safe consumer's receives and acks each cross threads: the next rounds look for where a send's time goes, and
measure loops.
## M7: Conformance and a first release
- The rest of the schemas, generic records included (C11, [7](docs/7-api.md) §8).
- End-to-end tests of the migration bridge: partitioned and non-partitioned `persistent://` topics, with v4 clients
running alongside.
- An audit of the error model, rustdoc and examples (send pipelining among them), and the conformance suite
([8](docs/8-quality.md) §2.2).
- A first ASF release.
**Checks:** the conformance checklist C1–C15 is complete, and `tests/PORTING.md` shows the Java scenarios in scope
covered.
The schemas land in six pull requests: the primitive types and C11's typed error; key/value; generic records, with
each message decoded by the schema of its version; JSON and Avro; Protobuf's native type; Java V5's Protobuf type.
The schemas are done: bytes, string, the primitive types, key/value, generic records, JSON, Avro, and Java's two
Protobuf schemas, named and encoded as Java's, with a public `SchemaInfo` and `SchemaType`. JSON, Avro and Protobuf
are features, on by default, through `serde`, apache-avro, buffa's descriptors and prost. The simulated cluster keeps
a schema history per topic, as the broker does, and serves a schema by version. C11 holds there and against a 5.0.1
broker: a schema of another type than the topic's fails with `IncompatibleSchema` for a Shared producer's sends, an
exclusive producer's create, and each kind of consumer's subscribe; the first consumer of a new topic registers its
schema; and a topic with messages but no schema refuses a schema. Java reads the values of each schema that Rust
sends, and Rust those Java sends, typed and as generic records. Generic and Avro consumers fetch the schema of each
version they meet, and decode each message with its own: against 5.0.1, Java's V5 evolution test holds across the two
clients, a second Avro version registering after a split and both clients reading the first version's records with it.
For Protobuf, Rust declares what Java declares for the same message: its descriptors for `PROTOBUF_NATIVE`, and for
Java V5's `Schema.protobuf`, type `PROTOBUF`, the same description in Avro, so that Rust's producers join the version
Java's registered. Neither client reads `PROTOBUF` as generic records, whose definition doesn't say how Protobuf
encodes the message (J22). Key/value is Java's inline encoding; its separated one, with the key in the message's key,
comes later. Java V5's `autoProduceBytes()` and `generic(SchemaInfo)`, which the spec's standard set doesn't name,
aren't planned yet.
The migration bridge's end-to-end tests run against 5.0.1, on partitioned and non-partitioned topics, with Java v4
clients running alongside (`tests/integration/bridge.rs`):
- **Before a migration:** v4 and Rust clients side by side, and on one Shared subscription. Every Rust producer and
consumer is marked as managed by a V5 client, and a v4 client holds a migration off until it is forced.
- **During one:** a producer keeps each key's order with sends in flight, and the Queue and Checkpoint consumers
follow. v4 and Rust clients run through a forced migration.
- **After one:** a Stream consumer reads the legacy segments first, every key in order, and a member of a Checkpoint
consumer group reads them and the new ones.
The 5.0.1 broker gives a migrated topic's first layout the synthetic layout's epoch, which the client allows for
(spec gap 29). Left to the broker: a Stream consumer or a Checkpoint consumer group can't use a topic before it
migrates (spec gap 28, J18). An ignored test keeps what a Stream consumer should get there.
The checks are done. `tests/conformance/README.md` holds the conformance suite, the spec's interoperability cases
described for any SDK, each with what this client runs for it, and the checklist, which names for each of C1–C15 the
tests that show the client meets it. `tests/PORTING.md` lists each Java test class that uses the V5 API, 150 classes
and 694 tests at apache/pulsar `a0e7f7de62`, with the tests here that cover its scenarios: 303 covered and 2 partly;
104 Java-only, 80 the broker's, 18 needing several brokers and 177 out of scope. The 10 in scope that aren't ported,
and what the 2 partly covered miss, each have their reason there: what the client doesn't have (a processing timeout,
a TLS certificate apart from authentication, metrics, a proxy URL, Java V5's `autoProduceBytes()` and
`generic(SchemaInfo)`), a failed `CONNECT` write, which nothing can cause over loopback, how the controller converges
under churn, which is the broker's, and a bug. Java's tests added since `a0e7f7de62` aren't mapped yet.
The bug is the checklist's known gap under C7: once the controller moves to another broker, a Stream consumer whose
client holds the topic's layout watch for something else too, a producer say, registers again with the old
controller. From the code, a member of a Checkpoint consumer group, which registers the same way and holds the watch
itself, would too. An ignored test pins it until it is fixed.
## After the first release
In rough order: OAuth2 authentication, dead-letter policy, namespace subscription, transactions, end-to-end
encryption, chunking, Windows as a tested platform. Then the later phase: a base for other language SDKs
([1](docs/1-scope.md) §6). The classic API, below, is part of it; where it goes in this order is open
([9](docs/9-classic-api.md) §12).
After M2, the three consumer milestones (M3–M5) can proceed in parallel. They share the segment consumer from M3,
so its subscription and ack parts land first.
## The classic API (proposed)
A classic (v4) API in a crate of its own, so that other languages can wrap this client's core
([9](docs/9-classic-api.md)). These steps are proposed. The crates' layout and names, the brokers they support, and
whether they wait for the first release are open questions there (§12).
### 1. The engine apart from the scalable layer
- A single-topic producer, carved out of the scalable producer, and each task's work on one topic apart from its
following of layouts ([9](docs/9-classic-api.md) §7).
- `apache-pulsar-core`: the driver, the connections, the loops and the engine, moved out of `apache-pulsar`, and
its place in the release ([9](docs/9-classic-api.md) §10).
**Checks:** the existing tests pass unchanged, and `apache-pulsar`'s public API doesn't change.
### 2. Producer
- `apache-pulsar-classic`: the client, and the producer on a topic partitioned or not: partitioned metadata,
routing modes, hashing schemes, partition-count updates, batching, compression, access modes and dedup
([9](docs/9-classic-api.md) §6.1).
- `MessageId`, the errors, and the producer in the three APIs ([9](docs/9-classic-api.md) §5).
**Checks:** a Java v4 consumer reads what Rust produces, keys land on the partitions Java's producer picks, and
message-id bytes round-trip with Java, against a broker of each supported line ([9](docs/9-classic-api.md) §8).
### 3. Consumer
- Exclusive, Shared, Failover and `Key_Shared` subscriptions; acks, negative acks, the ack timeout, seek and
unsubscribe; partitioned topics ([9](docs/9-classic-api.md) §6.2).
**Checks:** a Java v4 producer and a Rust consumer on each subscription type, and Java and Rust consumers on one
subscription. Failover moves the active consumer when it closes. Seek works by id and by time.
### 4. Several topics, and the reader
- Consumers on a list of topics or on a pattern, with the topic-list watch ([9](docs/9-classic-api.md) §6.3).
- The reader ([9](docs/9-classic-api.md) §6.4).
**Checks:** a pattern consumer picks up a topic created after it subscribed. A reader starts at the earliest, the
latest and a stored id, inclusive or not.
### 5. Java's v4 tests
- The client scenarios of Java's v4 tests, mapped as `tests/PORTING.md` maps the V5 ones, and those in scope
ported ([9](docs/9-classic-api.md) §9).
Whatever the order, the capabilities in the list above are built once, in the shared engine, for both crates. The
bindings come after the classic API ([9](docs/9-classic-api.md) §11).