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

Method SubToVolume

src/bccore/pubsub.go:17–41  ·  view source on GitHub ↗

SubToVolume subscribes vol to q. This allows aribtrary volumes to be subscribed to arbitrary queues, but this is not the correct thing for a Node to do in the general case, Nodes should forward subscriptions to remote Volumes and Queues when both are on the same Node.

(ctx context.Context, qh blobcache.Handle, volh blobcache.Handle, spec blobcache.VolSubSpec)

Source from the content-addressed store, hash-verified

15// Nodes should forward subscriptions to remote Volumes and Queues when both
16// are on the same Node.
17func (sys *System) SubToVolume(ctx context.Context, qh blobcache.Handle, volh blobcache.Handle, spec blobcache.VolSubSpec) error {
18 _, rights, err := sys.resolveVol(volh)
19 if err != nil {
20 return err
21 }
22 q, rights, err := sys.resolveQueue(qh, blobcache.Action_QUEUE_SUB_VOLUME)
23 if err != nil {
24 return err
25 }
26 sys.mu.Lock()
27 defer sys.mu.Unlock()
28 sub := sys.hub.Subscribe(volh.OID, func(ctx context.Context, k blobcache.OID, v *volume) {
29 // TODO: use rights to tailor message
30 _ = rights
31 msg := blobcache.Message{}
32 _, err := q.backend.Enqueue(ctx, []blobcache.Message{msg})
33 if err != nil {
34 logctx.Warn(ctx, "during subscription callback", zap.Error(err))
35 }
36 })
37 // add the sub to the set of subs on the queue
38 q.subs[sub] = struct{}{}
39 // when q goes down, also need to unsubscribe the subs
40 return nil
41}
42
43type hub struct {
44 // mu guards pubs

Callers

nothing calls this directly

Calls 7

resolveVolMethod · 0.95
resolveQueueMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
SubscribeMethod · 0.80
EnqueueMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected