Documentation
¶
Index ¶
- Constants
- Variables
- func AssertNoMemoryLeaks(t *testing.T)
- func ErrorCode(err error) int
- func Init() error
- func StatusMallocCount(reset bool) (int, int, error)
- func StatusMemoryUsed(reset bool) (int, int, error)
- type Cluster
- type ClusterMethods
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) ConfigNoCkptOnClose(flag bool) (bool, error)
- func (c *Conn) Exec(query string) error
- func (c *Conn) Filename() string
- func (c *Conn) Query(query string) (*Rows, error)
- func (c *Conn) WalCheckpoint(schema string, mode WalCheckpointMode) (int, int, error)
- func (c *Conn) WalReplicationFollower() error
- func (c *Conn) WalReplicationFrames(info WalReplicationFrameInfo) error
- func (c *Conn) WalReplicationLeader(name string) error
- func (c *Conn) WalReplicationUndo() error
- type Error
- type FrameNumber
- type Logger
- type PageNumber
- type Rows
- type Server
- type ServerInfo
- type Vfs
- type WalCheckpointMode
- type WalReplication
- type WalReplicationFrameInfo
- func (i *WalReplicationFrameInfo) IsBegin(flag bool)
- func (i *WalReplicationFrameInfo) IsCommit(flag bool)
- func (i *WalReplicationFrameInfo) IsCommitGet() bool
- func (i *WalReplicationFrameInfo) Len(n int)
- func (i *WalReplicationFrameInfo) PageSize(size int)
- func (i *WalReplicationFrameInfo) Pages(numbers []PageNumber, data unsafe.Pointer)
- func (i *WalReplicationFrameInfo) Truncate(truncate uint)
- type WalReplicationFrameList
- type WalReplicationMethods
Constants ¶
const ( OpenReadWrite = C.SQLITE_OPEN_READWRITE OpenReadOnly = C.SQLITE_OPEN_READONLY OpenCreate = C.SQLITE_OPEN_CREATE )
Open modes.
const ( Integer = C.SQLITE_INTEGER Float = C.SQLITE_FLOAT Text = C.SQLITE_TEXT Blob = C.SQLITE_BLOB Null = C.SQLITE_NULL )
SQLite datatype codes
const ( UnixTime = C.DQLITE_UNIXTIME ISO8601 = C.DQLITE_ISO8601 Boolean = C.DQLITE_BOOLEAN )
Special data types for time values.
const ( ErrError = C.SQLITE_ERROR ErrInternal = C.SQLITE_INTERNAL ErrNoMem = C.SQLITE_NOMEM ErrInterrupt = C.SQLITE_INTERRUPT ErrBusy = C.SQLITE_BUSY ErrIoErr = C.SQLITE_IOERR ErrIoErrNotLeader = C.SQLITE_IOERR_NOT_LEADER ErrIoErrLeadershipLost = C.SQLITE_IOERR_LEADERSHIP_LOST )
Error codes.
const ( LogDebug = C.DQLITE_LOG_DEBUG LogInfo = C.DQLITE_LOG_INFO LogWarn = C.DQLITE_LOG_WARN LogError = C.DQLITE_LOG_ERROR )
Logging levels.
const ( RequestLeader = C.DQLITE_REQUEST_LEADER RequestClient = C.DQLITE_REQUEST_CLIENT RequestHeartbeat = C.DQLITE_REQUEST_HEARTBEAT RequestOpen = C.DQLITE_REQUEST_OPEN RequestPrepare = C.DQLITE_REQUEST_PREPARE RequestExec = C.DQLITE_REQUEST_EXEC RequestQuery = C.DQLITE_REQUEST_QUERY RequestFinalize = C.DQLITE_REQUEST_FINALIZE RequestExecSQL = C.DQLITE_REQUEST_EXEC_SQL RequestQuerySQL = C.DQLITE_REQUEST_QUERY_SQL RequestInterrupt = C.DQLITE_REQUEST_INTERRUPT )
Request types.
const ( ResponseFailure = C.DQLITE_RESPONSE_FAILURE ResponseServer = C.DQLITE_RESPONSE_SERVER ResponseWelcome = C.DQLITE_RESPONSE_WELCOME ResponseServers = C.DQLITE_RESPONSE_SERVERS ResponseDb = C.DQLITE_RESPONSE_DB ResponseStmt = C.DQLITE_RESPONSE_STMT ResponseResult = C.DQLITE_RESPONSE_RESULT ResponseRows = C.DQLITE_RESPONSE_ROWS ResponseEmpty = C.DQLITE_RESPONSE_EMPTY )
Response types.
const ( WalCheckpointPassive = WalCheckpointMode(C.SQLITE_CHECKPOINT_PASSIVE) WalCheckpointFull = WalCheckpointMode(C.SQLITE_CHECKPOINT_FULL) WalCheckpointRestart = WalCheckpointMode(C.SQLITE_CHECKPOINT_RESTART) WalCheckpointTruncate = WalCheckpointMode(C.SQLITE_CHECKPOINT_TRUNCATE) )
WAL checkpoint modes
const ProtocolVersion = uint64(C.DQLITE_PROTOCOL_VERSION)
ProtocolVersion is the latest dqlite server protocol version.
Variables ¶
var ErrServerStopped = fmt.Errorf("server was stopped")
ErrServerStopped is returned by Server.Handle() is the server was stopped.
Functions ¶
func AssertNoMemoryLeaks ¶
AssertNoMemoryLeaks is a test helper asserting that current allocation count and used memory are both zero.
func StatusMallocCount ¶
StatusMallocCount returns the current and highest number of memory allocations performed with sqlite3_malloc.
Types ¶
type Cluster ¶
type Cluster C.dqlite_cluster
Cluster is a Go wrapper around the associated dqlite's C type.
func NewCluster ¶
func NewCluster(methods ClusterMethods) (*Cluster, error)
NewCluster creates a new Cluster object set with the given method hooks..
type ClusterMethods ¶
type ClusterMethods interface { // Return the address of the current cluster leader, if any. If not // empty, the address string must a be valid network IP or hostname, // that clients can use to connect to a dqlite service. Leader() string // If this driver is the current leader of the cluster, return the // addresses of all other servers. Each address must be a valid IP or // host name name, that clients can use to connect to the relevant // dqlite service , in case the current leader is deposed and a new one // is elected. // // If this driver is not the current leader of the cluster, an error // implementing the Error interface below and returning true in // NotLeader() must be returned. Servers() ([]ServerInfo, error) Register(*Conn) Unregister(*Conn) Barrier() error Recover(token uint64) error Checkpoint(*Conn) error }
ClusterMethods implements the interface required by the various hooks dqlite_cluster.
type Conn ¶
Conn is a Go wrapper around a SQLite database handle.
func (*Conn) ConfigNoCkptOnClose ¶
ConfigNoCkptOnClose switches on or off the automatic WAL checkpoint when a connection is closed.
func (*Conn) WalCheckpoint ¶
WalCheckpoint triggers a WAL checkpoint on the given database attached to the connection. See https://sqlite.org/c3ref/wal_checkpoint_v2.html
func (*Conn) WalReplicationFollower ¶
WalReplicationFollower switches the given SQLite connection to follower WAL replication mode. In this mode no regular operation is possible, and the connection should be driven with the WalReplicationFrames, and WalReplicationUndo APIs.
func (*Conn) WalReplicationFrames ¶
func (c *Conn) WalReplicationFrames(info WalReplicationFrameInfo) error
WalReplicationFrames writes the given batch of frames to the write-ahead log linked to the given connection.
This method must be called with a "follower" connection, meant to replicate the "leader" one.
func (*Conn) WalReplicationLeader ¶
WalReplicationLeader switches the SQLite connection to leader WAL replication mode.
func (*Conn) WalReplicationUndo ¶
WalReplicationUndo rollbacks a write transaction in the given sqlite connection. This should be called with a "follower" connection, meant to replicate the "leader" one.
type Logger ¶
type Logger C.dqlite_logger
Logger is a Go wrapper around the associated dqlite's C type.
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows represents a result set.
type Server ¶
type Server C.dqlite_server
Server is a Go wrapper arround dqlite_server.
func (*Server) SetWalReplication ¶
SetWalReplication sets the name of the WAL replication to use for new connections.
type ServerInfo ¶
ServerInfo is the Go equivalent of dqlite_server_info.
type Vfs ¶
type Vfs C.sqlite3_vfs
Vfs is a Go wrapper around dqlite's in-memory VFS implementation.
type WalCheckpointMode ¶
type WalCheckpointMode int
WalCheckpointMode defines all valid values for the "checkpoint mode" parameter of the WalCheckpointV2 API. See https://sqlite.org/c3ref/wal_checkpoint_v2.html.
type WalReplication ¶
type WalReplication C.sqlite3_wal_replication
WalReplication is a Go wrapper around the associated SQLite's C type.
func NewWalReplication ¶
func NewWalReplication(name string, methods WalReplicationMethods) (*WalReplication, error)
NewWalReplication registers a WAL replication instance under the given name.
func (*WalReplication) Close ¶
func (r *WalReplication) Close() error
Close unregisters and destroys this WAL replication instance.
func (*WalReplication) Name ¶
func (r *WalReplication) Name() string
Name returns the registration name of the Wal replication.
type WalReplicationFrameInfo ¶
type WalReplicationFrameInfo struct {
// contains filtered or unexported fields
}
WalReplicationFrameInfo information about a single batch of WAL frames that are being replicated by a follower connection.
func (*WalReplicationFrameInfo) IsBegin ¶
func (i *WalReplicationFrameInfo) IsBegin(flag bool)
IsBegin sets the C isBegin parameter for sqlite3_wal_replication_frames.
func (*WalReplicationFrameInfo) IsCommit ¶
func (i *WalReplicationFrameInfo) IsCommit(flag bool)
IsCommit sets the isCommit parameter for sqlite3_wal_replication_frames.
func (*WalReplicationFrameInfo) IsCommitGet ¶
func (i *WalReplicationFrameInfo) IsCommitGet() bool
func (*WalReplicationFrameInfo) Len ¶
func (i *WalReplicationFrameInfo) Len(n int)
Len sets the C nFrame parameter for sqlite3_wal_replication_frames.
func (*WalReplicationFrameInfo) PageSize ¶
func (i *WalReplicationFrameInfo) PageSize(size int)
PageSize sets the C szPage parameter for sqlite3_wal_replication_frames.
func (*WalReplicationFrameInfo) Pages ¶
func (i *WalReplicationFrameInfo) Pages(numbers []PageNumber, data unsafe.Pointer)
Pages sets the C aPgno and aPage parameters for sqlite3_wal_replication_frames.
func (*WalReplicationFrameInfo) Truncate ¶
func (i *WalReplicationFrameInfo) Truncate(truncate uint)
Truncate sets the nTruncate parameter for sqlite3_wal_replication_frames.
type WalReplicationFrameList ¶
type WalReplicationFrameList struct {
// contains filtered or unexported fields
}
WalReplicationFrameList holds information about a single batch of WAL frames that are being dispatched for replication by a leader connection.
They map to the parameters of the sqlite3_wal_replication.xFrames API
func (*WalReplicationFrameList) Frame ¶
func (l *WalReplicationFrameList) Frame(i int) (unsafe.Pointer, PageNumber, FrameNumber)
Frame returns information about the i'th frame in the batch.
func (*WalReplicationFrameList) IsCommit ¶
func (l *WalReplicationFrameList) IsCommit() bool
IsCommit returns whether this batch of WAL frames concludes a transaction.
func (*WalReplicationFrameList) Len ¶
func (l *WalReplicationFrameList) Len() int
Len returns the number of WAL frames in this batch.
func (*WalReplicationFrameList) PageSize ¶
func (l *WalReplicationFrameList) PageSize() int
PageSize returns the page size of this batch of WAL frames.
func (*WalReplicationFrameList) Truncate ¶
func (l *WalReplicationFrameList) Truncate() uint
Truncate returns the size of the database in pages after this batch of WAL frames is applied.
type WalReplicationMethods ¶
type WalReplicationMethods interface { // Begin a new write transaction. The implementation should check // that the database is eligible for starting a replicated write // transaction (e.g. this node is the leader), and perform internal // state changes as appropriate. Begin(*Conn) int // Abort a write transaction. The implementation should clear any // state previously set by the Begin hook. Abort(*Conn) int // Write new frames to the write-ahead log. The implementation should // broadcast this write to other nodes and wait for a quorum. Frames(*Conn, WalReplicationFrameList) int // Undo a write transaction. The implementation should broadcast // this event to other nodes and wait for a quorum. The return code // is currently ignored by SQLite. Undo(*Conn) int // End a write transaction. The implementation should update its // internal state and be ready for a new transaction. End(*Conn) int }
WalReplicationMethods implements the interface required by the various hooks of sqlite3_wal_replication.