Merge ~cjwatson/launchpad:db-kafka-offset into launchpad:db-devel

Proposed by Colin Watson
Status: Needs review
Proposed branch: ~cjwatson/launchpad:db-kafka-offset
Merge into: launchpad:db-devel
Diff against target: 22 lines (+16/-0)
1 file modified
database/schema/patch-2211-18-0.sql (+16/-0)
Reviewer Review Type Date Requested Status
Ines Almeida Approve
William Grant db Pending
Launchpad code reviewers db Pending
Review via email: mp+438771@code.launchpad.net

Commit message

Add KafkaOffset table

Description of the change

In order to consume events from Kafka, we'll need a way to keep track of our position in any given event stream. This is tracked by topic name and partition (with the number of partitions depending on the number of parallel consumers of any given topic). Updating a table of (topic, partition, offset) in the same transaction as we handle whatever else we need to do for that event gives us exactly-once event delivery, and seems to integrate quite nicely into the rest of Launchpad.

To post a comment you must log in.
Revision history for this message
Ines Almeida (ines-almeida) wrote :

LGTM

review: Approve

Unmerged commits

ee8a49c... by Colin Watson

Add KafkaOffset table

In order to consume events from Kafka, we'll need a way to keep track of
our position in any given event stream. This is tracked by topic name
and partition (with the number of partitions depending on the number of
parallel consumers of any given topic). Updating a table of (topic,
partition, offset) in the same transaction as we handle whatever else we
need to do for that event gives us exactly-once event delivery, and
seems to integrate quite nicely into the rest of Launchpad.

Succeeded
[SUCCEEDED] docs:0 (build)
[SUCCEEDED] lint:0 (build)
[SUCCEEDED] mypy:0 (build)
13 of 3 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/database/schema/patch-2211-18-0.sql b/database/schema/patch-2211-18-0.sql
2new file mode 100644
3index 0000000..c0c5e5d
4--- /dev/null
5+++ b/database/schema/patch-2211-18-0.sql
6@@ -0,0 +1,16 @@
7+-- Copyright 2023 Canonical Ltd. This software is licensed under the
8+-- GNU Affero General Public License version 3 (see the file LICENSE).
9+
10+SET client_min_messages=ERROR;
11+
12+CREATE TABLE KafkaOffset (
13+ id serial PRIMARY KEY,
14+ topic text NOT NULL,
15+ partition integer NOT NULL,
16+ stored_offset integer NOT NULL
17+);
18+
19+CREATE UNIQUE INDEX kafkaoffset__topic__partition__key
20+ ON KafkaOffset (topic, partition);
21+
22+INSERT INTO LaunchpadDatabaseRevision VALUES (2211, 18, 0);

Subscribers

People subscribed via source and target branches

to status/vote changes: