kv_view.go 1.4 KB

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