2014-08-30 13:19:10 +04:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
2020-04-24 09:10:03 +03:00
|
|
|
"github.com/ledisdb/ledisdb/store/driver"
|
2014-08-30 13:19:10 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Snapshot struct {
|
|
|
|
driver.ISnapshot
|
2014-10-15 06:18:20 +04:00
|
|
|
st *Stat
|
2014-08-30 13:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Snapshot) NewIterator() *Iterator {
|
|
|
|
it := new(Iterator)
|
|
|
|
it.it = s.ISnapshot.NewIterator()
|
2014-10-15 06:18:20 +04:00
|
|
|
it.st = s.st
|
|
|
|
|
|
|
|
s.st.IterNum.Add(1)
|
2014-08-30 13:19:10 +04:00
|
|
|
|
|
|
|
return it
|
|
|
|
}
|
2014-10-15 06:18:20 +04:00
|
|
|
|
|
|
|
func (s *Snapshot) Get(key []byte) ([]byte, error) {
|
|
|
|
v, err := s.ISnapshot.Get(key)
|
|
|
|
s.st.statGet(v, err)
|
|
|
|
return v, err
|
|
|
|
}
|
|
|
|
|
2014-10-29 05:29:35 +03:00
|
|
|
func (s *Snapshot) GetSlice(key []byte) (Slice, error) {
|
|
|
|
if d, ok := s.ISnapshot.(driver.ISliceGeter); ok {
|
|
|
|
v, err := d.GetSlice(key)
|
|
|
|
s.st.statGet(v, err)
|
|
|
|
return v, err
|
2020-05-10 13:17:39 +03:00
|
|
|
}
|
|
|
|
v, err := s.Get(key)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if v == nil {
|
|
|
|
return nil, nil
|
2014-10-29 05:29:35 +03:00
|
|
|
} else {
|
2020-05-10 13:17:39 +03:00
|
|
|
return driver.GoSlice(v), nil
|
2014-10-29 05:29:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-15 06:18:20 +04:00
|
|
|
func (s *Snapshot) Close() {
|
|
|
|
s.st.SnapshotCloseNum.Add(1)
|
|
|
|
s.ISnapshot.Close()
|
|
|
|
}
|