-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.go
50 lines (42 loc) · 1.17 KB
/
info.go
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/lxd/lxd/db"
"github.com/lxc/lxd/lxd/node"
"github.com/lxc/lxd/shared"
"github.com/lxc/lxd/shared/logger"
)
// Load information about the dqlite node associated with this LXD member
// should have, such as its ID, address and role.
func loadInfo(database *db.Node, cert *shared.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 !shared.PathExists(dir) {
err := os.Mkdir(dir, 0750)
if err != nil {
return nil, err
}
}
return info, nil
}