(ctx context.Context,
logger slog.Logger,
coordinatorID uuid.UUID,
ps pubsub.Pubsub,
store database.Store,
self uuid.UUID,
newConnections chan *connIO,
closeConnections chan *connIO,
numWorkers int,
firstHeartbeat chan struct{},
clk quartz.Clock,
)
| 891 | } |
| 892 | |
| 893 | func newQuerier(ctx context.Context, |
| 894 | logger slog.Logger, |
| 895 | coordinatorID uuid.UUID, |
| 896 | ps pubsub.Pubsub, |
| 897 | store database.Store, |
| 898 | self uuid.UUID, |
| 899 | newConnections chan *connIO, |
| 900 | closeConnections chan *connIO, |
| 901 | numWorkers int, |
| 902 | firstHeartbeat chan struct{}, |
| 903 | clk quartz.Clock, |
| 904 | ) *querier { |
| 905 | updates := make(chan hbUpdate) |
| 906 | q := &querier{ |
| 907 | ctx: ctx, |
| 908 | logger: logger.Named("querier"), |
| 909 | coordinatorID: coordinatorID, |
| 910 | pubsub: ps, |
| 911 | store: store, |
| 912 | newConnections: newConnections, |
| 913 | closeConnections: closeConnections, |
| 914 | peerUpdateQ: newWorkQ[uuid.UUID](ctx), |
| 915 | mappingQ: newWorkQ[mKey](ctx), |
| 916 | heartbeats: newHeartbeats(ctx, logger, ps, store, self, updates, firstHeartbeat, clk), |
| 917 | mappers: make(map[mKey]*mapper), |
| 918 | updates: updates, |
| 919 | healthy: true, // assume we start healthy |
| 920 | } |
| 921 | q.subscribe() |
| 922 | |
| 923 | // For an odd number of workers we allocate more to the mapping workers since they're busier. |
| 924 | mappingWorkers := int(math.Ceil(float64(numWorkers) / 2)) |
| 925 | peerWorkers := numWorkers - mappingWorkers |
| 926 | |
| 927 | q.wg.Add(2 + mappingWorkers + peerWorkers) |
| 928 | go func() { |
| 929 | <-firstHeartbeat |
| 930 | go q.handleIncoming() |
| 931 | go q.handleUpdates() |
| 932 | for range mappingWorkers { |
| 933 | go q.mappingWorker() |
| 934 | } |
| 935 | for range peerWorkers { |
| 936 | go q.peerUpdateWorker() |
| 937 | } |
| 938 | }() |
| 939 | return q |
| 940 | } |
| 941 | |
| 942 | func (q *querier) wait() { |
| 943 | q.wg.Wait() |
no test coverage detected