MCPcopy Create free account
hub / github.com/blobcache/blobcache / BeginTx

Method BeginTx

src/bccore/volapi.go:50–130  ·  view source on GitHub ↗
(ctx context.Context, volh blobcache.Handle, txspec blobcache.TxParams)

Source from the content-addressed store, hash-verified

48}
49
50func (sys *System) BeginTx(ctx context.Context, volh blobcache.Handle, txspec blobcache.TxParams) (*blobcache.Handle, error) {
51 logctx.Info(ctx, "begin", zap.String("method", "BeginTx"), zap.Stringer("oid", volh.OID))
52 defer logctx.Info(ctx, "done", zap.String("method", "BeginTx"), zap.Stringer("oid", volh.OID))
53 if err := txspec.Validate(); err != nil {
54 return nil, err
55 }
56 vol, rights, err := sys.resolveVol(volh)
57 if err != nil {
58 return nil, err
59 }
60 if !rights.Has(blobcache.Action_VOLUME_BEGIN_TX) {
61 return nil, blobcache.ErrPermission{
62 Handle: volh,
63 Rights: rights,
64 Requires: blobcache.Action_VOLUME_BEGIN_TX,
65 }
66 }
67 if txspec.GCBlobs {
68 gcBlobRights := blobcache.ActionSet(blobcache.Action_VOLUME_TX_VISIT | blobcache.Action_VOLUME_TX_IS_VISITED)
69 if rights&gcBlobRights == 0 {
70 return nil, blobcache.ErrPermission{
71 Handle: volh,
72 Rights: rights,
73 Requires: gcBlobRights,
74 }
75 }
76 }
77 if txspec.Modify {
78 mutatingRights := blobcache.ActionSet(blobcache.Action_VOLUME_TX_SAVE |
79 blobcache.Action_VOLUME_TX_POST |
80 blobcache.Action_VOLUME_TX_DELETE |
81 blobcache.Action_VOLUME_TX_COPY_TO |
82 blobcache.Action_VOLUME_TX_LINK_FROM |
83 blobcache.Action_VOLUME_TX_UNLINK_FROM |
84 blobcache.Action_VOLUME_TX_VISIT |
85 blobcache.Action_VOLUME_TX_VISIT_LINKS)
86 if rights&mutatingRights == 0 {
87 return nil, blobcache.ErrPermission{
88 Handle: volh,
89 Rights: rights,
90 Requires: mutatingRights,
91 }
92 }
93 }
94 tx, err := vol.backend.BeginTx(ctx, txspec)
95 if err != nil {
96 return nil, err
97 }
98
99 txoid := blobcache.RandomOID()
100 sys.mu.Lock()
101 if sys.txns == nil {
102 sys.txns = make(map[blobcache.OID]transaction)
103 }
104 sys.txns[txoid] = transaction{
105 backend: tx,
106 volume: &vol,
107 }

Callers

nothing calls this directly

Calls 13

resolveVolMethod · 0.95
ActionSetTypeAlias · 0.92
RandomOIDFunction · 0.92
SharedActionFunction · 0.92
InfoMethod · 0.80
HasMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
StringMethod · 0.65
BeginTxMethod · 0.65
AddMethod · 0.65
ValidateMethod · 0.45

Tested by

no test coverage detected