kv_view.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2017 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package mvcc
  15. import (
  16. "github.com/coreos/etcd/lease"
  17. )
  18. type readView struct{ kv KV }
  19. func (rv *readView) FirstRev() int64 {
  20. tr := rv.kv.Read()
  21. defer tr.End()
  22. return tr.FirstRev()
  23. }
  24. func (rv *readView) Rev() int64 {
  25. tr := rv.kv.Read()
  26. defer tr.End()
  27. return tr.Rev()
  28. }
  29. func (rv *readView) Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) {
  30. tr := rv.kv.Read()
  31. defer tr.End()
  32. return tr.Range(key, end, ro)
  33. }
  34. type writeView struct{ kv KV }
  35. func (wv *writeView) DeleteRange(key, end []byte) (n, rev int64) {
  36. tw := wv.kv.Write()
  37. defer tw.End()
  38. return tw.DeleteRange(key, end)
  39. }
  40. func (wv *writeView) Put(key, value []byte, lease lease.LeaseID) (rev int64) {
  41. tw := wv.kv.Write()
  42. defer tw.End()
  43. return tw.Put(key, value, lease)
  44. }