MCPcopy
hub / github.com/canopy-network/canopy / Get

Method Get

store/txn.go:107–120  ·  view source on GitHub ↗

Get() retrieves the value for a given key from either the txn operations or the reader store

(key []byte)

Source from the content-addressed store, hash-verified

105
106// Get() retrieves the value for a given key from either the txn operations or the reader store
107func (t *Txn) Get(key []byte) ([]byte, lib.ErrorI) {
108 t.txn.l.Lock()
109 defer t.txn.l.Unlock()
110 // first retrieve from the in-memory txn
111 if v, found := t.txn.ops[lib.MemHash(key)]; found {
112 if v.op == opDelete {
113 return nil, nil
114 }
115 // TODO: should a sentinel value be returned when a key is found but the value is nil
116 return v.value, nil
117 }
118 // if not found, retrieve from the parent reader
119 return t.reader.Get(lib.AppendWithBuffer(&t.txn.rbuf, t.prefix, key))
120}
121
122// Set() adds or updates the value for a key in the txn operations
123func (t *Txn) Set(key, value []byte) lib.ErrorI {

Callers 3

getLatestCommitIDFunction · 0.95
TestDoublyNestedTxnFunction · 0.95
TestNestedTxnFunction · 0.95

Calls 5

MemHashFunction · 0.92
AppendWithBufferFunction · 0.92
LockMethod · 0.80
UnlockMethod · 0.80
GetMethod · 0.65

Tested by 2

TestDoublyNestedTxnFunction · 0.76
TestNestedTxnFunction · 0.76