Go · Transactions

Transactions

import "github.com/unum-cloud/ustore" 1.0.0-rc.1 · 084197c4

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/ustore/go/transactions.md' | claude -p "How would this fit my code?"

A transaction groups reads and writes across collections and modalities, and commits all of them or none. Its own verbs record the keys they touch, so the commit reports StatusWriteConflict, StatusReadConflict or StatusPhantomConflict if another writer changed them, while Transaction.View with WatchNone records nothing. A transaction conflicts rather than blocks, and keeps its contents whatever the outcome, so Reset reopens it on the newest state for another try. Stage answers a ReadStamp, the stamp the transaction reads at and its commit validates against, and Commit a CommitStamp, its position in commit order; the two are distinct types, so neither is compared with the other by accident. Rollback withdraws a stage while keeping the reads and writes, so the transaction can stage again.

transaction, err := database.TransactionInit()
defer transaction.Close()
err = transaction.BlobsWrite(people, []ustore.Key{ada, grace}, ustore.TapeOf("Ada", "Grace"), nil)
peek, err := transaction.View(ustore.WatchNone).BlobsRead(people, []ustore.Key{ada}, arena, nil)
readStamp, err := transaction.Stage()
commitStamp, err := transaction.Commit(ustore.DurabilityFlushed)

API

Types

CommitStampCommitStamp is a commit's position in commit order, which a read at any ReadStamp at or above it sees.
db.go:145 ↗
type CommitStamp uint64
ReadStampReadStamp is the stamp a transaction or a snapshot reads at.
db.go:141 ↗
type ReadStamp uint64
EnumIsolationIsolation is how the transactions of the in-memory engine see each other's writes.2
db.go:344 ↗
type Isolation int32

Values

IsolationStrictSerializableIsolationStrictSerializable makes every transaction appear to run alone at one moment.
IsolationSnapshotIsolationSnapshot makes every transaction read the state its start saw.
IsolationFromNameIsolationFromName reads an isolation back from the spelling Isolation.String renders.
db.go:359 ↗
func IsolationFromName(name string) (Isolation, error)
StringString renders the isolation as the library spells it.
db.go:354 ↗
func (isolation Isolation) String() string
StructTransactionDeferredOnTransactionDeferredOn is the receiver whose verbs submit their calls to an executor, offering the verbs of TransactionOn with the same arguments.18
db.go:701 ↗
type TransactionDeferredOn struct {
    // contains filtered or unexported fields
}
*× 3Commit submits TransactionOn.Commit.
db.go:1692 ↗
func (on TransactionDeferredOn) Commit(
    durability Durability,
) (*Deferred[CommitStamp], error)
Symbol
Commit
Rollback
Stage
BlobsRemoveBlobsRemove submits DatabaseOn.BlobsRemove.
db.go:209 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) BlobsRemove(
    collections Collections,
    keys []Key,
    config *RemoveConfig,
) (*Deferred[struct{}], error)
BlobsWriteBlobsWrite submits DatabaseOn.BlobsWrite.
db.go:169 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) BlobsWrite(
    collections Collections,
    keys []Key,
    values Tape,
    config *WriteConfig,
) (*Deferred[struct{}], error)
DocsRemoveDocsRemove submits DatabaseOn.DocsRemove.
db.go:194 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) DocsRemove(
    collections Collections,
    keys []Key,
    config *RemoveConfig,
) (*Deferred[struct{}], error)
DocsWriteDocsWrite submits DatabaseOn.DocsWrite.
db.go:149 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) DocsWrite(
    collections Collections,
    keys []Key,
    values Tape,
    config *DocsWriteConfig,
) (*Deferred[struct{}], error)
GraphRemoveEdgesGraphRemoveEdges submits DatabaseOn.GraphRemoveEdges.
db.go:261 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) GraphRemoveEdges(
    collections Collections,
    edges []Edge,
    config *WriteConfig,
) (*Deferred[struct{}], error)
GraphRemoveVerticesGraphRemoveVertices submits DatabaseOn.GraphRemoveVertices.
db.go:358 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) GraphRemoveVertices(
    collections Collections,
    vertices []Key,
    config *GraphRemoveVerticesConfig,
) (*Deferred[struct{}], error)
GraphWriteEdgesGraphWriteEdges submits DatabaseOn.GraphWriteEdges.
db.go:219 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) GraphWriteEdges(
    collections Collections,
    edges []Edge,
    config *WriteConfig,
) (*Deferred[struct{}], error)
GraphWriteVerticesGraphWriteVertices submits DatabaseOn.GraphWriteVertices.
db.go:307 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) GraphWriteVertices(
    collections Collections,
    vertices []Key,
    config *WriteConfig,
) (*Deferred[struct{}], error)
PagesImportPagesImport submits DatabaseOn.PagesImport.
db.go:91 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) PagesImport(
    collections Collections,
    keys []Key,
    values Tape,
    config *PagesImportConfig,
) (*Deferred[struct{}], error)
PagesInsertPagesInsert submits DatabaseOn.PagesInsert.
db.go:167 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) PagesInsert(
    collections Collections,
    keys []Key,
    values Tape,
    arena *Arena,
    config *PagesInsertConfig,
) (*Deferred[Inserted], error)
PagesMovePagesMove submits DatabaseOn.PagesMove.
db.go:280 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) PagesMove(
    collections Collections,
    keys, elements []Key,
    config *PagesMoveConfig,
) (*Deferred[struct{}], error)
PagesRemovePagesRemove submits DatabaseOn.PagesRemove.
db.go:227 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) PagesRemove(
    collections Collections,
    keys []Key,
    config *PagesRemoveConfig,
) (*Deferred[struct{}], error)
PagesRemoveAttributesPagesRemoveAttributes submits DatabaseOn.PagesRemoveAttributes.
db.go:408 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) PagesRemoveAttributes(
    collections Collections,
    keys, elements []Key,
    fields Tape,
    config *WriteConfig,
) (*Deferred[struct{}], error)
PagesSetAttributesPagesSetAttributes submits DatabaseOn.PagesSetAttributes.
db.go:366 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) PagesSetAttributes(
    collections Collections,
    keys, elements []Key,
    fields, values Tape,
    config *WriteConfig,
) (*Deferred[struct{}], error)
PagesSplicePagesSplice submits DatabaseOn.PagesSplice.
db.go:323 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) PagesSplice(
    collections Collections,
    keys, elements []Key,
    textStarts, textLengths []uint64,
    values Tape,
    config *WriteConfig,
) (*Deferred[struct{}], error)
StringsRemoveStringsRemove submits DatabaseOn.StringsRemove.
db.go:91 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) StringsRemove(
    collections Collections,
    strings Tape,
    config *StringsRemoveConfig,
) (*Deferred[struct{}], error)
StringsWriteStringsWrite submits DatabaseOn.StringsWrite.
db.go:40 ↗

Inherited from deferredWrites[Handle]

func (on TransactionDeferredOn) StringsWrite(
    collections Collections,
    strings Tape,
    values []Key,
    config *WriteConfig,
) (*Deferred[struct{}], error)
EnumWatchWatch is whether a transaction records the keys a call reads or writes, to refuse its commit when another writer changes them first.2
db.go:244 ↗
type Watch int32

Values

WatchKeysWatchKeys records the keys, so a concurrent change to any of them fails the commit.
WatchNoneWatchNone records nothing, so concurrent changes to these keys never fail the commit.
WatchFromNameWatchFromName reads a watch back from the spelling Watch.String renders.
db.go:257 ↗
func WatchFromName(name string) (Watch, error)
StringString renders the watch as the library spells it.
db.go:254 ↗
func (watch Watch) String() string