transaction

package
v0.0.0-...-65fd79d Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager interface {
	io.Closer

	// Start a new transaction that will be pending in this manager
	// until it is either committed or rolled back. This means, that
	// it will be persisted if the Manager is closed before the
	// transaction finishes.
	Start() (*TX, error)
	// Commit will apply all changes from the transaction to the database,
	// or return an error and not apply any changes.
	Commit(*TX) error
	// Rollback will abort the transaction. No changes will be applied
	// and the transaction will not be considered 'pending' anymore.
	Rollback(*TX) error
}

Manager describes a component that can start and process transactions. A manager is used to start a transaction, which will be used to store modifications to the database. The transaction only describe the changes, they do not perform them.

The Manager is responsible to apply the described changes. If this is not possible, NO CHANGE of the transaction must be applied.

A Manager is also responsible for keeping track of pending transactions. Upon close, these transactions must be persisted, either in the database, in a journal or similar. The exact way of persisting these pending changes is up to the implementation. The constructor of a Manager should read persisted, still pending changes.

func NewBrokenManager

func NewBrokenManager(log zerolog.Logger, dbfs *dbfs.DBFS) Manager

NewBrokenManager returns a transaction manager that probably works, but it's just as likely that it is broken - as the name says.

type State

type State uint8

State describes the current state of a transaction, and implies whether or not the transaction may be modified any more.

const (
	// StateUnknown indicates that the state is unknown and/or invalid
	// and/or not set yet.
	StateUnknown State = iota
	// StatePending indicates that a transaction is still in use and
	// may be modified further.
	StatePending
	// StateCommitted indicates that the transaction was committed to
	// secondary storage, and that it can not be modified any further.
	StateCommitted
	// StateRolledBack indicates that the transaction was aborted and
	// no changes were persisted. The transaction can not be modified
	// any further.
	StateRolledBack
)

func (State) String

func (i State) String() string

type TX

type TX struct {
	ID id.ID
	// contains filtered or unexported fields
}

TX represents a single transaction or unit of work in the database. A transaction can load and modify pages. Changes across multiple transactions will be merged by the transaction manager upon commit.

func (*TX) AllocateNewDataPage

func (tx *TX) AllocateNewDataPage(table string) (*page.Page, error)

AllocateNewDataPage will attempt to allocate a new page in the data file of the table with the given name. If the table does not exist, an error will be returned.

func (*TX) CreateTable

func (tx *TX) CreateTable(name string) error

CreateTable creates a table in this transaction. If such a table already exists, this will return an error.

func (*TX) DataPage

func (tx *TX) DataPage(table string, id page.ID) (*page.Page, error)

DataPage attempts to lookup a page with the given ID from the data file of the table with the given name. This will also check pages that were created in this transaction and are not written to disk yet. This will cache loaded pages.

func (*TX) DataPageReadOnly

func (tx *TX) DataPageReadOnly(table string, id page.ID) (*page.Page, error)

DataPageReadOnly will load the requested page from the given table in read-only mode, meaning that you can modify the page, but all modifications will be lost as soon as the GC collects the page. If the requested page already exists in memory, a copy of the cached page will be returned. If not, the requested page will be loaded from secondary storage, but will not be cached.

func (*TX) ExistingDataPagesForTable

func (tx *TX) ExistingDataPagesForTable(table string) ([]page.ID, error)

ExistingDataPagesForTable returns a slice of page IDs that exist in the data file of the table with the given name. If the table does not exist, an error will be returned.

func (*TX) HasTable

func (tx *TX) HasTable(name string) (bool, error)

HasTable indicates whether this transaction has access to a table with the given name. This also accounts for tables that were created in this transaction and do not exist on disk yet.

func (*TX) SchemaFile

func (tx *TX) SchemaFile(table string) (*dbfs.SchemaFile, error)

SchemaFile returns the schema file for the table with the given name. This respects changes to the schema file that were performed in this transaction. Schema files will be cached.

func (TX) State

func (tx TX) State() State

State returns the state that this transaction is currently in.

Jump to

Keyboard shortcuts

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