@zukhruf/checkpoint 0.0.0-stage → 0.8.165
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +436 -2
- package/dist/checkpoint-store.d.ts +34 -0
- package/dist/checkpoint-store.d.ts.map +1 -0
- package/dist/checkpoint-store.js +2 -0
- package/dist/checkpoint-store.js.map +1 -0
- package/dist/checkpoint.d.ts +60 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +2 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/consumer-group.d.ts +30 -0
- package/dist/consumer-group.d.ts.map +1 -0
- package/dist/consumer-group.js +56 -0
- package/dist/consumer-group.js.map +1 -0
- package/dist/errors.d.ts +34 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +46 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/map-state.d.ts +36 -0
- package/dist/map-state.d.ts.map +1 -0
- package/dist/map-state.js +82 -0
- package/dist/map-state.js.map +1 -0
- package/dist/memory-checkpoint-store.d.ts +25 -0
- package/dist/memory-checkpoint-store.d.ts.map +1 -0
- package/dist/memory-checkpoint-store.js +107 -0
- package/dist/memory-checkpoint-store.js.map +1 -0
- package/dist/partition-context.d.ts +36 -0
- package/dist/partition-context.d.ts.map +1 -0
- package/dist/partition-context.js +80 -0
- package/dist/partition-context.js.map +1 -0
- package/package.json +48 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ezzabuzaid
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,437 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zukhruf/checkpoint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Being built (backlog #6201).** The maintainer approved this API on 2026-11-27. `ConsumerGroup`, `PartitionContext`, the map states, the errors and `MemoryCheckpointStore` exist. The trackers and the SQLite, Postgres and SQL Server stores come next.
|
|
4
|
+
|
|
5
|
+
Keep how far a reader of a stream got, so that it can resume after a stop or a crash. A **checkpoint** belongs to one consumer group, one stream and one partition of that stream. It holds a position, which names the next record to read, and the keyed state of the reader, which a commit saves as changes. A commit saves the position, the state changes and the next checkpoint id together, and it can write the output of the reader in the same transaction. A newer claim of a partition fences the older one, so a reader that a restart replaced cannot commit.
|
|
6
|
+
|
|
7
|
+
The package replaces the checkpoint stores of elt and the position of `@zukhruf/sqlite-changefeed`, which move here ([ADR 0001](./docs/adr/0001-the-package-keeps-the-progress-of-a-reader-of-a-stream-and-the-checkpoint-stores-of-elt-and-the-position-of-sqlite-changefeed-move-into-it.md)).
|
|
8
|
+
|
|
9
|
+
The package has four entry points. `@zukhruf/checkpoint` has `ConsumerGroup`, the store port, the memory store, the trackers and the errors. `@zukhruf/checkpoint/sqlite`, `@zukhruf/checkpoint/postgres` and `@zukhruf/checkpoint/sqlserver` each have the store of one engine.
|
|
10
|
+
|
|
11
|
+
The words in these documents have one meaning each. See the glossary in [CONTEXT.md](./CONTEXT.md).
|
|
12
|
+
|
|
13
|
+
## Use it
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @zukhruf/checkpoint
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
21
|
+
|
|
22
|
+
import { ConsumerGroup, type Format } from '@zukhruf/checkpoint';
|
|
23
|
+
import { SqliteCheckpointStore } from '@zukhruf/checkpoint/sqlite';
|
|
24
|
+
|
|
25
|
+
type Position = { readonly above: string };
|
|
26
|
+
|
|
27
|
+
const positionFormat: Format<Position> = {
|
|
28
|
+
version: 1,
|
|
29
|
+
encode: (position) => position,
|
|
30
|
+
decode: (version, json) => {
|
|
31
|
+
if (version !== 1) throw new TypeError(`Unknown version ${version}`);
|
|
32
|
+
return json as Position;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const database = new DatabaseSync('copy.sqlite');
|
|
37
|
+
const group = new ConsumerGroup(
|
|
38
|
+
'mail-copy',
|
|
39
|
+
new SqliteCheckpointStore({ database }),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const context = await group.claim(
|
|
43
|
+
{ stream: 'messages', partition: 'inbox' },
|
|
44
|
+
positionFormat,
|
|
45
|
+
);
|
|
46
|
+
let from = context.checkpoint?.position ?? { above: '0' };
|
|
47
|
+
for await (const page of readMessages(from)) {
|
|
48
|
+
await context.commit(page.next, {
|
|
49
|
+
write: (database) => insertRows(database, page.rows),
|
|
50
|
+
});
|
|
51
|
+
from = page.next;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`readMessages` and `insertRows` are the reader's own code. The rows and the position commit in one SQLite transaction, or neither does.
|
|
56
|
+
|
|
57
|
+
## Resume a reader from its checkpoint
|
|
58
|
+
|
|
59
|
+
`group.claim(partition, format)` takes the partition for this reader and reads its checkpoint ([ADR 0005](./docs/adr/0005-a-claim-gives-the-saved-checkpoint-or-none-and-the-reader-picks-its-start-when-it-has-none.md)).
|
|
60
|
+
|
|
61
|
+
- `context.checkpoint` is the checkpoint that the claim read: its `position` and its `checkpointId`. It is `undefined` when the partition had no checkpoint. Then the reader picks its own start, for example the first record or the newest one. It does not change after a commit, as Flink gives the restored checkpoint only once; each commit resolves with the new checkpoint.
|
|
62
|
+
- The position names the next record to read. Each record before it is done ([ADR 0004](./docs/adr/0004-a-position-is-an-opaque-json-value-with-a-format-version-and-it-names-the-next-record-to-read.md)).
|
|
63
|
+
- The package never reads the position. The `format` writes it as JSON with a version, and reads it back.
|
|
64
|
+
|
|
65
|
+
A partition is a part of a stream that the reader reads in order, such as a mailbox, a table or a shard. A stream that has no parts has one partition, for example `'0'`. An input with a new identity is a new stream or a new partition, so it has a new checkpoint ([ADR 0003](./docs/adr/0003-a-checkpoint-belongs-to-a-consumer-group-a-stream-and-a-partition-and-an-input-with-a-new-identity-has-a-new-checkpoint.md)).
|
|
66
|
+
|
|
67
|
+
## Keep keyed state beside the position
|
|
68
|
+
|
|
69
|
+
`context.state(name, format)` gives a map state: one value for each key, kept with the checkpoint ([ADR 0006](./docs/adr/0006-keyed-state-is-a-set-of-named-map-states-and-a-commit-writes-only-what-changed.md)).
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const seen = context.state('seen', fingerprintFormat);
|
|
73
|
+
|
|
74
|
+
if ((await seen.get(row.key)) !== row.fingerprint) changed.push(row);
|
|
75
|
+
seen.set(row.key, row.fingerprint);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- `get`, `has` and `entries` read the committed values and the changes of this context. They are async: a store reads a key when it is asked, so the state can be larger than memory.
|
|
79
|
+
- `set`, `delete` and `clear` change the state in memory. The next commit saves only these changes.
|
|
80
|
+
- Each name is one map state. Two map states of one partition never share a key.
|
|
81
|
+
|
|
82
|
+
## Commit the output and the checkpoint together
|
|
83
|
+
|
|
84
|
+
`context.commit(position, options)` saves the position, the changes of each map state and the next checkpoint id, all of them or none of them ([ADR 0007](./docs/adr/0007-a-commit-saves-the-position-the-state-changes-and-the-next-checkpoint-id-together-and-can-write-the-output-in-the-same-transaction.md)). It resolves with the new checkpoint.
|
|
85
|
+
|
|
86
|
+
- With `write`, the store runs the write in the transaction of the commit, after it checks the epoch. The output and the checkpoint commit together. A fenced reader writes no output.
|
|
87
|
+
- With no `write`, the commit is alone. The reader commits its output first, then the checkpoint. A crash between the two reads the last records again: delivery is at least once.
|
|
88
|
+
- The type of `write` comes from the store. The SQLite store gives the `DatabaseSync` of its database. The Postgres and SQL Server stores give the session of the transaction. The memory store takes no `write`.
|
|
89
|
+
|
|
90
|
+
## Stop a reader that a newer claim replaced
|
|
91
|
+
|
|
92
|
+
Each claim of a partition gets a new epoch. The newest claim owns the partition ([ADR 0008](./docs/adr/0008-a-newer-claim-fences-an-older-one-and-a-commit-of-a-fenced-claim-throws-and-writes-nothing.md)).
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
try {
|
|
96
|
+
await context.commit(next);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error instanceof CheckpointFencedError) return; // a newer run reads this partition now
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- A commit checks the epoch in its transaction. When a newer claim or a reset took the partition, the commit throws `CheckpointFencedError` and writes nothing, also no output.
|
|
104
|
+
- No claim waits and no claim expires. A restart claims the partition again, and the reader of the old run stops at its next commit.
|
|
105
|
+
|
|
106
|
+
## Change the format of a position
|
|
107
|
+
|
|
108
|
+
The `format` of a position or of a map state has a version. A commit writes the version beside the JSON. A claim gives the stored version to `decode` ([ADR 0004](./docs/adr/0004-a-position-is-an-opaque-json-value-with-a-format-version-and-it-names-the-next-record-to-read.md)).
|
|
109
|
+
|
|
110
|
+
- To change a format, raise its `version`, and let `decode` read each older version that it can migrate.
|
|
111
|
+
- When `decode` throws, the claim or the read throws `IncompatibleCheckpointError`, with the error of `decode` as its cause. Then migrate in `decode`, or reset the partition.
|
|
112
|
+
|
|
113
|
+
## List and reset the checkpoints of a consumer group
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
for await (const checkpoint of group.list({ stream: 'messages' }))
|
|
117
|
+
console.log(checkpoint.partition, checkpoint.checkpointId);
|
|
118
|
+
|
|
119
|
+
await group.reset({ stream: 'messages', partition: 'inbox' });
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
- `list` gives the checkpoint of each partition, with no position and no state ([ADR 0009](./docs/adr/0009-a-consumer-group-lists-and-resets-its-checkpoints-and-a-reset-fences-the-live-owner.md)).
|
|
123
|
+
- `reset` removes the checkpoint and the state of one partition, or of each partition of a stream. It fences the live owner first, so the owner cannot commit an old position after the reset.
|
|
124
|
+
|
|
125
|
+
## Find the position when records finish out of order
|
|
126
|
+
|
|
127
|
+
A reader that handles records in parallel can finish them out of order. The checkpoint must not pass a record that is not done. A tracker gives the highest position below which each record is done ([ADR 0010](./docs/adr/0010-a-tracker-gives-the-highest-position-below-which-every-record-is-done.md)).
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
const tracker = new CappedTracker<Position>(1000);
|
|
131
|
+
|
|
132
|
+
const done = await tracker.track(batch.next, batch.records.length);
|
|
133
|
+
await handle(batch);
|
|
134
|
+
const position = done();
|
|
135
|
+
if (position) await context.commit(position);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- `track(position, size)` records a batch in the order that the reader read it, and gives the function that marks it done.
|
|
139
|
+
- The function gives the highest position below which each batch is done, or `undefined` when an earlier batch is still open.
|
|
140
|
+
- `CappedTracker` waits in `track` while more than its capacity is open. `UncappedTracker` never waits.
|
|
141
|
+
|
|
142
|
+
## Write your own store
|
|
143
|
+
|
|
144
|
+
A store is an implementation of `CheckpointStore` ([ADR 0011](./docs/adr/0011-the-package-has-a-memory-store-and-stores-for-sqlite-postgres-and-sql-server-and-a-host-can-write-its-own.md)). `ConsumerGroup` is the only caller of a store.
|
|
145
|
+
|
|
146
|
+
- `claim` raises the epoch of a key in one atomic write and gives the new epoch.
|
|
147
|
+
- `commit` checks the epoch, runs the write, and writes the position, the version, the checkpoint id and the state changes, in one transaction. It throws `CheckpointFencedError` when the stored epoch is newer.
|
|
148
|
+
- `get` and `scan` read the values of one map state. `read` reads the stored checkpoint.
|
|
149
|
+
- `list` and `reset` work on the keys of one consumer group.
|
|
150
|
+
|
|
151
|
+
## Errors
|
|
152
|
+
|
|
153
|
+
| Error | When |
|
|
154
|
+
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
155
|
+
| `CheckpointFencedError` | A commit of a context whose epoch is older than the stored epoch: a newer claim or a reset took the partition. The commit wrote nothing. The reader stops. It does not retry. |
|
|
156
|
+
| `IncompatibleCheckpointError` | `decode` of a format threw for a stored version. The error of `decode` is its `cause`. Migrate the version in `decode`, or reset the partition. |
|
|
157
|
+
| `CorruptCheckpointError` | A stored checkpoint or value is not a valid record of the store: its JSON does not parse, or a field is missing. Only a reset repairs it. |
|
|
158
|
+
| The error of the driver | The store cannot reach its database. The package does not wrap it ([ADR 0012](./docs/adr/0012-the-package-owns-three-error-classes-one-for-each-next-step.md)). The reader can retry. |
|
|
159
|
+
|
|
160
|
+
## What the package does not do
|
|
161
|
+
|
|
162
|
+
- **It does not decide when to commit.** The reader commits after each page, each batch or each interval. A commit cadence belongs to the reader, as auto commit belongs to the Kafka consumer and the commit policy to the Debezium engine ([ADR 0001](./docs/adr/0001-the-package-keeps-the-progress-of-a-reader-of-a-stream-and-the-checkpoint-stores-of-elt-and-the-position-of-sqlite-changefeed-move-into-it.md)).
|
|
163
|
+
- **It does not assign partitions to workers.** A claim takes a partition, and a newer claim takes it from an older one. Load balancing over workers is the work of a group coordinator, such as `@zukhruf/election` or `@zukhruf/pool`.
|
|
164
|
+
- **It does not know the start of a stream.** "The first record", "the newest record" and "a time" are words of the input. The reader picks its start when `context.checkpoint` is `undefined`.
|
|
165
|
+
- **It does not keep old checkpoints.** A commit replaces the checkpoint. A store of older checkpoints for a rollback (savepoints) comes later (Ezz, 2026-11-27).
|
|
166
|
+
- **It does not replay the steps of a program.** A journal of step results is durable execution, which is the work of a separate package.
|
|
167
|
+
|
|
168
|
+
## Who uses it
|
|
169
|
+
|
|
170
|
+
No code yet. Each consumer moves after the release, with a migration item in its repository ([ADR 0001](./docs/adr/0001-the-package-keeps-the-progress-of-a-reader-of-a-stream-and-the-checkpoint-stores-of-elt-and-the-position-of-sqlite-changefeed-move-into-it.md)).
|
|
171
|
+
|
|
172
|
+
| Consumer | How | Record |
|
|
173
|
+
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ |
|
|
174
|
+
| elt | `CheckpointStore`, its SQLite, Postgres and SQL Server stores, the binding and the keyed entries of a `STATE` message go away. A copy claims its partition and commits its stage in `write`. | #6201 |
|
|
175
|
+
| `@zukhruf/sqlite-changefeed` | `Position`, `PositionFile` and `PositionInMemory` go away. The WAL progress is the position, the fingerprints of each table are a map state, and the sequence of a batch is the checkpoint id. | #6201 |
|
|
176
|
+
| eca and its proactive host | The cursor of each automation is the position of a checkpoint. | #6201 |
|
|
177
|
+
|
|
178
|
+
## The same concepts in other systems
|
|
179
|
+
|
|
180
|
+
| Concept | Other systems |
|
|
181
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
182
|
+
| Checkpoint store | Event Hubs `CheckpointStore` ([.NET](https://github.com/Azure/azure-sdk-for-net/blob/9841bf0096d377f09c976fea5c201ffe9606b4ff/sdk/eventhub/Azure.Messaging.EventHubs/src/Primitives/CheckpointStore.cs)), Kinesis `Checkpointer`, Orleans `IStreamCheckpointStore`, Kafka Connect `OffsetBackingStore`, Debezium `OffsetStore` |
|
|
183
|
+
| Consumer group and partition | Kafka `group.id` and `TopicPartition`, Event Hubs `consumerGroup` and `partitionId`, Kinesis application and shard |
|
|
184
|
+
| Position | Kafka committed offset ("the offset of the next message"), Event Hubs `CheckpointPosition`, Kafka Connect source offset, Spark `Offset` |
|
|
185
|
+
| Format with a version | Flink `SimpleVersionedSerializer`, Airbyte `StateMigration` |
|
|
186
|
+
| Map state | Flink `MapState`, Spark `MapState`, Kafka Streams `KeyValueStore` |
|
|
187
|
+
| Commit of changes only | Flink incremental checkpoints and the changelog, Kafka Streams changelog topics, Spark delta files |
|
|
188
|
+
| Output in the commit | Kafka `sendOffsetsToTransaction`, Kafka Streams exactly-once, Kafka Connect exactly-once sources (KIP-618) |
|
|
189
|
+
| Epoch and fencing | Kinesis lease counter (`ShutdownException`), Kafka `CommitFailedException` and `ProducerFencedException`, Kafka Streams `TaskMigratedException`, Kafka Connect zombie fencing |
|
|
190
|
+
| Reset | Kafka Connect `DELETE /connectors/{name}/offsets` (KIP-875), Airbyte `eraseState`, Singer `reset_stream` |
|
|
191
|
+
| Tracker | Go `Jeffail/checkpoint` `Capped` and `Uncapped`, Kafka Connect `SubmittedRecords` |
|
|
192
|
+
|
|
193
|
+
No package on npm does this work for any store. Each candidate of the search on 2026-11-27 fails one requirement:
|
|
194
|
+
|
|
195
|
+
| Package | Why it does not fit |
|
|
196
|
+
| ---------------------------------- | ------------------------------------------------------------------------------------- |
|
|
197
|
+
| `@azure/event-hubs` and its stores | Only for Event Hubs. No keyed state. A checkpoint write does not check the owner. |
|
|
198
|
+
| `kafkajs`, `kafka-node` | Only for Kafka. The broker is the store. |
|
|
199
|
+
| `@langchain/langgraph-checkpoint` | The state of a graph per thread, not the position of a reader of a stream. |
|
|
200
|
+
| `keyv` | A key-value store. No position, no commit of a position and state together, no owner. |
|
|
201
|
+
|
|
202
|
+
## API
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
// @zukhruf/checkpoint
|
|
206
|
+
// @zukhruf/checkpoint/sqlite
|
|
207
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
208
|
+
|
|
209
|
+
import type { FencingToken } from '@zukhruf/fencing';
|
|
210
|
+
|
|
211
|
+
export type Json =
|
|
212
|
+
| null
|
|
213
|
+
| boolean
|
|
214
|
+
| number
|
|
215
|
+
| string
|
|
216
|
+
| readonly Json[]
|
|
217
|
+
| { readonly [key: string]: Json };
|
|
218
|
+
|
|
219
|
+
/** How a value is written as JSON and read back (Flink's SimpleVersionedSerializer). */
|
|
220
|
+
export type Format<T> = {
|
|
221
|
+
readonly version: number;
|
|
222
|
+
encode(value: T): Json;
|
|
223
|
+
/** Reads a value that `version` wrote. Throws when it cannot. */
|
|
224
|
+
decode(version: number, json: Json): T;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export type StreamPartition = {
|
|
228
|
+
readonly stream: string;
|
|
229
|
+
readonly partition: string;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
export type Checkpoint<P> = {
|
|
233
|
+
readonly position: P;
|
|
234
|
+
/** One more with each commit of the partition. */
|
|
235
|
+
readonly checkpointId: number;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export interface MapState<V> {
|
|
239
|
+
get(
|
|
240
|
+
key: string,
|
|
241
|
+
options?: { readonly signal?: AbortSignal },
|
|
242
|
+
): Promise<V | undefined>;
|
|
243
|
+
has(
|
|
244
|
+
key: string,
|
|
245
|
+
options?: { readonly signal?: AbortSignal },
|
|
246
|
+
): Promise<boolean>;
|
|
247
|
+
entries(options?: {
|
|
248
|
+
readonly signal?: AbortSignal;
|
|
249
|
+
}): AsyncIterable<[key: string, value: V]>;
|
|
250
|
+
set(key: string, value: V): void;
|
|
251
|
+
delete(key: string): void;
|
|
252
|
+
clear(): void;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export class PartitionContext<P, W> {
|
|
256
|
+
readonly consumerGroup: string;
|
|
257
|
+
readonly stream: string;
|
|
258
|
+
readonly partition: string;
|
|
259
|
+
readonly epoch: FencingToken;
|
|
260
|
+
/** The checkpoint that the claim read; undefined when there was none. */
|
|
261
|
+
readonly checkpoint: Checkpoint<P> | undefined;
|
|
262
|
+
state<V>(name: string, format: Format<V>): MapState<V>;
|
|
263
|
+
commit(
|
|
264
|
+
position: P,
|
|
265
|
+
options?: { readonly write?: W; readonly signal?: AbortSignal },
|
|
266
|
+
): Promise<Checkpoint<P>>;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export type CheckpointSummary = {
|
|
270
|
+
readonly stream: string;
|
|
271
|
+
readonly partition: string;
|
|
272
|
+
readonly checkpointId: number;
|
|
273
|
+
readonly epoch: FencingToken;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export class ConsumerGroup<W> {
|
|
277
|
+
constructor(name: string, store: CheckpointStore<W>);
|
|
278
|
+
readonly name: string;
|
|
279
|
+
claim<P>(
|
|
280
|
+
partition: StreamPartition,
|
|
281
|
+
format: Format<P>,
|
|
282
|
+
options?: { readonly signal?: AbortSignal },
|
|
283
|
+
): Promise<PartitionContext<P, W>>;
|
|
284
|
+
list(options?: {
|
|
285
|
+
readonly stream?: string;
|
|
286
|
+
readonly signal?: AbortSignal;
|
|
287
|
+
}): AsyncIterable<CheckpointSummary>;
|
|
288
|
+
reset(
|
|
289
|
+
target: { readonly stream: string; readonly partition?: string },
|
|
290
|
+
options?: { readonly signal?: AbortSignal },
|
|
291
|
+
): Promise<void>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// The store port. ConsumerGroup is its only caller.
|
|
295
|
+
export type CheckpointKey = StreamPartition & {
|
|
296
|
+
readonly consumerGroup: string;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export type StoredValue = { readonly version: number; readonly json: Json };
|
|
300
|
+
|
|
301
|
+
export type StoredCheckpoint = StoredValue & { readonly checkpointId: number };
|
|
302
|
+
|
|
303
|
+
export type StateChanges = {
|
|
304
|
+
readonly cleared: ReadonlySet<string>;
|
|
305
|
+
readonly set: ReadonlyMap<string, ReadonlyMap<string, StoredValue>>;
|
|
306
|
+
readonly deleted: ReadonlyMap<string, ReadonlySet<string>>;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export interface CheckpointStore<W> {
|
|
310
|
+
claim(
|
|
311
|
+
key: CheckpointKey,
|
|
312
|
+
options?: { readonly signal?: AbortSignal },
|
|
313
|
+
): Promise<FencingToken>;
|
|
314
|
+
read(
|
|
315
|
+
key: CheckpointKey,
|
|
316
|
+
options?: { readonly signal?: AbortSignal },
|
|
317
|
+
): Promise<StoredCheckpoint | undefined>;
|
|
318
|
+
get(
|
|
319
|
+
key: CheckpointKey,
|
|
320
|
+
state: string,
|
|
321
|
+
keys: readonly string[],
|
|
322
|
+
options?: { readonly signal?: AbortSignal },
|
|
323
|
+
): Promise<ReadonlyMap<string, StoredValue>>;
|
|
324
|
+
scan(
|
|
325
|
+
key: CheckpointKey,
|
|
326
|
+
state: string,
|
|
327
|
+
options?: { readonly signal?: AbortSignal },
|
|
328
|
+
): AsyncIterable<[string, StoredValue]>;
|
|
329
|
+
commit(
|
|
330
|
+
key: CheckpointKey,
|
|
331
|
+
epoch: FencingToken,
|
|
332
|
+
checkpoint: StoredCheckpoint,
|
|
333
|
+
changes: StateChanges,
|
|
334
|
+
options?: { readonly write?: W; readonly signal?: AbortSignal },
|
|
335
|
+
): Promise<void>;
|
|
336
|
+
list(
|
|
337
|
+
consumerGroup: string,
|
|
338
|
+
options?: { readonly stream?: string; readonly signal?: AbortSignal },
|
|
339
|
+
): AsyncIterable<CheckpointSummary>;
|
|
340
|
+
reset(
|
|
341
|
+
consumerGroup: string,
|
|
342
|
+
target: { readonly stream: string; readonly partition?: string },
|
|
343
|
+
options?: { readonly signal?: AbortSignal },
|
|
344
|
+
): Promise<void>;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export class MemoryCheckpointStore implements CheckpointStore<never> {}
|
|
348
|
+
|
|
349
|
+
export class UncappedTracker<P> {
|
|
350
|
+
track(position: P, size: number): () => P | undefined;
|
|
351
|
+
highest(): P | undefined;
|
|
352
|
+
readonly pending: number;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export class CappedTracker<P> {
|
|
356
|
+
constructor(capacity: number);
|
|
357
|
+
track(
|
|
358
|
+
position: P,
|
|
359
|
+
size: number,
|
|
360
|
+
options?: { readonly signal?: AbortSignal },
|
|
361
|
+
): Promise<() => P | undefined>;
|
|
362
|
+
highest(): P | undefined;
|
|
363
|
+
readonly pending: number;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export class CheckpointFencedError extends Error {
|
|
367
|
+
readonly key: CheckpointKey;
|
|
368
|
+
readonly epoch: FencingToken;
|
|
369
|
+
}
|
|
370
|
+
export class IncompatibleCheckpointError extends Error {
|
|
371
|
+
readonly key: CheckpointKey;
|
|
372
|
+
readonly version: number;
|
|
373
|
+
}
|
|
374
|
+
export class CorruptCheckpointError extends Error {
|
|
375
|
+
readonly key: CheckpointKey;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export class SqliteCheckpointStore implements CheckpointStore<
|
|
379
|
+
(database: DatabaseSync) => void
|
|
380
|
+
> {
|
|
381
|
+
constructor(options: { readonly database: DatabaseSync });
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// @zukhruf/checkpoint/postgres
|
|
385
|
+
export type PostgresSession = {
|
|
386
|
+
query(
|
|
387
|
+
sql: string,
|
|
388
|
+
parameters: readonly unknown[],
|
|
389
|
+
options?: { readonly signal?: AbortSignal },
|
|
390
|
+
): Promise<readonly Record<string, unknown>[]>;
|
|
391
|
+
transaction<T>(work: (session: PostgresSession) => Promise<T>): Promise<T>;
|
|
392
|
+
};
|
|
393
|
+
export class PostgresCheckpointStore implements CheckpointStore<
|
|
394
|
+
(session: PostgresSession) => Promise<void>
|
|
395
|
+
> {
|
|
396
|
+
constructor(options: {
|
|
397
|
+
readonly session: PostgresSession;
|
|
398
|
+
readonly schema?: string;
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// @zukhruf/checkpoint/sqlserver
|
|
403
|
+
export type SqlServerSession = {
|
|
404
|
+
query(
|
|
405
|
+
sql: string,
|
|
406
|
+
parameters: Readonly<Record<string, unknown>>,
|
|
407
|
+
options?: { readonly signal?: AbortSignal },
|
|
408
|
+
): Promise<readonly Record<string, unknown>[]>;
|
|
409
|
+
transaction<T>(work: (session: SqlServerSession) => Promise<T>): Promise<T>;
|
|
410
|
+
};
|
|
411
|
+
export class SqlServerCheckpointStore implements CheckpointStore<
|
|
412
|
+
(session: SqlServerSession) => Promise<void>
|
|
413
|
+
> {
|
|
414
|
+
constructor(options: {
|
|
415
|
+
readonly session: SqlServerSession;
|
|
416
|
+
readonly schema?: string;
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
## Documentation
|
|
422
|
+
|
|
423
|
+
**Decisions**
|
|
424
|
+
|
|
425
|
+
- [ADR 0001](./docs/adr/0001-the-package-keeps-the-progress-of-a-reader-of-a-stream-and-the-checkpoint-stores-of-elt-and-the-position-of-sqlite-changefeed-move-into-it.md): the package keeps the progress of a reader of a stream, and the checkpoint stores of elt and the position of sqlite-changefeed move into it.
|
|
426
|
+
- [ADR 0002](./docs/adr/0002-the-package-is-zukhruf-checkpoint-and-the-sqlite-sense-of-the-word-is-a-wal-checkpoint.md): the package is `@zukhruf/checkpoint`, and the SQLite sense of the word is a WAL checkpoint.
|
|
427
|
+
- [ADR 0003](./docs/adr/0003-a-checkpoint-belongs-to-a-consumer-group-a-stream-and-a-partition-and-an-input-with-a-new-identity-has-a-new-checkpoint.md): a checkpoint belongs to a consumer group, a stream and a partition, and an input with a new identity has a new checkpoint.
|
|
428
|
+
- [ADR 0004](./docs/adr/0004-a-position-is-an-opaque-json-value-with-a-format-version-and-it-names-the-next-record-to-read.md): a position is an opaque JSON value with a format version, and it names the next record to read.
|
|
429
|
+
- [ADR 0005](./docs/adr/0005-a-claim-gives-the-saved-checkpoint-or-none-and-the-reader-picks-its-start-when-it-has-none.md): a claim gives the saved checkpoint or none, and the reader picks its start when it has none.
|
|
430
|
+
- [ADR 0006](./docs/adr/0006-keyed-state-is-a-set-of-named-map-states-and-a-commit-writes-only-what-changed.md): keyed state is a set of named map states, and a commit writes only what changed.
|
|
431
|
+
- [ADR 0007](./docs/adr/0007-a-commit-saves-the-position-the-state-changes-and-the-next-checkpoint-id-together-and-can-write-the-output-in-the-same-transaction.md): a commit saves the position, the state changes and the next checkpoint id together, and can write the output in the same transaction.
|
|
432
|
+
- [ADR 0008](./docs/adr/0008-a-newer-claim-fences-an-older-one-and-a-commit-of-a-fenced-claim-throws-and-writes-nothing.md): a newer claim fences an older one, and a commit of a fenced claim throws and writes nothing.
|
|
433
|
+
- [ADR 0009](./docs/adr/0009-a-consumer-group-lists-and-resets-its-checkpoints-and-a-reset-fences-the-live-owner.md): a consumer group lists and resets its checkpoints, and a reset fences the live owner.
|
|
434
|
+
- [ADR 0010](./docs/adr/0010-a-tracker-gives-the-highest-position-below-which-every-record-is-done.md): a tracker gives the highest position below which every record is done.
|
|
435
|
+
- [ADR 0011](./docs/adr/0011-the-package-has-a-memory-store-and-stores-for-sqlite-postgres-and-sql-server-and-a-host-can-write-its-own.md): the package has a memory store and stores for SQLite, Postgres and SQL Server, and a host can write its own.
|
|
436
|
+
- [ADR 0012](./docs/adr/0012-the-package-owns-three-error-classes-one-for-each-next-step.md): the package owns three error classes, one for each next step.
|
|
437
|
+
- [ADR 0013](./docs/adr/0013-the-package-is-in-the-base-layer.md): the package is in the base layer.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FencingToken } from '@zukhruf/fencing';
|
|
2
|
+
import type { CheckpointKey, CheckpointSummary, SignalOption, StateChanges, StoredCheckpoint, StoredValue } from './checkpoint.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Where checkpoints are kept (ADR 0011). `ConsumerGroup` is the only caller.
|
|
5
|
+
* `W` is the type of the `write` that a commit runs in its transaction.
|
|
6
|
+
*/
|
|
7
|
+
export interface CheckpointStore<W> {
|
|
8
|
+
/** Raises the epoch of the key in one atomic write, and gives it. */
|
|
9
|
+
claim(key: CheckpointKey, options?: SignalOption): Promise<FencingToken>;
|
|
10
|
+
read(key: CheckpointKey, options?: SignalOption): Promise<StoredCheckpoint | undefined>;
|
|
11
|
+
get(key: CheckpointKey, state: string, keys: readonly string[], options?: SignalOption): Promise<ReadonlyMap<string, StoredValue>>;
|
|
12
|
+
scan(key: CheckpointKey, state: string, options?: SignalOption): AsyncIterable<readonly [string, StoredValue]>;
|
|
13
|
+
/**
|
|
14
|
+
* In one transaction: checks that the stored epoch is `epoch`, else throws
|
|
15
|
+
* `CheckpointFencedError` and writes nothing; runs `write`; writes the
|
|
16
|
+
* checkpoint and the changes.
|
|
17
|
+
*/
|
|
18
|
+
commit(key: CheckpointKey, epoch: FencingToken, checkpoint: StoredCheckpoint, changes: StateChanges, options?: SignalOption & {
|
|
19
|
+
readonly write?: W;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
/** The partitions of the group that have a checkpoint. */
|
|
22
|
+
list(consumerGroup: string, options?: SignalOption & {
|
|
23
|
+
readonly stream?: string;
|
|
24
|
+
}): AsyncIterable<CheckpointSummary>;
|
|
25
|
+
/**
|
|
26
|
+
* Removes the checkpoint and the map states of one partition, or of each
|
|
27
|
+
* partition of a stream, and raises the epoch of each key it removes.
|
|
28
|
+
*/
|
|
29
|
+
reset(consumerGroup: string, target: {
|
|
30
|
+
readonly stream: string;
|
|
31
|
+
readonly partition?: string;
|
|
32
|
+
}, options?: SignalOption): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=checkpoint-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint-store.d.ts","sourceRoot":"","sources":["../src/checkpoint-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,qEAAqE;IACrE,KAAK,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACzE,IAAI,CACF,GAAG,EAAE,aAAa,EAClB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IACzC,GAAG,CACD,GAAG,EAAE,aAAa,EAClB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAC7C,IAAI,CACF,GAAG,EAAE,aAAa,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,YAAY,GACrB,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IACjD;;;;OAIG;IACH,MAAM,CACJ,GAAG,EAAE,aAAa,EAClB,KAAK,EAAE,YAAY,EACnB,UAAU,EAAE,gBAAgB,EAC5B,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,YAAY,GAAG;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KAAE,GAC9C,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,0DAA0D;IAC1D,IAAI,CACF,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,YAAY,GAAG;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACpD,aAAa,CAAC,iBAAiB,CAAC,CAAC;IACpC;;;OAGG;IACH,KAAK,CACH,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,EAChE,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint-store.js","sourceRoot":"","sources":["../src/checkpoint-store.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { FencingToken } from '@zukhruf/fencing';
|
|
2
|
+
/** A value that JSON can hold. */
|
|
3
|
+
export type Json = null | boolean | number | string | readonly Json[] | {
|
|
4
|
+
readonly [key: string]: Json;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* How a value is written as JSON and read back, after Flink's
|
|
8
|
+
* `SimpleVersionedSerializer` (ADR 0004). A commit writes `version` beside the
|
|
9
|
+
* JSON, and a read gives the stored version to `decode`.
|
|
10
|
+
*/
|
|
11
|
+
export type Format<T> = {
|
|
12
|
+
readonly version: number;
|
|
13
|
+
encode(value: T): Json;
|
|
14
|
+
/** Reads a value that `version` wrote. Throws when it cannot. */
|
|
15
|
+
decode(version: number, json: Json): T;
|
|
16
|
+
};
|
|
17
|
+
/** A stream and one of its partitions (ADR 0003). */
|
|
18
|
+
export type StreamPartition = {
|
|
19
|
+
readonly stream: string;
|
|
20
|
+
readonly partition: string;
|
|
21
|
+
};
|
|
22
|
+
/** The consumer group, the stream and the partition of one checkpoint. */
|
|
23
|
+
export type CheckpointKey = StreamPartition & {
|
|
24
|
+
readonly consumerGroup: string;
|
|
25
|
+
};
|
|
26
|
+
/** The saved progress of one partition (ADR 0005). */
|
|
27
|
+
export type Checkpoint<P> = {
|
|
28
|
+
readonly position: P;
|
|
29
|
+
/** 1 at the first commit of the partition, one more at each commit. */
|
|
30
|
+
readonly checkpointId: number;
|
|
31
|
+
};
|
|
32
|
+
/** A value as a store keeps it: the JSON and the version of its format. */
|
|
33
|
+
export type StoredValue = {
|
|
34
|
+
readonly version: number;
|
|
35
|
+
readonly json: Json;
|
|
36
|
+
};
|
|
37
|
+
/** A checkpoint as a store keeps it. */
|
|
38
|
+
export type StoredCheckpoint = StoredValue & {
|
|
39
|
+
readonly checkpointId: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The changes of the map states of one commit, by state name (ADR 0006). A
|
|
43
|
+
* store applies `cleared` first, then `deleted`, then `set`.
|
|
44
|
+
*/
|
|
45
|
+
export type StateChanges = {
|
|
46
|
+
readonly cleared: ReadonlySet<string>;
|
|
47
|
+
readonly deleted: ReadonlyMap<string, ReadonlySet<string>>;
|
|
48
|
+
readonly set: ReadonlyMap<string, ReadonlyMap<string, StoredValue>>;
|
|
49
|
+
};
|
|
50
|
+
/** One partition of `list`: no position and no state (ADR 0009). */
|
|
51
|
+
export type CheckpointSummary = {
|
|
52
|
+
readonly stream: string;
|
|
53
|
+
readonly partition: string;
|
|
54
|
+
readonly checkpointId: number;
|
|
55
|
+
readonly epoch: FencingToken;
|
|
56
|
+
};
|
|
57
|
+
export type SignalOption = {
|
|
58
|
+
readonly signal?: AbortSignal;
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=checkpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint.d.ts","sourceRoot":"","sources":["../src/checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,kCAAkC;AAClC,MAAM,MAAM,IAAI,GACZ,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,SAAS,IAAI,EAAE,GACf;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACvB,iEAAiE;IACjE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC;CACxC,CAAC;AAEF,qDAAqD;AACrD,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG;IAC5C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,sDAAsD;AACtD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC1B,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IACrB,uEAAuE;IACvE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG;IAC3C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;CACrE,CAAC;AAEF,oEAAoE;AACpE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../src/checkpoint.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CheckpointStore } from './checkpoint-store.ts';
|
|
2
|
+
import type { CheckpointSummary, Format, SignalOption, StreamPartition } from './checkpoint.ts';
|
|
3
|
+
import { PartitionContext } from './partition-context.ts';
|
|
4
|
+
/**
|
|
5
|
+
* One reader of a stream, by name, as Kafka's `group.id` (ADR 0003). It claims
|
|
6
|
+
* partitions, and it lists and resets their checkpoints.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ConsumerGroup<W> {
|
|
9
|
+
#private;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
constructor(name: string, store: CheckpointStore<W>);
|
|
12
|
+
/**
|
|
13
|
+
* Takes the partition with a new epoch, which fences each older claim, and
|
|
14
|
+
* reads its checkpoint (ADRs 0005 and 0008).
|
|
15
|
+
*/
|
|
16
|
+
claim<P>(partition: StreamPartition, format: Format<P>, options?: SignalOption): Promise<PartitionContext<P, W>>;
|
|
17
|
+
/** The partitions of this group that have a checkpoint (ADR 0009). */
|
|
18
|
+
list(options?: SignalOption & {
|
|
19
|
+
readonly stream?: string;
|
|
20
|
+
}): AsyncIterable<CheckpointSummary>;
|
|
21
|
+
/**
|
|
22
|
+
* Removes the checkpoint and the map states of one partition, or of each
|
|
23
|
+
* partition of a stream, and fences their live owners (ADR 0009).
|
|
24
|
+
*/
|
|
25
|
+
reset(target: {
|
|
26
|
+
readonly stream: string;
|
|
27
|
+
readonly partition?: string;
|
|
28
|
+
}, options?: SignalOption): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=consumer-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer-group.d.ts","sourceRoot":"","sources":["../src/consumer-group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAEV,iBAAiB,EACjB,MAAM,EACN,YAAY,EAEZ,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;;GAGG;AACH,qBAAa,aAAa,CAAC,CAAC;;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAGtB,YAAY,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EAGlD;IAED;;;OAGG;IACG,KAAK,CAAC,CAAC,EACX,SAAS,EAAE,eAAe,EAC1B,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAqBjC;IAED,sEAAsE;IAC/D,IAAI,CACT,OAAO,CAAC,EAAE,YAAY,GAAG;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACpD,aAAa,CAAC,iBAAiB,CAAC,CAGlC;IAED;;;OAGG;IACG,KAAK,CACT,MAAM,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,EAChE,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,IAAI,CAAC,CAGf;CACF"}
|