lxd/cluster/raft.go
func newRaft(database *db.Node, cert *shared.CertInfo, latency float64) (*raftInstance, error) {
	if latency <= 0 {
		return nil, fmt.Errorf("latency should be positive")
	}

	// Figure out if we actually need to act as dqlite node.
	var info *db.RaftNode
	err := database.Transaction(func(tx *db.NodeTx) error {
		var err error
		info, err = node.DetermineRaftNode(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
	}
	logger.Debug("Start database node", log15.Ctx{"id": info.ID, "address": info.Address})

	// Initialize a raft instance along with all needed dependencies.
	instance, err := raftInstanceInit(database, info, cert, latency)
	if err != nil {
		return nil, err
	}

	return instance, nil
}
func newRaft(database *db.Node, cert *shared.CertInfo, latency float64) (*raftInstance, error) {
	if latency <= 0 {
		return nil, fmt.Errorf("latency should be positive")
	}

	// Figure out if we actually need to act as dqlite node.
	var info *db.RaftNode
	err := database.Transaction(func(tx *db.NodeTx) error {
		var err error
		info, err = node.DetermineRaftNode(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
	}
	logger.Debug("Start database node", log15.Ctx{"id": info.ID, "address": info.Address})

	// Initialize a raft instance along with all needed dependencies.
	instance, err := raftInstanceInit(database, info, cert, latency)
	if err != nil {
		return nil, err
	}

	return instance, nil
}
// Create a raft instance and all its dependencies, to be used as backend for
// the dqlite driver running on this LXD node.
//
// If this node should not serve as dqlite node, nil is returned.
//
// The raft instance will use an in-memory transport if clustering is not
// enabled on this node.
//
// The certInfo parameter should contain the cluster TLS keypair and optional
// CA certificate.
//
// The latency parameter is a coarse grain measure of how fast/reliable network
// links are. This is used to tweak the various timeouts parameters of the raft
// algorithm. See the raft.Config structure for more details. A value of 1.0
// means use the default values from hashicorp's raft package. Values closer to
// 0 reduce the values of the various timeouts (useful when running unit tests
// in-memory).