Skip to content

Commit

Permalink
wal heartbeat: allow overriding query with env variable (#1725)
Browse files Browse the repository at this point in the history
To enable heartbeating, set these two environment vars:

```yaml
  PEERDB_WAL_HEARTBEAT_QUERY: ${PEERDB_WAL_HEARTBEAT_QUERY:-UPDATE _peerdb_heartbeat SET last_heartbeat = now() WHERE id = 1;}
  PEERDB_ENABLE_WAL_HEARTBEAT: ${PEERDB_ENABLE_WAL_HEARTBEAT:-true}
```
  • Loading branch information
serprex authored May 27, 2024
1 parent b063b61 commit 3485158
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 1 addition & 7 deletions flow/activities/flowable.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,7 @@ func (a *FlowableActivity) SendWALHeartbeat(ctx context.Context) error {
return err
}

command := `
BEGIN;
DROP AGGREGATE IF EXISTS PEERDB_EPHEMERAL_HEARTBEAT(float4);
CREATE AGGREGATE PEERDB_EPHEMERAL_HEARTBEAT(float4) (SFUNC = float4pl, STYPE = float4);
DROP AGGREGATE PEERDB_EPHEMERAL_HEARTBEAT(float4);
END;
`
command := peerdbenv.PeerDBWALHeartbeatQuery()
// run above command for each Postgres peer
for _, pgPeer := range pgPeers {
activity.RecordHeartbeat(ctx, pgPeer.Name)
Expand Down
9 changes: 9 additions & 0 deletions flow/peerdbenv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ func PeerDBEnableWALHeartbeat() bool {
return getEnvBool("PEERDB_ENABLE_WAL_HEARTBEAT", false)
}

// PEERDB_WAL_HEARTBEAT_QUERY
func PeerDBWALHeartbeatQuery() string {
return GetEnvString("PEERDB_WAL_HEARTBEAT_QUERY", `BEGIN;
DROP AGGREGATE IF EXISTS PEERDB_EPHEMERAL_HEARTBEAT(float4);
CREATE AGGREGATE PEERDB_EPHEMERAL_HEARTBEAT(float4) (SFUNC = float4pl, STYPE = float4);
DROP AGGREGATE PEERDB_EPHEMERAL_HEARTBEAT(float4);
END;`)
}

// PEERDB_ENABLE_PARALLEL_SYNC_NORMALIZE
func PeerDBEnableParallelSyncNormalize() bool {
return getEnvBool("PEERDB_ENABLE_PARALLEL_SYNC_NORMALIZE", false)
Expand Down

0 comments on commit 3485158

Please sign in to comment.