Skip to content

Commit 4393537

Browse files
committed
1.0.0 release
1 parent 7fb655b commit 4393537

File tree

4 files changed

+60
-53
lines changed

4 files changed

+60
-53
lines changed

README.md

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,78 +12,79 @@ For proofs, see [benchmarks](/benchmarks/README.md).
1212

1313
## How it works
1414

15-
We just need to have a few tables (postgres syntax, schema managed fully by EventSQL):
16-
15+
We just need to have a few tables. Column names should be prefixed because some of the names are reserved keywords in some databases (Postgres syntax, schema is fully managed by EventSQL):
1716
```sql
1817
CREATE TABLE topic (
19-
name TEXT PRIMARY KEY,
20-
partitions SMALLINT NOT NULL,
21-
created_at TIMESTAMP NOT NULL DEFAULT NOW()
18+
eql_name TEXT PRIMARY KEY,
19+
eql_partitions SMALLINT NOT NULL,
20+
eql_created_at TIMESTAMP NOT NULL DEFAULT NOW()
2221
);
2322

2423
CREATE TABLE consumer (
25-
topic TEXT NOT NULL,
26-
name TEXT NOT NULL,
27-
partition SMALLINT NOT NULL,
28-
first_event_id BIGINT,
29-
last_event_id BIGINT,
30-
last_consumption_at TIMESTAMP,
31-
consumed_events BIGINT NOT NULL,
32-
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
33-
PRIMARY KEY (topic, name, partition)
24+
eql_topic TEXT NOT NULL,
25+
eql_name TEXT NOT NULL,
26+
eql_partition SMALLINT NOT NULL,
27+
eql_first_event_id BIGINT,
28+
eql_last_event_id BIGINT,
29+
eql_last_consumption_at TIMESTAMP,
30+
eql_consumed_events BIGINT NOT NULL,
31+
eql_created_at TIMESTAMP NOT NULL DEFAULT NOW(),
32+
PRIMARY KEY (eql_topic, eql_name, eql_partition)
3433
);
3534

3635
CREATE TABLE {topic}_event (
37-
id BIGSERIAL PRIMARY KEY,
38-
partition SMALLINT NOT NULL,
39-
key TEXT,
40-
value BYTEA NOT NULL,
41-
buffered_at TIMESTAMP NOT NULL,
42-
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
43-
metadata JSON NOT NULL
36+
eql_id BIGSERIAL PRIMARY KEY,
37+
eql_partition SMALLINT NOT NULL,
38+
eql_key TEXT,
39+
eql_value BYTEA NOT NULL,
40+
eql_buffered_at TIMESTAMP NOT NULL,
41+
eql_created_at TIMESTAMP NOT NULL DEFAULT NOW(),
42+
eql_metadata JSON NOT NULL
4443
);
4544

4645
-- Same schema as event, just not partitioned (by topic). --
4746
-- It is used to handle eventual consistency of auto increment; --
48-
-- there is no guarantee that record of id 2 is visible after id 1 record. --
47+
-- there is no guarantee that record of id 2 is visible only after id 1 record. --
4948
-- Events are first inserted to the event_buffer; --
50-
-- they are then moved to the {topic}_event table in bulk, by a single, serialized writer (per topic); --
51-
-- because there is only one writer, it fixes eventual consistency issue --
49+
-- they are then moved to the {topic}_event table in bulk, by a single, serialized writer (per topic). --
50+
-- Because there is only one writer, it fixes eventual consistency issue --
5251
CREATE TABLE event_buffer (
53-
id BIGSERIAL PRIMARY KEY,
54-
topic TEXT NOT NULL,
55-
partition SMALLINT NOT NULL,
56-
key TEXT,
57-
value BYTEA NOT NULL,
58-
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
59-
metadata JSON NOT NULL
52+
eql_id BIGSERIAL PRIMARY KEY,
53+
eql_topic TEXT NOT NULL,
54+
eql_partition SMALLINT NOT NULL,
55+
eql_key TEXT,
56+
eql_value BYTEA NOT NULL,
57+
eql_created_at TIMESTAMP NOT NULL DEFAULT NOW(),
58+
eql_metadata JSON NOT NULL
6059
);
61-
CREATE INDEX event_buffer_topic_id ON event_buffer (topic, id);
60+
CREATE INDEX event_buffer_topic_id ON event_buffer (eql_topic, eql_id);
6261
-- Used to lock single (per topic) event_buffer to {topic}_event writer --
6362
CREATE TABLE event_buffer_lock (
64-
topic TEXT PRIMARY KEY
63+
eql_topic TEXT PRIMARY KEY
6564
);
6665
```
6766

68-
To consume events, we just need to periodically (every one to a few seconds) do:
69-
67+
To consume events, we periodically do (every one to several seconds):
7068
```sql
7169
BEGIN;
7270

7371
SELECT * FROM consumer
74-
WHERE topic = :topic AND name = :c_name
72+
WHERE eql_topic = :topic
73+
AND eql_name = :c_name
7574
FOR UPDATE SKIP LOCKED;
7675

7776
SELECT * FROM {topic}_event
78-
WHERE (:last_event_id IS NULL OR id > :last_event_id)
79-
ORDER BY id LIMIT :limit;
77+
WHERE (:last_event_id IS NULL OR eql_id > :last_event_id)
78+
ORDER BY eql_id
79+
LIMIT :limit;
8080

8181
(process events)
8282

8383
UPDATE consumer
84-
SET last_event_id = :id,
85-
last_consumption_at = :now
86-
WHERE topic = :topic AND name = :c_name;
84+
SET eql_last_event_id = :id,
85+
eql_last_consumption_at = :now
86+
WHERE eql_topic = :topic
87+
AND eql_name = :c_name;
8788

8889
COMMIT;
8990
```
@@ -99,19 +100,25 @@ Consumption of such events per partition (0 in an example) might look like this:
99100
BEGIN;
100101

101102
SELECT * FROM consumer
102-
WHERE topic = :topic AND name = :c_name AND partition = 0
103+
WHERE eql_topic = :topic
104+
AND eql_name = :c_name
105+
AND eql_partition = 0
103106
FOR UPDATE SKIP LOCKED;
104107

105108
SELECT * FROM {topic}_event
106-
WHERE partition = 0 AND (:last_event_id IS NULL OR id > :last_event_id)
107-
ORDER BY id LIMIT :limit;
109+
WHERE (:last_event_id IS NULL OR eql_id > :last_event_id)
110+
AND eql_partition = 0
111+
ORDER BY eql_id
112+
LIMIT :limit;
108113

109114
(process events)
110115

111116
UPDATE consumer
112-
SET last_event_id = :id,
113-
last_consumption_at = :now
114-
WHERE topic = :topic AND name = :c_name AND partition = 0;
117+
SET eql_last_event_id = :id,
118+
eql_last_consumption_at = :now
119+
WHERE eql_topic = :topic
120+
AND eql_name = :c_name
121+
AND eql_partition = 0;
115122

116123
COMMIT;
117124
```
@@ -303,11 +310,11 @@ Maven:
303310
<dependency>
304311
<groupId>com.binaryigor</groupId>
305312
<artifactId>eventsql</artifactId>
306-
<version>0.0.1</version>
313+
<version>1.0.0</version>
307314
</dependency>
308315
```
309316
Gradle:
310317
```
311-
implementation 'com.binaryigor:eventsql:0.0.1'
312-
implementation("com.binaryigor:eventsql:0.0.1")
318+
implementation 'com.binaryigor:eventsql:1.0.0'
319+
implementation("com.binaryigor:eventsql:1.0.0")
313320
```

benchmarks/app/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>com.binaryigor</groupId>
3333
<artifactId>eventsql</artifactId>
34-
<version>0.0.1</version>
34+
<version>1.0.0</version>
3535
</dependency>
3636

3737
<dependency>

benchmarks/runner/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>com.binaryigor</groupId>
4646
<artifactId>eventsql</artifactId>
47-
<version>0.0.1</version>
47+
<version>1.0.0</version>
4848
</dependency>
4949
</dependencies>
5050

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.binaryigor</groupId>
88
<artifactId>eventsql</artifactId>
9-
<version>0.0.1</version>
9+
<version>1.0.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>EventSQL</name>

0 commit comments

Comments
 (0)