2014-08-25 10:18:23 +04:00
|
|
|
// +build rocksdb
|
|
|
|
|
|
|
|
package rocksdb
|
|
|
|
|
|
|
|
// #cgo LDFLAGS: -lrocksdb
|
|
|
|
// #include "rocksdb/c.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2020-04-24 09:10:03 +03:00
|
|
|
"github.com/ledisdb/ledisdb/store/driver"
|
2014-08-25 10:18:23 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Snapshot struct {
|
|
|
|
db *DB
|
|
|
|
snap *C.rocksdb_snapshot_t
|
|
|
|
readOpts *ReadOptions
|
|
|
|
iteratorOpts *ReadOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Snapshot) Get(key []byte) ([]byte, error) {
|
|
|
|
return s.db.get(s.readOpts, key)
|
|
|
|
}
|
|
|
|
|
2014-10-29 05:29:35 +03:00
|
|
|
func (s *Snapshot) GetSlice(key []byte) (driver.ISlice, error) {
|
|
|
|
return s.db.getSlice(s.readOpts, key)
|
|
|
|
}
|
|
|
|
|
2014-08-25 10:18:23 +04:00
|
|
|
func (s *Snapshot) NewIterator() driver.IIterator {
|
|
|
|
it := new(Iterator)
|
|
|
|
it.it = C.rocksdb_create_iterator(s.db.db, s.db.iteratorOpts.Opt)
|
|
|
|
return it
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Snapshot) Close() {
|
|
|
|
C.rocksdb_release_snapshot(s.db.db, s.snap)
|
|
|
|
s.iteratorOpts.Close()
|
|
|
|
s.readOpts.Close()
|
|
|
|
}
|