go.etcd.io/etcd@v3.3.27+incompatible/mvcc/kv_view.go (about)

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