-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Central slot collecting function for UI and monitoring (#771)
## Keeping Track Of The WAL <img width="1067" alt="Screenshot 2023-12-07 at 7 54 39 PM" src="https://github.com/PeerDB-io/peerdb/assets/65964360/fe9e94ff-c141-43ec-b063-cd334c584541"> This PR does the following: 1. Moves the API function which queries `pg_replication_slots` to a PullConnector function for Postgres (in `client.go`). 2. Introduces a table - `peer_slot_size` in catalog, and a function in `monitoring.go` to upsert data into this table. 3. The API function for UI to get slot changes now calls the Postgres function for the same. 4. In `StartFlow` in `flowable.go`, we call the same GetSlot function and put it's results into the `peer_slot_size` table in catalog. Here, we store the slot information **once every 10 minutes or at the end of every sync flow - whichever comes first**. ### What is stored ? - Slot name - Peer name - Redo LSN - Restart LSN - Confirmed Flush LSN - Size of slot AKA Lag - Timestamp of recording ### Lag calculation Lag is now calculated (in MB) as: ```sql round(pg_current_wal_lsn() - confirmed_flush_lsn) -- (divided by 1024 couple of times) ``` **What are those terms ?** `pg_current_wal_lsn()` is the current LSN the WAL is at. `confirmed_flush_lsn` is where the client has told Postgres that it has read till. so our "lag" is the difference between where the WAL is vs where we are at as PeerDB reading the WAL.
- Loading branch information
1 parent
d9b152a
commit 92e50b3
Showing
11 changed files
with
201 additions
and
38 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE IF NOT EXISTS peerdb_stats.peer_slot_size ( | ||
id SERIAL PRIMARY KEY, | ||
slot_name TEXT NOT NULL, | ||
peer_name TEXT NOT NULL, | ||
redo_lsn TEXT, | ||
restart_lsn TEXT, | ||
confirmed_flush_lsn TEXT, | ||
slot_size BIGINT, | ||
updated_at TIMESTAMP NOT NULL DEFAULT NOW() | ||
); | ||
|
||
CREATE INDEX index_slot_name ON peerdb_stats.peer_slot_size (slot_name); |
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
Oops, something went wrong.