...

Source file src/go.etcd.io/etcd/server/v3/mvcc/kv_view.go

Documentation: go.etcd.io/etcd/server/v3/mvcc

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

View as plain text