Documentation ¶
Index ¶
- Constants
- Variables
- func CheckDatabase(dbfile string) (ec error)
- func CheckOtherIndex(ixcols []string, ix *index.Overlay, nrows int, sumPrev uint64)
- func MakeLess(store *stor.Stor, is *ixkey.Spec) func(x, y uint64) bool
- func OffToRec(store *stor.Stor, off uint64) core.Record
- func OffToRecCk(store *stor.Stor, off uint64) core.Record
- func Repair(dbfile string, err error) (string, error)
- func StartConcur(db *Database, persistInterval time.Duration)
- func StartTimestamps()
- func Timestamp() SuDate
- type Check
- func (ck *Check) Abort(t *CkTran, reason string) bool
- func (ck *Check) AddExclusive(table string) bool
- func (ck *Check) Commit(ut *UpdateTran) bool
- func (ck *Check) Delete(t *CkTran, table string, off uint64, keys []string) bool
- func (ck *Check) EndExclusive(table string)
- func (ck *Check) Final() int
- func (ck *Check) Output(t *CkTran, table string, keys []string) bool
- func (ck *Check) Persist() *DbState
- func (ck *Check) Read(t *CkTran, table string, index int, from, to string) bool
- func (ck *Check) ReadCount(t *CkTran) int
- func (ck *Check) Run(fn func() error) error
- func (ck *Check) RunEndExclusive(table string, fn func()) (err any)
- func (ck *Check) RunExclusive(table string, fn func()) any
- func (ck *Check) StartTran() *CkTran
- func (ck *Check) Stop()
- func (ck *Check) Transactions() []int
- func (ck *Check) Update(t *CkTran, table string, oldoff uint64, oldkeys, newkeys []string) bool
- type CheckCo
- func (ck *CheckCo) Abort(t *CkTran, reason string) bool
- func (ck *CheckCo) AddExclusive(table string) bool
- func (ck *CheckCo) Commit(ut *UpdateTran) bool
- func (ck *CheckCo) Delete(t *CkTran, table string, off uint64, keys []string) bool
- func (ck *CheckCo) EndExclusive(table string)
- func (ck *CheckCo) Final() int
- func (ck *CheckCo) Output(t *CkTran, table string, keys []string) bool
- func (ck *CheckCo) Persist() *DbState
- func (ck *CheckCo) Read(t *CkTran, table string, index int, from, to string) bool
- func (ck *CheckCo) ReadCount(t *CkTran) int
- func (ck *CheckCo) RunEndExclusive(table string, fn func()) any
- func (ck *CheckCo) RunExclusive(table string, fn func()) any
- func (ck *CheckCo) StartTran() *CkTran
- func (ck *CheckCo) Stop()
- func (ck *CheckCo) Transactions() []int
- func (ck *CheckCo) Update(t *CkTran, table string, oldoff uint64, oldkeys, newkeys []string) bool
- type Checker
- type CkTran
- type Database
- func CreateDatabase(filename string) (*Database, error)
- func CreateDb(store *stor.Stor) (*Database, error)
- func OpenDatabase(filename string) (*Database, error)
- func OpenDb(filename string, mode stor.Mode, check bool) (db *Database, err error)
- func OpenDbStor(store *stor.Stor, mode stor.Mode, check bool) (db *Database, err error)
- func (db *Database) AddExclusive(table string)
- func (db *Database) AddNewTable(ts *meta.Schema, ti *meta.Info)
- func (db *Database) AddView(name, def string) bool
- func (db *Database) AlterCreate(sch *schema.Schema)
- func (db *Database) AlterDrop(schema *schema.Schema) bool
- func (db *Database) AlterRename(table string, from, to []string) bool
- func (t *Database) CallTrigger(th *Thread, tran *UpdateTran, table string, oldrec, newrec Record)
- func (db *Database) Check() (ec error)
- func (db *Database) CheckAllFkeys()
- func (db *Database) CheckerSync()
- func (db *Database) Close()
- func (db *Database) CloseKeepMapped()
- func (db *Database) Closed() bool
- func (db *Database) CommitMerge(ut *UpdateTran)
- func (db *Database) Corrupt()
- func (db *Database) Corrupted() bool
- func (db *Database) Create(schema *schema.Schema)
- func (t *Database) DisableTrigger(table string)
- func (db *Database) Drop(table string) error
- func (t *Database) EnableTrigger(table string)
- func (db *Database) EndExclusive(table string)
- func (db *Database) Ensure(sch *schema.Schema)
- func (db *Database) Final() int
- func (db *Database) GetState() *DbState
- func (db *Database) GetView(name string) string
- func (db *Database) HaveUsers() bool
- func (db *Database) Merge(fn mergefn, merges *mergeList)
- func (db *Database) MustCheck()
- func (db *Database) NewReadTran() *ReadTran
- func (db *Database) NewUpdateTran() *UpdateTran
- func (db *Database) OverwriteTable(ts *meta.Schema, ti *meta.Info)
- func (db *Database) Persist() *DbState
- func (db *Database) PersistSync()
- func (db *Database) QuickCheck() (err error)
- func (db *Database) RenameTable(from, to string) bool
- func (db *Database) RunEndExclusive(table string, fn func())
- func (db *Database) RunExclusive(table string, fn func())
- func (db *Database) Schema(table string) string
- func (db *Database) Size() uint64
- func (db *Database) Transactions() []int
- func (db *Database) UpdateState(fn func(*DbState))
- type DbState
- type ErrCorrupt
- type Ranges
- type ReadTran
- func (t *ReadTran) Abort() string
- func (t *ReadTran) Asof(asof int64) int64
- func (t *ReadTran) ColToFld(table, col string) int
- func (t *ReadTran) Complete() string
- func (t *ReadTran) Delete(*core.Thread, string, uint64)
- func (t *ReadTran) GetAllInfo() []*meta.Info
- func (t *ReadTran) GetAllSchema() []*meta.Schema
- func (t *ReadTran) GetAllViews() []string
- func (t *ReadTran) GetIndex(table string, cols []string) *index.Overlay
- func (t *ReadTran) GetIndexI(table string, iIndex int) *index.Overlay
- func (t *ReadTran) GetInfo(table string) *meta.Info
- func (t *ReadTran) GetRecord(off uint64) core.Record
- func (t *ReadTran) GetSchema(table string) *schema.Schema
- func (t *ReadTran) GetStore() *stor.Stor
- func (t *ReadTran) GetView(name string) string
- func (t *ReadTran) Lookup(table string, iIndex int, key string) *core.DbRec
- func (t *ReadTran) MakeLess(is *ixkey.Spec) func(x, y uint64) bool
- func (t *ReadTran) Num() int
- func (t *ReadTran) Output(*core.Thread, string, core.Record)
- func (t *ReadTran) RangeFrac(table string, iIndex int, org, end string) float64
- func (t *ReadTran) Read(string, int, string, string)
- func (t *ReadTran) ReadCount() int
- func (t *ReadTran) String() string
- func (t *ReadTran) Update(*core.Thread, string, uint64, core.Record) uint64
- func (t *ReadTran) WriteCount() int
- type Set
- type UpdateTran
- func (t *UpdateTran) Abort() string
- func (t *UpdateTran) Commit()
- func (t *UpdateTran) Complete() string
- func (t *UpdateTran) Delete(th *core.Thread, table string, off uint64)
- func (t *UpdateTran) GetAllInfo() []*meta.Info
- func (t *UpdateTran) GetAllSchema() []*meta.Schema
- func (t *UpdateTran) GetAllViews() []string
- func (t *UpdateTran) GetInfo(table string) *meta.Info
- func (t *UpdateTran) GetSchema(table string) *schema.Schema
- func (t *UpdateTran) GetStore() *stor.Stor
- func (t *UpdateTran) GetView(name string) string
- func (t *UpdateTran) Lookup(table string, iIndex int, key string) *core.DbRec
- func (t *UpdateTran) Num() int
- func (t *UpdateTran) Output(th *core.Thread, table string, rec core.Record)
- func (t *UpdateTran) Read(table string, iIndex int, from, to string)
- func (t *UpdateTran) ReadCount() int
- func (t *UpdateTran) String() string
- func (t *UpdateTran) Update(th *core.Thread, table string, oldoff uint64, newrec core.Record) uint64
- func (t *UpdateTran) WriteCount() int
Constants ¶
const MaxTrans = 500 // ???
MaxTrans is the maximum number of outstanding/overlapping update transactions
Variables ¶
var MakeSuTran func(tran *UpdateTran) *SuTran
MakeSuTran is injected by dbms to avoid import cycle
var MaxAge = 20
MaxAge is the maximum number of ticks that a transaction can be outstanding. Transactions are aborted if they exceed this limit.
Functions ¶
func CheckDatabase ¶
CheckDatabase is called by -check and -repair
func CheckOtherIndex ¶
func MakeLess ¶
MakeLess handles _lower! but not rules. It is used for indexes (which don't support rules).
func OffToRecCk ¶
OffToRecCk verifies the checksum following the record
func StartConcur ¶
StartConcur starts the database pipeline - starting the goroutines and connecting them with channels.
checker -> merger
persist is called by merger every persistInterval
To stop we close the checker channel, and then each following stage closes its output channel. Finally the merger closes the allDone channel so we know the shutdown has finished.
Types ¶
type Check ¶
type Check struct {
// contains filtered or unexported fields
}
Check holds the data for the transaction conflict checker. Checking is designed to be single threaded i.e. run in its own goroutine. It is intended to run asynchronously, i.e. callers not waiting for results. This allow more concurrency (overlap) with user code. Actions are checked as they are done, incrementally. A conflict with a completed transaction aborts the current transaction. A conflict with an outstanding (not completed) transaction randomly aborts one of the two transactions. The checker serializes transaction commits. A single sequence counter is used to assign unique start and end values. See CheckCo for the concurrent channel based interface to Check. See Checker for the common interface to Check and CheckCo
func (*Check) Abort ¶
Abort cancels a transaction. It returns false if the transaction is not found (e.g. already aborted).
func (*Check) AddExclusive ¶
AddExclusive is used for creating indexes on existing tables
func (*Check) Commit ¶
func (ck *Check) Commit(ut *UpdateTran) bool
Commit finishes a transaction. It returns false if the transaction is not found (e.g. already aborted). No additional checking required since actions have already been checked.
func (*Check) Delete ¶
Delete adds a delete action. Outputs only need to be checked against outstanding reads. The keys are parallel with the indexes i.e. keys[i] is for indexes[i].
func (*Check) EndExclusive ¶
func (*Check) Final ¶
Final returns the count of committed transactions overlapping with outstanding
func (*Check) Output ¶
Output adds an output action. Outputs only need to be checked against outstanding reads. The keys are parallel with the indexes i.e. keys[i] is for indexes[i].
func (*Check) Read ¶
Read adds a read action. Will conflict if another transaction has a write within the range.
func (*Check) RunEndExclusive ¶
func (*Check) RunExclusive ¶
func (*Check) Transactions ¶
Transactions returns a list of the active update transactions
type CheckCo ¶
type CheckCo struct {
// contains filtered or unexported fields
}
CheckCo is the concurrent, channel based interface to Check
func StartCheckCo ¶
func (*CheckCo) AddExclusive ¶
AddExclusive is used by load table and add index
func (*CheckCo) Commit ¶
func (ck *CheckCo) Commit(ut *UpdateTran) bool
func (*CheckCo) EndExclusive ¶
func (*CheckCo) RunEndExclusive ¶
func (*CheckCo) RunExclusive ¶
func (*CheckCo) Transactions ¶
type Checker ¶
type Checker interface { StartTran() *CkTran Read(t *CkTran, table string, index int, from, to string) bool Output(t *CkTran, table string, keys []string) bool Delete(t *CkTran, table string, off uint64, keys []string) bool Update(t *CkTran, table string, oldoff uint64, oldkeys, newkeys []string) bool ReadCount(t *CkTran) int Abort(t *CkTran, reason string) bool Commit(t *UpdateTran) bool Persist() *DbState Stop() Transactions() []int Final() int AddExclusive(table string) bool EndExclusive(table string) RunEndExclusive(table string, fn func()) any RunExclusive(table string, fn func()) any }
Checker is the interface for Check and CheckCo
type Database ¶
func CreateDatabase ¶
CreateDatabase creates an empty database in the named file. NOTE: The returned Database does not have a checker.
func CreateDb ¶
CreateDb creates an empty database in the store. NOTE: The returned Database does not have a checker.
func OpenDatabase ¶
OpenDatabase opens the database in the named file for read & write. NOTE: The returned Database does not have a checker yet.
func OpenDb ¶
OpenDb opens the database in the named file. NOTE: The returned Database does not have a checker.
func OpenDbStor ¶
OpenDbStor opens the database in the store. NOTE: The returned Database does not have a checker.
func (*Database) AddExclusive ¶
func (*Database) AddNewTable ¶
AddNewTable is used by compact and loading entire database. It panics if the table already exists.
func (*Database) AlterCreate ¶
AlterCreate creates columns or indexes
func (*Database) AlterRename ¶
AlterRename renames columns
func (*Database) CallTrigger ¶
func (t *Database) CallTrigger(th *Thread, tran *UpdateTran, table string, oldrec, newrec Record)
func (*Database) CheckAllFkeys ¶
func (db *Database) CheckAllFkeys()
CheckAllFkeys is used after loading an entire database.
func (*Database) CheckerSync ¶
func (db *Database) CheckerSync()
CheckerSync is for tests. It assigns a synchronous transaction checker to the database.
func (*Database) Close ¶
func (db *Database) Close()
Close closes the database store, writing the current size to the start.
func (*Database) CloseKeepMapped ¶
func (db *Database) CloseKeepMapped()
func (*Database) CommitMerge ¶
func (db *Database) CommitMerge(ut *UpdateTran)
CommitMerge is for tests. It merges synchronously after each commit.
func (*Database) DisableTrigger ¶
func (t *Database) DisableTrigger(table string)
func (*Database) EnableTrigger ¶
func (t *Database) EnableTrigger(table string)
func (*Database) EndExclusive ¶
func (*Database) GetState ¶
GetState returns a snapshot of the state as of a point in time. This state must be treated as read-only and must not be modified. To modify the state use UpdateState.
GetState is atomic, it is not blocked by UpdateState.
func (*Database) Merge ¶
func (db *Database) Merge(fn mergefn, merges *mergeList)
Merge updates the base ixbuf's with the ones from transactions It is called by concur.go merger.
func (*Database) NewReadTran ¶
func (*Database) NewUpdateTran ¶
func (db *Database) NewUpdateTran() *UpdateTran
func (*Database) OverwriteTable ¶
OverwriteTable is used when loading a single table. If the table already exists it is replaced.
func (*Database) Persist ¶
Persist forces a persist and returns a persisted state, with all ixbuf layer entries merged into the btree. This is used by dump, load, and checkdb.
func (*Database) QuickCheck ¶
QuickCheck is the default partial checking done at start up.
func (*Database) RenameTable ¶
func (*Database) RunEndExclusive ¶
func (*Database) RunExclusive ¶
func (*Database) Transactions ¶
Transactions only returns the update transactions. It returns nil if corrupted.
func (*Database) UpdateState ¶
UpdateState applies the given update function to a copy of theState and sets theState to the result. Guarded by stateMutex so only one thread can execute at a time. Note: the state passed to the update function is a *shallow* copy, it is up to the function to make copies of any nested containers.
UpdateState is guarded by a mutex
type DbState ¶
type DbState struct { Meta *meta.Meta Asof int64 // unix milli time Off uint64 // offset of this state // contains filtered or unexported fields }
type ErrCorrupt ¶
type ErrCorrupt struct {
// contains filtered or unexported fields
}
func (*ErrCorrupt) Error ¶
func (ec *ErrCorrupt) Error() string
func (*ErrCorrupt) Table ¶
func (ec *ErrCorrupt) Table() string
type ReadTran ¶
type ReadTran struct {
// contains filtered or unexported fields
}
func (*ReadTran) GetAllInfo ¶
func (*ReadTran) GetAllSchema ¶
func (*ReadTran) GetAllViews ¶
func (t *ReadTran) GetAllViews() []string
func (*ReadTran) WriteCount ¶
type UpdateTran ¶
type UpdateTran struct { ReadTran // contains filtered or unexported fields }
func (*UpdateTran) Abort ¶
func (t *UpdateTran) Abort() string
Abort returns "" if it succeeds or if the transaction was already aborted.
func (*UpdateTran) Commit ¶
func (t *UpdateTran) Commit()
Commit is used by tests. It panics on error.
func (*UpdateTran) Complete ¶
func (t *UpdateTran) Complete() string
Complete returns "" on success, otherwise an error
func (*UpdateTran) GetAllInfo ¶
func (*UpdateTran) GetAllSchema ¶
func (*UpdateTran) GetAllViews ¶
func (t *UpdateTran) GetAllViews() []string
func (*UpdateTran) Num ¶
func (t *UpdateTran) Num() int
func (*UpdateTran) Read ¶
func (t *UpdateTran) Read(table string, iIndex int, from, to string)
Read adds a transaction read event to the checker
func (*UpdateTran) ReadCount ¶
func (t *UpdateTran) ReadCount() int
func (*UpdateTran) String ¶
func (t *UpdateTran) String() string
func (*UpdateTran) WriteCount ¶
func (t *UpdateTran) WriteCount() int
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package filelock provides a platform-independent API for advisory file locking.
|
Package filelock provides a platform-independent API for advisory file locking. |
Package index implements gSuneido database indexes.
|
Package index implements gSuneido database indexes. |
ixbuf
Package ixbuf defines an ordered list ixbuf.T with a mutating Insert and a immutable persistent Merge.
|
Package ixbuf defines an ordered list ixbuf.T with a mutating Insert and a immutable persistent Merge. |
ixkey
Package ixkey handles specifying and encoding index key strings that are directly comparable.
|
Package ixkey handles specifying and encoding index key strings that are directly comparable. |
Package meta handles the database metadata.
|
Package meta handles the database metadata. |
schema
Package schema is a separate package so it can be used by query parsing.
|
Package schema is a separate package so it can be used by query parsing. |
Package stor is used to access physical storage, normally by memory mapped file access.
|
Package stor is used to access physical storage, normally by memory mapped file access. |