ldbwriter

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 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 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 SqlLdbWriter

type SqlLdbWriter struct {
	Db       *sql.DB
	LedgerTx *sql.Tx
}

ldbWriter applies statements to a SQL database

func (*SqlLdbWriter) ApplyDMLStatement

func (writer *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) Close

func (writer *SqlLdbWriter) Close() error

Jump to

Keyboard shortcuts

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