dqlite

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DriverName is the default driver name for dqlite.
	DriverName = "dqlite"
)

Variables

View Source
var (
	ErrNoNativeApp = errors.New("dqlite: native app is not active")
)

Functions

func ClusterNodes

func ClusterNodes(ctx context.Context) ([]client.NodeInfo, error)

ClusterNodes returns the current list of nodes in the dqlite cluster.

func IsConnPoolPoisonedError

func IsConnPoolPoisonedError(err error) bool

IsConnPoolPoisonedError matches the narrow case where a pooled connection has been left with a stale active transaction. Distinct from IsContentionError, which also covers transient busy/locked errors that don't require active recovery (an explicit ROLLBACK on the pool to clear the leftover BEGIN).

func IsContentionError

func IsContentionError(err error) bool

IsContentionError reports whether err is a transient dqlite/SQLite contention or connection-state error worth retrying.

This is the single source of truth for contention classification across the codebase. The bounded busy-retry helpers (internal/run, internal/worker, internal/backfill) and the global connection-pool retry in pkg/db all delegate here so the matched error strings live in exactly one place.

Two distinct classes are recognised:

  • Direct contention (`database is locked`, `checkpoint in progress`, etc.): a simple retry is likely to find the database in a non-busy state. dqlite surfaces a WAL checkpoint in progress as a discrete "checkpoint in progress" error rather than SQLITE_BUSY, so it must be matched by string.
  • Connection-state poisoning (`cannot start a transaction within a transaction`): a previous transaction on the same pooled connection failed mid-flight (typically because the implicit ROLLBACK after a `checkpoint in progress` itself failed) and left the connection with a still-active SQLite transaction handle. The next caller's BEGIN on that connection then fails. With multiple pooled connections, retries are likely to draw a clean one.

func IsLocalLeader

func IsLocalLeader(ctx context.Context) (bool, error)

IsLocalLeader reports whether this process hosts the current dqlite leader.

func Open

func Open(dsn string) gorm.Dialector

func OpenSQLDB

func OpenSQLDB(ctx context.Context, name string) (*sql.DB, error)

OpenSQLDB opens an additional *sql.DB pool to the named database on the already-running native dqlite app. It backs a separate read pool alongside the gorm-managed (write) connection, so reads stay concurrent while writes serialize on a single-connection write pool. The native app must already be initialized — it is, once the first (write) connection has been opened.

Types

type ClusterNode

type ClusterNode struct {
	ID       uint64
	Address  string
	Role     string
	IsLeader bool
}

ClusterNode is a dqlite cluster member visible to the current native app.

func Cluster

func Cluster(ctx context.Context) ([]ClusterNode, error)

Cluster returns the current dqlite cluster membership from the leader.

type Dialector

type Dialector struct {
	DriverName string
	DSN        string
	Conn       gorm.ConnPool
}

func (Dialector) BindVarTo

func (dialector Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v any)

func (Dialector) ClauseBuilders

func (dialector Dialector) ClauseBuilders() map[string]clause.ClauseBuilder

func (Dialector) DataTypeOf

func (dialector Dialector) DataTypeOf(field *schema.Field) string

func (Dialector) DefaultValueOf

func (dialector Dialector) DefaultValueOf(field *schema.Field) clause.Expression

func (Dialector) Explain

func (dialector Dialector) Explain(sql string, vars ...any) string

func (Dialector) Initialize

func (dialector Dialector) Initialize(db *gorm.DB) (err error)

func (Dialector) Migrator

func (dialector Dialector) Migrator(db *gorm.DB) gorm.Migrator

func (Dialector) Name

func (dialector Dialector) Name() string

func (Dialector) QuoteTo

func (dialector Dialector) QuoteTo(writer clause.Writer, str string)

func (Dialector) RollbackTo

func (dialectopr Dialector) RollbackTo(tx *gorm.DB, name string) error

func (Dialector) SavePoint

func (dialectopr Dialector) SavePoint(tx *gorm.DB, name string) error

type Migrator

type Migrator struct {
	migrator.Migrator
}

func (Migrator) AlterColumn

func (m Migrator) AlterColumn(value any, name string) error

func (Migrator) BuildIndexOptions

func (m Migrator) BuildIndexOptions(opts []schema.IndexOption, stmt *gorm.Statement) (results []any)

func (Migrator) CreateConstraint

func (m Migrator) CreateConstraint(value any, name string) error

func (Migrator) CreateIndex

func (m Migrator) CreateIndex(value any, name string) error

func (Migrator) CurrentDatabase

func (m Migrator) CurrentDatabase() (name string)

func (Migrator) DropColumn

func (m Migrator) DropColumn(value any, name string) error

func (Migrator) DropConstraint

func (m Migrator) DropConstraint(value any, name string) error

func (Migrator) DropIndex

func (m Migrator) DropIndex(value any, name string) error

func (Migrator) DropTable

func (m Migrator) DropTable(values ...any) error

func (Migrator) HasColumn

func (m Migrator) HasColumn(value any, name string) bool

func (Migrator) HasConstraint

func (m Migrator) HasConstraint(value any, name string) bool

func (Migrator) HasIndex

func (m Migrator) HasIndex(value any, name string) bool

func (Migrator) HasTable

func (m Migrator) HasTable(value any) bool

func (Migrator) RenameIndex

func (m Migrator) RenameIndex(value any, oldName, newName string) error

func (*Migrator) RunWithoutForeignKey

func (m *Migrator) RunWithoutForeignKey(fc func() error) error

Jump to

Keyboard shortcuts

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