Documentation
¶
Index ¶
- type Args
- type DaemonArgs
- type MicroCluster
- func (m *MicroCluster) GetClusterMembers(ctx context.Context) ([]types.ClusterMember, error)
- func (m *MicroCluster) GetDqliteClusterMembers() ([]types.DqliteMember, error)
- func (m *MicroCluster) JoinCluster(ctx context.Context, name string, address string, token string, ...) error
- func (m *MicroCluster) ListJoinTokens(ctx context.Context) ([]types.TokenRecord, error)
- func (m *MicroCluster) LocalClient() (types.Client, error)
- func (m *MicroCluster) LoggerFromContext(ctx context.Context) *slog.Logger
- func (m *MicroCluster) NewCluster(ctx context.Context, name string, address string, config map[string]string) error
- func (m *MicroCluster) NewJoinToken(ctx context.Context, name string, expireAfter time.Duration) (string, error)
- func (m *MicroCluster) Ready(ctx context.Context) error
- func (m *MicroCluster) RecoverFromQuorumLoss(members []types.DqliteMember) (string, error)
- func (m *MicroCluster) RemoteClient(address string) (types.Client, error)
- func (m *MicroCluster) RemoteClientWithCert(address string, cert *x509.Certificate) (types.Client, error)
- func (m *MicroCluster) RemoveClusterMember(ctx context.Context, name string, address string, force bool) error
- func (m *MicroCluster) RevokeJoinToken(ctx context.Context, name string) error
- func (m *MicroCluster) SQL(ctx context.Context, query string) (string, *types.SQLBatch, error)
- func (m *MicroCluster) Shutdown(ctx context.Context) error
- func (m *MicroCluster) Start(ctx context.Context, daemonArgs DaemonArgs) error
- func (m *MicroCluster) Status(ctx context.Context) (*types.Status, error)
- func (m *MicroCluster) UpdateCertificates(ctx context.Context, name types.CertificateName, args types.KeyPair) error
- func (m *MicroCluster) UpdateServers(ctx context.Context, config map[string]types.ServerConfig) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Args ¶
type Args struct {
StateDir string
// LogHandler can be used to pass a custom logging handler to Microcluster.
// The handler allows setting options like the log level and output.
// If none is provided a default handler is used.
LogHandler slog.Handler
Client types.Client
Proxy func(*http.Request) (*url.URL, error)
}
Args contains options for configuring MicroCluster.
type DaemonArgs ¶
DaemonArgs are the data needed to start a MicroCluster daemon.
type MicroCluster ¶
MicroCluster contains some basic filesystem information for interacting with the MicroCluster daemon.
func App ¶
func App(args Args) (*MicroCluster, error)
App returns an instance of MicroCluster with a newly initialized filesystem if one does not exist.
func (*MicroCluster) GetClusterMembers ¶
func (m *MicroCluster) GetClusterMembers(ctx context.Context) ([]types.ClusterMember, error)
GetClusterMembers returns a list of cluster members.
func (*MicroCluster) GetDqliteClusterMembers ¶
func (m *MicroCluster) GetDqliteClusterMembers() ([]types.DqliteMember, error)
GetDqliteClusterMembers retrieves the current local cluster configuration (derived from the trust store & dqlite metadata); it does not query the database. This is primarily intended for modifying the cluster configuration via MicroCluster.RecoverFromQuorumLoss.
func (*MicroCluster) JoinCluster ¶
func (m *MicroCluster) JoinCluster(ctx context.Context, name string, address string, token string, initConfig map[string]string) error
JoinCluster joins an existing cluster with a join token supplied by an existing cluster member.
func (*MicroCluster) ListJoinTokens ¶
func (m *MicroCluster) ListJoinTokens(ctx context.Context) ([]types.TokenRecord, error)
ListJoinTokens lists all the join tokens currently available for use.
func (*MicroCluster) LocalClient ¶
func (m *MicroCluster) LocalClient() (types.Client, error)
LocalClient returns a client connected to the local control socket.
func (*MicroCluster) LoggerFromContext ¶
func (m *MicroCluster) LoggerFromContext(ctx context.Context) *slog.Logger
LoggerFromContext returns a logger instance using the provided logging handler. A default handler is used if none is provided. If the context doesn't contain a logger, a new one is returned instead.
func (*MicroCluster) NewCluster ¶
func (m *MicroCluster) NewCluster(ctx context.Context, name string, address string, config map[string]string) error
NewCluster bootstrapps a brand new cluster with this daemon as its only member.
func (*MicroCluster) NewJoinToken ¶
func (m *MicroCluster) NewJoinToken(ctx context.Context, name string, expireAfter time.Duration) (string, error)
NewJoinToken creates and records a new join token containing all the necessary credentials for joining a cluster. Join tokens are tied to the server certificate of the joining node, and will be deleted once the node has joined the cluster.
func (*MicroCluster) Ready ¶
func (m *MicroCluster) Ready(ctx context.Context) error
Ready waits for the daemon to report it has finished initial setup and is ready to be bootstrapped or join an existing cluster.
func (*MicroCluster) RecoverFromQuorumLoss ¶
func (m *MicroCluster) RecoverFromQuorumLoss(members []types.DqliteMember) (string, error)
RecoverFromQuorumLoss can be used to recover database access when a quorum of members is lost and cannot be recovered (e.g. hardware failure). This function requires that:
- All cluster members' databases are not running
- The current member has the most up-to-date raft log (usually the member which was most recently the leader)
RecoverFromQuorumLoss will take a database backup before attempting the recovery operation.
RecoverFromQuorumLoss should be invoked _exactly once_ for the entire cluster. This function creates a gz-compressed tarball and returns its path. This tarball should be manually copied by the user to the state dir of all other cluster members.
On start, Microcluster will automatically check for & load the recovery tarball. A database backup will be taken before the load.
func (*MicroCluster) RemoteClient ¶
func (m *MicroCluster) RemoteClient(address string) (types.Client, error)
RemoteClient gets a client for the specified cluster member URL. The filesystem will be parsed for the cluster and server certificates.
func (*MicroCluster) RemoteClientWithCert ¶
func (m *MicroCluster) RemoteClientWithCert(address string, cert *x509.Certificate) (types.Client, error)
RemoteClientWithCert gets a client for the specified cluster member URL using the remote server cert. The filesystem will be parsed for the server client certificate.
func (*MicroCluster) RemoveClusterMember ¶
func (m *MicroCluster) RemoveClusterMember(ctx context.Context, name string, address string, force bool) error
RemoveClusterMember removes a member from the cluster. If `address` is non-empty it is sent as a query parameter to target dqlite removal by address when the truststore cannot map name to address. Dqlite does not track names, so this is useful when the name is no longer resolvable.
func (*MicroCluster) RevokeJoinToken ¶
func (m *MicroCluster) RevokeJoinToken(ctx context.Context, name string) error
RevokeJoinToken revokes the token record stored under the given name.
func (*MicroCluster) SQL ¶
SQL performs either a GET or POST on /internal/sql with a given query. This is a useful helper for using direct SQL.
func (*MicroCluster) Shutdown ¶
func (m *MicroCluster) Shutdown(ctx context.Context) error
Shutdown stops the local Microcluster daemon.
func (*MicroCluster) Start ¶
func (m *MicroCluster) Start(ctx context.Context, daemonArgs DaemonArgs) error
Start starts up a brand new MicroCluster daemon. Only the local control socket will be available at this stage, no database exists yet. Any api or schema extensions can be applied here. If daemonArgs.ShutdownSignals is provided, the daemon will automatically handle those signals for graceful shutdown. If nil, default signals (SIGPWR, SIGTERM, SIGINT, SIGQUIT) will be used for graceful shutdown. If set to an empty slice, no signal handling will be performed.
func (*MicroCluster) UpdateCertificates ¶
func (m *MicroCluster) UpdateCertificates(ctx context.Context, name types.CertificateName, args types.KeyPair) error
UpdateCertificates updates the named certificate of either the core or extension server.
func (*MicroCluster) UpdateServers ¶
func (m *MicroCluster) UpdateServers(ctx context.Context, config map[string]types.ServerConfig) error
UpdateServers updates the extension servers defined when starting the daemon.