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

Avoid ReadOptions mutated by reference release in iterator #172

Merged
merged 6 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ func (db *DB) NewIterator(opts *ReadOptions) *Iterator {
// that uses the ReadOptions given.
func (db *DB) NewIteratorCF(opts *ReadOptions, cf *ColumnFamilyHandle) *Iterator {
cIter := C.rocksdb_create_iterator_cf(db.c, opts.c, cf.c)
return newNativeIterator(cIter)
return newNativeIteratorWithTS(cIter, opts.timestamp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a few other bytes fields in ReadOptions, need to handle in a similar way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if it's ok with this direction

}

// NewIterators returns iterators from a consistent database state across multiple
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/linxGnu/grocksdb

go 1.17

toolchain go1.23.6

require github.com/stretchr/testify v1.10.0

require (
Expand Down
8 changes: 7 additions & 1 deletion iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ import (
// return err
// }
type Iterator struct {
c *C.rocksdb_iterator_t
c *C.rocksdb_iterator_t
timestamp []byte
}

// NewNativeIterator creates a Iterator object.
func newNativeIterator(c *C.rocksdb_iterator_t) *Iterator {
return &Iterator{c: c}
}

// newNativeIteratorWithTS creates a Iterator object with ts.
func newNativeIteratorWithTS(c *C.rocksdb_iterator_t, ts []byte) *Iterator {
return &Iterator{c: c, timestamp: ts}
}

// Valid returns false only when an Iterator has iterated past either the
// first or the last key in the database.
func (iter *Iterator) Valid() bool {
Expand Down