forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
indexer: make event commit atomic and append only (MystenLabs#7524)
### problem and theory I found the event indexer's throughput will go down along with growth of event table, one reason is that today upon event commit, we do de-dup like below, which will be more and more expensive along with table growth ``` .on_conflict((transaction_digest, event_sequence)) .do_nothing() ``` the reason that we need this de-dup is that, we commit event and event logs in 2 steps (so not atomic), first commit events, second commit event log. However indexer itself can stop / crash in between, thus to avoid writing duplicate events to event table, we want to de-dup here. ### solution in this PR This PR merges the events and event_log table such that we only need one DB commit for events thus it is atomic, in that sense we do not have to count on DB de-dup and can do append only. This should help if not resolve the event throughput issue. ### Test - run indexer with local validator and make sure events can be populated - stop indexer, check DB and make sure that last event indeed has next cursor info - restart indexer and make sure that indexer can proceed with new events
- Loading branch information
Showing
8 changed files
with
118 additions
and
131 deletions.
There are no files selected for viewing
5 changes: 3 additions & 2 deletions
5
crates/sui-indexer/migrations/2022-11-18-220045_events/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
CREATE TABLE EVENTS ( | ||
id BIGSERIAL PRIMARY KEY, | ||
-- below 2 are from Event ID, tx_digest and event_seq | ||
transaction_digest VARCHAR(255), | ||
transaction_digest VARCHAR(255) NOT NULL, | ||
event_sequence BIGINT NOT NULL, | ||
event_time TIMESTAMP, | ||
event_type VARCHAR NOT NULL, | ||
event_content VARCHAR NOT NULL, | ||
UNIQUE (transaction_digest, event_sequence) | ||
next_cursor_transaction_digest VARCHAR(255), | ||
next_cursor_event_sequence BIGINT | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
DROP TABLE event_logs; | ||
DROP TABLE transaction_logs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,7 @@ | ||
CREATE TABLE event_logs ( | ||
id SERIAL PRIMARY KEY, | ||
next_cursor_tx_dig TEXT, | ||
next_cursor_event_seq BIGINT | ||
); | ||
|
||
CREATE TABLE transaction_logs ( | ||
id SERIAL PRIMARY KEY, | ||
next_cursor_tx_digest TEXT | ||
); | ||
|
||
INSERT INTO event_logs (id, next_cursor_tx_dig, next_cursor_event_seq) VALUES | ||
(1, NULL, NULL); | ||
|
||
INSERT INTO transaction_logs (id, next_cursor_tx_digest) VALUES | ||
(1, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters