MCPcopy Create free account
hub / github.com/distributedio/titan / GetHash

Function GetHash

db/hash.go:39–62  ·  view source on GitHub ↗

GetHash returns a hash object, create new one if nonexists

(txn *Transaction, key []byte)

Source from the content-addressed store, hash-verified

37
38// GetHash returns a hash object, create new one if nonexists
39func GetHash(txn *Transaction, key []byte) (*Hash, error) {
40 hash := newHash(txn, key)
41 mkey := MetaKey(txn.db, key)
42 meta, err := txn.t.Get(mkey)
43 if err != nil {
44 if IsErrNotFound(err) {
45 return hash, nil
46 }
47 return nil, err
48 }
49 hmeta, err := DecodeHashMeta(meta)
50 if err != nil {
51 return nil, err
52 }
53 if IsExpired(&hmeta.Object, Now()) {
54 return hash, nil
55 }
56 if hmeta.Type != ObjectHash {
57 return nil, ErrTypeMismatch
58 }
59 hash.meta = hmeta
60 hash.exists = true
61 return hash, nil
62}
63
64//newHash creates a hash object
65func newHash(txn *Transaction, key []byte) *Hash {

Callers 3

getHashFunction · 0.85
TestGetHashFunction · 0.85
HashMethod · 0.85

Calls 7

newHashFunction · 0.85
MetaKeyFunction · 0.85
IsErrNotFoundFunction · 0.85
DecodeHashMetaFunction · 0.85
IsExpiredFunction · 0.85
NowFunction · 0.85
GetMethod · 0.80

Tested by 2

getHashFunction · 0.68
TestGetHashFunction · 0.68