Andras Banki-Horvath
3 years ago
3 changed files with 55 additions and 0 deletions
@ -0,0 +1,26 @@ |
|||||||
|
package cluster |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
) |
||||||
|
|
||||||
|
const ( |
||||||
|
// EtcdLeaderElector is the id used when constructing an
|
||||||
|
// etcdLeaderElector instance through the factory.
|
||||||
|
EtcdLeaderElector = "etcd" |
||||||
|
) |
||||||
|
|
||||||
|
// LeaderElector is a general interface implementing basic leader elections
|
||||||
|
// in a clustered environment.
|
||||||
|
type LeaderElector interface { |
||||||
|
// Campaign starts a run for leadership. Campaign will block until
|
||||||
|
// the caller is elected as the leader.
|
||||||
|
Campaign(ctx context.Context) error |
||||||
|
|
||||||
|
// Resign resigns from the leader role, allowing other election members
|
||||||
|
// to take on leadership.
|
||||||
|
Resign() error |
||||||
|
|
||||||
|
// Leader returns the leader value for the current election.
|
||||||
|
Leader(ctx context.Context) (string, error) |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
package cluster |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/btcsuite/btclog" |
||||||
|
"github.com/lightningnetwork/lnd/build" |
||||||
|
) |
||||||
|
|
||||||
|
// Subsystem defines the logging code for this subsystem.
|
||||||
|
const Subsystem = "CLUS" |
||||||
|
|
||||||
|
// log is a logger that is initialized with the btclog.Disabled logger.
|
||||||
|
var log btclog.Logger |
||||||
|
|
||||||
|
// The default amount of logging is none.
|
||||||
|
func init() { |
||||||
|
UseLogger(build.NewSubLogger(Subsystem, nil)) |
||||||
|
} |
||||||
|
|
||||||
|
// DisableLog disables all logging output.
|
||||||
|
func DisableLog() { |
||||||
|
UseLogger(btclog.Disabled) |
||||||
|
} |
||||||
|
|
||||||
|
// UseLogger uses a specified Logger to output package logging info.
|
||||||
|
func UseLogger(logger btclog.Logger) { |
||||||
|
log = logger |
||||||
|
} |
Loading…
Reference in new issue