Skip to content

Commit

Permalink
breaking change: remove txn.RawRead field (#89)
Browse files Browse the repository at this point in the history
* save

* save
  • Loading branch information
AskAlexSharov authored Dec 7, 2022
1 parent 2cd9df4 commit 18e3486
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 21 deletions.
1 change: 0 additions & 1 deletion exp/mdbxpool/txnpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func (p *TxnPool) beginReadonly() (*mdbx.Txn, error) {
// Clear txn.Pooled to let a warning be emitted from the Txn finalizer
// again. And, make sure to clear RawRead to make the Txn appear like it
// was just allocated.
txn.RawRead = false
txn.Pooled = false

return txn, nil
Expand Down
8 changes: 1 addition & 7 deletions mdbx/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,7 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
// routines will be bad for the Go runtime when operating on Go memory
// (panic or potentially garbage memory reference).
if op == Set {
if c.txn.RawRead {
key = setkey
} else {
p := make([]byte, len(setkey))
copy(p, setkey)
key = p
}
key = setkey
} else {
if op != LastDup {
key = c.txn.bytes(c.txn.key)
Expand Down
3 changes: 0 additions & 3 deletions mdbx/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ func TestLastDup(t *testing.T) {
}

err = env.View(func(txn *Txn) error {
txn.RawRead = true
c, err := txn.OpenCursor(dbi)
if err != nil {
return err
Expand Down Expand Up @@ -649,7 +648,6 @@ func TestCursor_Del(t *testing.T) {
}

err = env.Update(func(txn *Txn) (err error) {
txn.RawRead = true
cur, err := txn.OpenCursor(db)
if err != nil {
return err
Expand Down Expand Up @@ -692,7 +690,6 @@ func TestCursor_Del(t *testing.T) {

var newitems []Item
err = env.View(func(txn *Txn) (err error) {
txn.RawRead = true
cur, err := txn.OpenCursor(db)
if err != nil {
return err
Expand Down
11 changes: 1 addition & 10 deletions mdbx/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ type Txn struct {

errLogf func(format string, v ...interface{})

// If RawRead is true []byte values retrieved from Get() calls on the Txn
// and its cursors will point directly into the memory-mapped structure.
// Such slices will be readonly and must only be referenced wthin the
// transaction's lifetime.
RawRead bool

// Pooled may be set to true while a Txn is stored in a sync.Pool, after
// Txn.Reset reset has been called and before Txn.Renew. This will keep
// the Txn finalizer from unnecessarily warning the application about
Expand Down Expand Up @@ -503,10 +497,7 @@ func (txn *Txn) subFlag(flags uint, fn TxnOp) error {
}

func (txn *Txn) bytes(val *C.MDBX_val) []byte {
if txn.RawRead {
return getBytes(val)
}
return getBytesCopy(val)
return getBytes(val)
}

// Get retrieves items from database dbi. If txn.RawRead is true the slice
Expand Down

0 comments on commit 18e3486

Please sign in to comment.