From 9d007e481048296f09f59bd19bb7ae584563cd95 Mon Sep 17 00:00:00 2001 From: Suryandaru Triandana Date: Fri, 22 Feb 2019 12:17:00 +0700 Subject: [PATCH] docs: add warning regarding iterator buffer usage (fixes #258) --- leveldb/db.go | 4 ++++ leveldb/db_snapshot.go | 4 ++++ leveldb/db_transaction.go | 4 ++++ leveldb/memdb/memdb.go | 4 ++++ leveldb/table/reader.go | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/leveldb/db.go b/leveldb/db.go index b27c38d3..90fedf7b 100644 --- a/leveldb/db.go +++ b/leveldb/db.go @@ -872,6 +872,10 @@ func (db *DB) Has(key []byte, ro *opt.ReadOptions) (ret bool, err error) { // DB. And a nil Range.Limit is treated as a key after all keys in // the DB. // +// WARNING: Any slice returned by interator (e.g. slice returned by calling +// Iterator.Key() or Iterator.Key() methods), its content should not be modified +// unless noted otherwise. +// // The iterator must be released after use, by calling Release method. // // Also read Iterator documentation of the leveldb/iterator package. diff --git a/leveldb/db_snapshot.go b/leveldb/db_snapshot.go index 2c69d2e5..c2ad70c8 100644 --- a/leveldb/db_snapshot.go +++ b/leveldb/db_snapshot.go @@ -142,6 +142,10 @@ func (snap *Snapshot) Has(key []byte, ro *opt.ReadOptions) (ret bool, err error) // DB. And a nil Range.Limit is treated as a key after all keys in // the DB. // +// WARNING: Any slice returned by interator (e.g. slice returned by calling +// Iterator.Key() or Iterator.Value() methods), its content should not be +// modified unless noted otherwise. +// // The iterator must be released after use, by calling Release method. // Releasing the snapshot doesn't mean releasing the iterator too, the // iterator would be still valid until released. diff --git a/leveldb/db_transaction.go b/leveldb/db_transaction.go index b8f7e7d2..1a000018 100644 --- a/leveldb/db_transaction.go +++ b/leveldb/db_transaction.go @@ -69,6 +69,10 @@ func (tr *Transaction) Has(key []byte, ro *opt.ReadOptions) (bool, error) { // DB. And a nil Range.Limit is treated as a key after all keys in // the DB. // +// WARNING: Any slice returned by interator (e.g. slice returned by calling +// Iterator.Key() or Iterator.Key() methods), its content should not be modified +// unless noted otherwise. +// // The iterator must be released after use, by calling Release method. // // Also read Iterator documentation of the leveldb/iterator package. diff --git a/leveldb/memdb/memdb.go b/leveldb/memdb/memdb.go index b661c08a..824e47f5 100644 --- a/leveldb/memdb/memdb.go +++ b/leveldb/memdb/memdb.go @@ -397,6 +397,10 @@ func (p *DB) Find(key []byte) (rkey, value []byte, err error) { // DB. And a nil Range.Limit is treated as a key after all keys in // the DB. // +// WARNING: Any slice returned by interator (e.g. slice returned by calling +// Iterator.Key() or Iterator.Key() methods), its content should not be modified +// unless noted otherwise. +// // The iterator must be released after use, by calling Release method. // // Also read Iterator documentation of the leveldb/iterator package. diff --git a/leveldb/table/reader.go b/leveldb/table/reader.go index 16cfbaa0..496feb6f 100644 --- a/leveldb/table/reader.go +++ b/leveldb/table/reader.go @@ -787,6 +787,10 @@ func (r *Reader) getDataIterErr(dataBH blockHandle, slice *util.Range, verifyChe // table. And a nil Range.Limit is treated as a key after all keys in // the table. // +// WARNING: Any slice returned by interator (e.g. slice returned by calling +// Iterator.Key() or Iterator.Key() methods), its content should not be modified +// unless noted otherwise. +// // The returned iterator is not safe for concurrent use and should be released // after use. //