db

package
v0.0.0-...-67f9e1d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2024 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultHeartbeatInterval is the default interval used for heartbeats and dqlite role probes.
	DefaultHeartbeatInterval time.Duration = time.Second * 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	// Transaction handles performing a transaction on the dqlite database.
	Transaction(outerCtx context.Context, f func(context.Context, *sql.Tx) error) error

	// Leader returns a client connected to the leader of the dqlite cluster.
	Leader(ctx context.Context) (*dqliteClient.Client, error)

	// Cluster returns information about dqlite cluster members.
	Cluster(ctx context.Context, client *dqliteClient.Client) ([]dqliteClient.NodeInfo, error)

	// Status returns the current status of the database.
	Status() types.DatabaseStatus

	// IsOpen returns nil  only if the DB has been opened and the schema loaded.
	// Otherwise, it returns an error describing why the database is offline.
	// The returned error may have the http status 503, indicating that the database is in a valid but unavailable state.
	IsOpen(ctx context.Context) error

	// SchemaVersion returns the current internal and external schema version, as well as all API extensions in memory.
	SchemaVersion() (versionInternal uint64, versionExternal uint64, apiExtensions extensions.Extensions)
}

DB exposes the internal database for use with external projects.

type DqliteDB

type DqliteDB struct {
	// contains filtered or unexported fields
}

DqliteDB holds all information internal to the dqlite database.

func NewDB

func NewDB(ctx context.Context, serverCert func() *shared.CertInfo, clusterCert func() *shared.CertInfo, memberName func() string, os *sys.OS, heartbeatInterval time.Duration) *DqliteDB

NewDB creates an empty db struct with no dqlite connection.

func (*DqliteDB) Accept

func (db *DqliteDB) Accept(conn net.Conn)

Accept sends the outbound connection through the acceptCh channel to be received by dqlite.

func (*DqliteDB) Bootstrap

func (db *DqliteDB) Bootstrap(extensions extensions.Extensions, project string, addr api.URL, clusterRecord cluster.CoreClusterMember) error

Bootstrap dqlite.

func (*DqliteDB) Cluster

func (db *DqliteDB) Cluster(ctx context.Context, client *dqliteClient.Client) ([]dqliteClient.NodeInfo, error)

Cluster returns information about dqlite cluster members.

func (*DqliteDB) GetHeartbeatInterval

func (db *DqliteDB) GetHeartbeatInterval() time.Duration

GetHeartbeatInterval returns the current database heartbeat interval.

func (*DqliteDB) IsOpen

func (db *DqliteDB) IsOpen(ctx context.Context) error

IsOpen returns nil only if the DB has been opened and the schema loaded. Otherwise, it returns an error describing why the database is offline. The returned error may have the http status 503, indicating that the database is in a valid but unavailable state.

func (*DqliteDB) Join

func (db *DqliteDB) Join(extensions extensions.Extensions, project string, addr api.URL, joinAddresses ...string) error

Join a dqlite cluster with the address of a member.

func (*DqliteDB) Leader

func (db *DqliteDB) Leader(ctx context.Context) (*dqliteClient.Client, error)

Leader returns a client connected to the leader of the dqlite cluster.

func (*DqliteDB) NotifyUpgraded

func (db *DqliteDB) NotifyUpgraded()

NotifyUpgraded sends a notification that we can stop waiting for a cluster member to be upgraded.

func (*DqliteDB) Open

func (db *DqliteDB) Open(ext extensions.Extensions, bootstrap bool, project string) error

Open opens the dqlite database and loads the schema. Returns true if we need to wait for other nodes to catch up to our version.

func (*DqliteDB) Schema

func (db *DqliteDB) Schema() *update.SchemaUpdate

Schema returns the update.SchemaUpdate for the DB.

func (*DqliteDB) SchemaVersion

func (db *DqliteDB) SchemaVersion() (versionInternal uint64, versionExternal uint64, apiExtensions extensions.Extensions)

SchemaVersion returns the current internal and external schema version, as well as all API extensions in memory.

func (*DqliteDB) SendHeartbeat

func (db *DqliteDB) SendHeartbeat(ctx context.Context, c *internalClient.Client, hbInfo internalTypes.HeartbeatInfo) error

SendHeartbeat initiates a new heartbeat sequence if this is a leader node.

func (*DqliteDB) SetSchema

func (db *DqliteDB) SetSchema(schemaExtensions []schema.Update, apiExtensions extensions.Extensions)

SetSchema sets schema and API extensions on the DB.

func (*DqliteDB) StartWithCluster

func (db *DqliteDB) StartWithCluster(extensions extensions.Extensions, project string, addr api.URL, clusterMembers map[string]types.AddrPort) error

StartWithCluster starts up dqlite and joins the cluster.

func (*DqliteDB) Status

func (db *DqliteDB) Status() types.DatabaseStatus

Status returns the current status of the database.

func (*DqliteDB) Stop

func (db *DqliteDB) Stop() error

Stop closes the database and dqlite connection.

func (*DqliteDB) Transaction

func (db *DqliteDB) Transaction(outerCtx context.Context, f func(context.Context, *sql.Tx) error) error

Transaction handles performing a transaction on the dqlite database.

func (*DqliteDB) Update

func (db *DqliteDB) Update() error

Update attempts to update the database with the executable at the path specified by the SCHEMA_UPDATE variable.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL