remove "k,v,err" fields in kv_bolt, they are useful only in badger (#690)

This commit is contained in:
Alex Sharov 2020-06-27 15:27:06 +07:00 committed by GitHub
parent 4c456a649f
commit 488a368e5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,10 +122,6 @@ type boltCursor struct {
prefix []byte
bolt *bolt.Cursor
k []byte
v []byte
err error
}
type noValuesBoltCursor struct {
@ -412,9 +408,6 @@ func (b boltBucket) Cursor() Cursor {
c.ctx = b.tx.ctx
c.bucket = b
c.prefix = nil
c.k = nil
c.v = nil
c.err = nil
c.bolt = b.bolt.Cursor()
// add to auto-close on end of transactions
if b.tx.cursors == nil {
@ -424,64 +417,64 @@ func (b boltBucket) Cursor() Cursor {
return c
}
func (c *boltCursor) First() ([]byte, []byte, error) {
func (c *boltCursor) First() (k, v []byte, err error) {
if len(c.prefix) == 0 {
c.k, c.v = c.bolt.First()
return c.k, c.v, nil
k, v = c.bolt.First()
return k, v, nil
}
c.k, c.v = c.bolt.Seek(c.prefix)
if !bytes.HasPrefix(c.k, c.prefix) {
k, v = c.bolt.Seek(c.prefix)
if !bytes.HasPrefix(k, c.prefix) {
return nil, nil, nil
}
return c.k, c.v, nil
return k, v, nil
}
func (c *boltCursor) Seek(seek []byte) ([]byte, []byte, error) {
func (c *boltCursor) Seek(seek []byte) (k, v []byte, err error) {
select {
case <-c.ctx.Done():
return []byte{}, nil, c.ctx.Err()
default:
}
c.k, c.v = c.bolt.Seek(seek)
k, v = c.bolt.Seek(seek)
if c.prefix != nil {
if !bytes.HasPrefix(c.k, c.prefix) {
if !bytes.HasPrefix(k, c.prefix) {
return nil, nil, nil
}
}
return c.k, c.v, nil
return k, v, nil
}
func (c *boltCursor) SeekTo(seek []byte) ([]byte, []byte, error) {
func (c *boltCursor) SeekTo(seek []byte) (k, v []byte, err error) {
select {
case <-c.ctx.Done():
return []byte{}, nil, c.ctx.Err()
default:
}
c.k, c.v = c.bolt.SeekTo(seek)
k, v = c.bolt.SeekTo(seek)
if c.prefix != nil {
if !bytes.HasPrefix(c.k, c.prefix) {
if !bytes.HasPrefix(k, c.prefix) {
return nil, nil, nil
}
}
return c.k, c.v, nil
return k, v, nil
}
func (c *boltCursor) Next() ([]byte, []byte, error) {
func (c *boltCursor) Next() (k, v []byte, err error) {
select {
case <-c.ctx.Done():
return []byte{}, nil, c.ctx.Err()
default:
}
c.k, c.v = c.bolt.Next()
k, v = c.bolt.Next()
if c.prefix != nil {
if !bytes.HasPrefix(c.k, c.prefix) {
c.k, c.v = nil, nil
if !bytes.HasPrefix(k, c.prefix) {
k, v = nil, nil
}
}
return c.k, c.v, nil
return k, v, nil
}
func (c *boltCursor) Delete(key []byte) error {
@ -540,47 +533,50 @@ func (c *noValuesBoltCursor) Walk(walker func(k []byte, vSize uint32) (bool, err
return nil
}
func (c *noValuesBoltCursor) First() ([]byte, uint32, error) {
func (c *noValuesBoltCursor) First() (k []byte, vSize uint32, err error) {
var v []byte
if len(c.prefix) == 0 {
c.k, c.v = c.bolt.First()
return c.k, uint32(len(c.v)), nil
k, v = c.bolt.First()
return k, uint32(len(v)), nil
}
c.k, c.v = c.bolt.Seek(c.prefix)
if !bytes.HasPrefix(c.k, c.prefix) {
k, v = c.bolt.Seek(c.prefix)
if !bytes.HasPrefix(k, c.prefix) {
return nil, 0, nil
}
return c.k, uint32(len(c.v)), nil
return k, uint32(len(v)), nil
}
func (c *noValuesBoltCursor) Seek(seek []byte) ([]byte, uint32, error) {
func (c *noValuesBoltCursor) Seek(seek []byte) (k []byte, vSize uint32, err error) {
select {
case <-c.ctx.Done():
return []byte{}, 0, c.ctx.Err() // on error key should be != nil
default:
}
c.k, c.v = c.bolt.Seek(seek)
var v []byte
k, v = c.bolt.Seek(seek)
if c.prefix != nil {
if !bytes.HasPrefix(c.k, c.prefix) {
if !bytes.HasPrefix(k, c.prefix) {
return nil, 0, nil
}
}
return c.k, uint32(len(c.v)), nil
return k, uint32(len(v)), nil
}
func (c *noValuesBoltCursor) Next() ([]byte, uint32, error) {
func (c *noValuesBoltCursor) Next() (k []byte, vSize uint32, err error) {
select {
case <-c.ctx.Done():
return []byte{}, 0, c.ctx.Err()
default:
}
c.k, c.v = c.bolt.Next()
var v []byte
k, v = c.bolt.Next()
if c.prefix != nil {
if !bytes.HasPrefix(c.k, c.prefix) {
if !bytes.HasPrefix(k, c.prefix) {
return nil, 0, nil
}
}
return c.k, uint32(len(c.v)), nil
return k, uint32(len(v)), nil
}