mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-11-10 14:44:04 +08:00
A node cut off from its database only showed in the logs. The health check loop now always
runs and pings the primary too; ntfy_db_up (1/0, per pool, next to ntfy_db_pool_*) is the
result of the last check, so an alert can fire on ntfy_db_up{role="primary"} == 0.
40 lines
966 B
Go
40 lines
966 B
Go
package db
|
|
|
|
import (
|
|
"database/sql"
|
|
"sync/atomic"
|
|
)
|
|
|
|
// Beginner is an interface for types that can begin a database transaction.
|
|
// Both *sql.DB and *DB implement this.
|
|
type Beginner interface {
|
|
Begin() (*sql.Tx, error)
|
|
}
|
|
|
|
// Querier is an interface for types that can execute SQL queries.
|
|
// *sql.DB, *sql.Tx, and *DB all implement this.
|
|
type Querier interface {
|
|
Query(query string, args ...any) (*sql.Rows, error)
|
|
}
|
|
|
|
// Host pairs a *sql.DB with the host:port it was opened against.
|
|
type Host struct {
|
|
Addr string // "host:port"
|
|
DB *sql.DB
|
|
healthy atomic.Bool
|
|
}
|
|
|
|
// Roles of a connection pool, see PoolStats
|
|
const (
|
|
PoolRolePrimary = "primary"
|
|
PoolRoleReplica = "replica"
|
|
)
|
|
|
|
// PoolStats is one connection pool's statistics: the primary's or a replica's
|
|
type PoolStats struct {
|
|
Role string // PoolRolePrimary or PoolRoleReplica
|
|
Addr string // "host:port"
|
|
Healthy bool // The last health check (a ping) succeeded
|
|
Stats sql.DBStats
|
|
}
|