ldbwriter

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackWriter

type CallbackWriter struct {
	DB           *sql.DB
	Delegate     LDBWriter
	Callbacks    []LDBWriteCallback
	ChangeBuffer *sqlite.SQLChangeBuffer
}

CallbackWriter is an LDBWriter that delegates to another writer and then, upon a successful write, executes N callbacks.

func (*CallbackWriter) ApplyDMLStatement

func (w *CallbackWriter) ApplyDMLStatement(ctx context.Context, statement schema.DMLStatement) error

type ChangelogCallback

type ChangelogCallback struct {
	ChangelogWriter *changelog.ChangelogWriter
	Seq             int64
}

func (*ChangelogCallback) LDBWritten

func (c *ChangelogCallback) LDBWritten(ctx context.Context, data LDBWriteMetadata)

type CheckpointType added in v0.0.4

type CheckpointType string

CheckpointType see https://www.sqlite.org/pragma.html#pragma_wal_checkpoint

var (
	Passive  CheckpointType = "PASSIVE"
	Full     CheckpointType = "FULL"
	Restart  CheckpointType = "RESTART"
	Truncate CheckpointType = "TRUNCATE"
)

type LDBWriteCallback

type LDBWriteCallback interface {
	LDBWritten(ctx context.Context, data LDBWriteMetadata)
}

type LDBWriteMetadata

type LDBWriteMetadata struct {
	DB        *sql.DB
	Statement schema.DMLStatement
	Changes   []sqlite.SQLiteWatchChange
}

LDBWriteMetadata contains the metadata about a statement that was written to the LDB.

type LDBWriter

type LDBWriter interface {
	ApplyDMLStatement(ctx context.Context, statement schema.DMLStatement) error
}

Statement to update the sequence tracker, ensuring that it doesn't go backwards without a round-trip to the DB and/or any race conditions. The statement is parameterized with the only one being the new sequence

type LDBWriterWithChangelog

type LDBWriterWithChangelog struct {
	LdbWriter       LDBWriter
	ChangelogWriter *changelog.ChangelogWriter
	DB              *sql.DB
	ChangeBuffer    *sqlite.SQLChangeBuffer
	Seq             int64
}

func (*LDBWriterWithChangelog) ApplyDMLStatement

func (w *LDBWriterWithChangelog) ApplyDMLStatement(ctx context.Context, statement schema.DMLStatement) error

NOTE: How does the changelog work?

This is sort of the crux of how the changelog comes together. The Reflector sets a pre-update hook which populates a channel with any changes that happen in the LDB. These changes end up on a buffered channel. After each statement is executed, the pre-update hook will get called, filling in the channel. Once that ApplyDMLStatement returns, the DML statement is committed and the channel contains the contents of the update. Then this function takes over, extracts the keys from the update, and writes them to the changelogWriter.

This is pretty complex, but after enumerating about 8 different options, it ended up actually being the most simple. Other options involved not-so-great options like parsing SQL or maintaining triggers on every table.

type PragmaWALResult added in v0.0.4

type PragmaWALResult struct {
	// 0 indicates not busy, checkpoint was not blocked from completing. 1 is blocked
	Busy int
	// number of modified pages that have been written to the write-ahead log file per a checkpoint run
	Log int
	// number of pages in the write-ahead log file that have been successfully moved back into the database file at the conclusion of the checkpoint
	Checkpointed int
	// Type of checkpointing performed
	Type CheckpointType
}

PragmaWALResult https://www.sqlite.org/pragma.html#pragma_wal_checkpoint

func (*PragmaWALResult) String added in v0.0.4

func (p *PragmaWALResult) String() string

type SqlLdbWriter

type SqlLdbWriter struct {
	Db       *sql.DB
	LedgerTx *sql.Tx
	// uniquely identify this SqlWriter
	Logger *events.Logger
	ID     string
}

ldbWriter applies statements to a SQL database

func (*SqlLdbWriter) ApplyDMLStatement

func (w *SqlLdbWriter) ApplyDMLStatement(_ context.Context, statement schema.DMLStatement) error

Applies a DML statement to the writer's db, updating the sequence tracking table in the same transaction

func (*SqlLdbWriter) Checkpoint added in v0.0.4

func (w *SqlLdbWriter) Checkpoint(checkpointingType CheckpointType) (*PragmaWALResult, error)

Checkpoint initiates a wal checkpoint, returning stats on the checkpoint's progress see https://www.sqlite.org/pragma.html#pragma_wal_checkpoint for more details requires write access

func (*SqlLdbWriter) Close

func (w *SqlLdbWriter) Close() error

Jump to

Keyboard shortcuts

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