Skip to content

Commit c1d826f

Browse files
authored
Merge pull request #412 from Icinga/own-connections-for-ha-and-heartbeat
Use own connections for heartbeat and HA
2 parents 68943a6 + 8169239 commit c1d826f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cmd/icingadb/main.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,26 @@ func run() int {
9696
ctx, cancelCtx := context.WithCancel(context.Background())
9797
defer cancelCtx()
9898

99-
heartbeat := icingaredis.NewHeartbeat(ctx, rc, logs.GetChildLogger("heartbeat"))
100-
ha := icingadb.NewHA(ctx, db, heartbeat, logs.GetChildLogger("high-availability"))
99+
// Use dedicated connections for heartbeat and HA to ensure that heartbeats are always processed and
100+
// the instance table is updated. Otherwise, the connections can be too busy due to the synchronization of
101+
// configuration, status, history, etc., which can lead to handover / takeover loops because
102+
// the heartbeat is not read while HA gets stuck when updating the instance table.
103+
var heartbeat *icingaredis.Heartbeat
104+
var ha *icingadb.HA
105+
{
106+
rc, err := cmd.Redis(logs.GetChildLogger("redis"))
107+
if err != nil {
108+
logger.Fatalf("%+v", errors.Wrap(err, "can't create Redis client from config"))
109+
}
110+
heartbeat = icingaredis.NewHeartbeat(ctx, rc, logs.GetChildLogger("heartbeat"))
111+
112+
db, err := cmd.Database(logs.GetChildLogger("database"))
113+
if err != nil {
114+
logger.Fatalf("%+v", errors.Wrap(err, "can't create database connection pool from config"))
115+
}
116+
defer db.Close()
117+
ha = icingadb.NewHA(ctx, db, heartbeat, logs.GetChildLogger("high-availability"))
118+
}
101119
// Closing ha on exit ensures that this instance retracts its heartbeat
102120
// from the database so that another instance can take over immediately.
103121
defer func() {

0 commit comments

Comments
 (0)