Documentation ¶
Index ¶
- type Manager
- type State
- type TX
- func (tx *TX) AllocateNewDataPage(table string) (*page.Page, error)
- func (tx *TX) CreateTable(name string) error
- func (tx *TX) DataPage(table string, id page.ID) (*page.Page, error)
- func (tx *TX) DataPageReadOnly(table string, id page.ID) (*page.Page, error)
- func (tx *TX) ExistingDataPagesForTable(table string) ([]page.ID, error)
- func (tx *TX) HasTable(name string) (bool, error)
- func (tx *TX) SchemaFile(table string) (*dbfs.SchemaFile, error)
- func (tx TX) State() State
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.
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 )
type TX ¶
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 ¶
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 ¶
CreateTable creates a table in this transaction. If such a table already exists, this will return an error.
func (*TX) DataPage ¶
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 ¶
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 ¶
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 ¶
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.