Skip to content

Commit

Permalink
lxd: Apply DB triggers on start up if we are the leader.
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Laing <mark.laing@canonical.com>
  • Loading branch information
markylaing committed Mar 1, 2024
1 parent c882a8c commit a15cb04
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lxd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,21 @@ func (d *Daemon) init() error {

d.gateway.Cluster = d.db.Cluster

// Check if we are the database leader. If we are, apply database triggers on start up.
isLeader, err := isDQLiteLeader(d)
if err != nil {
return fmt.Errorf("Failed to check raft leader status: %w", err)
}

if isLeader {
err := d.db.Cluster.Transaction(d.shutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
return dbCluster.ApplyTriggers(ctx, tx.Tx())
})
if err != nil {
return fmt.Errorf("Failed to prepare cluster database triggers: %w", err)
}
}

// This logic used to belong to patchUpdateFromV10, but has been moved
// here because it needs database access.
if shared.PathExists(shared.VarPath("lxc")) {
Expand Down

0 comments on commit a15cb04

Please sign in to comment.