Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stateless Tx interface #1667

Merged
merged 1 commit into from
Apr 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions ethdb/kv_abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,42 +81,55 @@ const (
RO TxFlags = 0x02
)

type Tx interface {
// Cursor - creates cursor object on top of given bucket. Type of cursor - depends on bucket configuration.
// If bucket was created with lmdb.DupSort flag, then cursor with interface CursorDupSort created
// Otherwise - object of interface Cursor created
//
// Cursor, also provides a grain of magic - it can use a declarative configuration - and automatically break
// long keys into DupSort key/values. See docs for `bucket.go:BucketConfigItem`
Cursor(bucket string) (Cursor, error)
CursorDupSort(bucket string) (CursorDupSort, error) // CursorDupSort - can be used if bucket has lmdb.DupSort flag
type StatelessReadTx interface {
GetOne(bucket string, key []byte) (val []byte, err error)
HasOne(bucket string, key []byte) (bool, error)

Commit(ctx context.Context) error // Commit all the operations of a transaction into the database.
Rollback() // Rollback - abandon all the operations of the transaction instead of saving them.

Comparator(bucket string) dbutils.CmpFunc

// ReadSequence - allows to create a linear sequence of unique positive integers for each table.
// Can be called for a read transaction to retrieve the current sequence value, and the increment must be zero.
// Sequence changes become visible outside the current write transaction after it is committed, and discarded on abort.
// Starts from 0.
ReadSequence(bucket string) (uint64, error)
}

type StatelessWriteTx interface {
IncrementSequence(bucket string, amount uint64) (uint64, error)

Put(bucket string, k, v []byte) error
Delete(bucket string, k, v []byte) error
}

type StatelessRwTx interface {
StatelessReadTx
StatelessWriteTx
}

type Tx interface {
StatelessReadTx

// Cursor - creates cursor object on top of given bucket. Type of cursor - depends on bucket configuration.
// If bucket was created with lmdb.DupSort flag, then cursor with interface CursorDupSort created
// Otherwise - object of interface Cursor created
//
// Cursor, also provides a grain of magic - it can use a declarative configuration - and automatically break
// long keys into DupSort key/values. See docs for `bucket.go:BucketConfigItem`
Cursor(bucket string) (Cursor, error)
CursorDupSort(bucket string) (CursorDupSort, error) // CursorDupSort - can be used if bucket has lmdb.DupSort flag

Comparator(bucket string) dbutils.CmpFunc

CHandle() unsafe.Pointer // Pointer to the underlying C transaction handle (e.g. *C.MDB_txn)
}

type RwTx interface {
Tx
StatelessWriteTx

RwCursor(bucket string) (RwCursor, error)
RwCursorDupSort(bucket string) (RwCursorDupSort, error)

IncrementSequence(bucket string, amount uint64) (uint64, error)

Put(bucket string, k, v []byte) error
Delete(bucket string, k, v []byte) error
}

// BucketMigrator used for buckets migration, don't use it in usual app code
Expand Down