1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
package cluster
import (
"context"
"os"
"path/filepath"
"github.com/lxc/incus/v6/internal/server/db"
"github.com/lxc/incus/v6/internal/server/node"
"github.com/lxc/incus/v6/shared/logger"
localtls "github.com/lxc/incus/v6/shared/tls"
"github.com/lxc/incus/v6/shared/util"
)
// Load information about the dqlite node associated with this cluster member.
func loadInfo(database *db.Node, cert *localtls.CertInfo) (*db.RaftNode, error) {
// Figure out if we actually need to act as dqlite node.
var info *db.RaftNode
err := database.Transaction(context.TODO(), func(ctx context.Context, tx *db.NodeTx) error {
var err error
info, err = node.DetermineRaftNode(ctx, tx)
return err
})
if err != nil {
return nil, err
}
// If we're not part of the dqlite cluster, there's nothing to do.
if info == nil {
return nil, nil
}
if info.Address == "" {
// This is a standalone node not exposed to the network.
info.Address = "1"
}
logger.Info("Starting database node", logger.Ctx{"id": info.ID, "local": info.Address, "role": info.Role})
// Data directory
dir := filepath.Join(database.Dir(), "global")
if !util.PathExists(dir) {
err := os.Mkdir(dir, 0o750)
if err != nil {
return nil, err
}
}
return info, nil
}
|