From 28d6482e8224c37ab541fb718c31bd31ba52f961 Mon Sep 17 00:00:00 2001 From: Artem Vorotnikov Date: Sat, 3 Apr 2021 07:17:51 +0300 Subject: [PATCH] Stateless Tx interface --- ethdb/kv_abstract.go | 45 ++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/ethdb/kv_abstract.go b/ethdb/kv_abstract.go index 44960226224..cd46e4189a3 100644 --- a/ethdb/kv_abstract.go +++ b/ethdb/kv_abstract.go @@ -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