Esempio n. 1
0
File: db.go Progetto: 29n/goleveldb
// Get get value for given key of the latest snapshot of database.
func (d *DB) Get(key []byte, ro *opt.ReadOptions) (value []byte, err error) {
	err = d.rok()
	if err != nil {
		return
	}

	value, err = d.get(key, d.getSeq(), ro)
	if ro.HasFlag(opt.RFDontCopyBuffer) {
		return
	}
	return dupBytes(value), err
}
Esempio n. 2
0
// NewIterator return an iterator over the contents of this snapshot of
// database.
//
// Please note that the iterator is not thread-safe, you may not use same
// iterator instance concurrently without external synchronization.
func (p *Snapshot) NewIterator(ro *opt.ReadOptions) iterator.Iterator {
	if atomic.LoadUint32(&p.released) != 0 {
		return &iterator.EmptyIterator{errors.ErrSnapshotReleased}
	}

	d := p.d

	if err := d.rok(); err != nil {
		return &iterator.EmptyIterator{err}
	}

	return &dbIter{
		snap:       p,
		cmp:        d.s.cmp.cmp,
		it:         d.newRawIterator(ro),
		seq:        p.entry.seq,
		copyBuffer: !ro.HasFlag(opt.RFDontCopyBuffer),
	}
}