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)
| 15 | // Nodes should forward subscriptions to remote Volumes and Queues when both |
| 16 | // are on the same Node. |
| 17 | func (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 | |
| 43 | type hub struct { |
| 44 | // mu guards pubs |
nothing calls this directly
no test coverage detected