kv_view.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "github.com/coreos/etcd/internal/lease"
  16. type readView struct{ kv KV }
  17. func (rv *readView) FirstRev() int64 {
  18. tr := rv.kv.Read()
  19. defer tr.End()
  20. return tr.FirstRev()
  21. }
  22. func (rv *readView) Rev() int64 {
  23. tr := rv.kv.Read()
  24. defer tr.End()
  25. return tr.Rev()
  26. }
  27. func (rv *readView) Range(key, end []byte, ro RangeOptions) (r *RangeResult, err error) {
  28. tr := rv.kv.Read()
  29. defer tr.End()
  30. return tr.Range(key, end, ro)
  31. }
  32. type writeView struct{ kv KV }
  33. func (wv *writeView) DeleteRange(key, end []byte) (n, rev int64) {
  34. tw := wv.kv.Write()
  35. defer tw.End()
  36. return tw.DeleteRange(key, end)
  37. }
  38. func (wv *writeView) Put(key, value []byte, lease lease.LeaseID) (rev int64) {
  39. tw := wv.kv.Write()
  40. defer tw.End()
  41. return tw.Put(key, value, lease)
  42. }