MCPcopy Create free account
hub / github.com/coder/coder / newQuerier

Function newQuerier

enterprise/tailnet/pgcoord.go:893–940  ·  view source on GitHub ↗
(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,
)

Source from the content-addressed store, hash-verified

891}
892
893func 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
942func (q *querier) wait() {
943 q.wg.Wait()

Callers 1

newPGCoordInternalFunction · 0.85

Calls 8

subscribeMethod · 0.95
handleIncomingMethod · 0.95
handleUpdatesMethod · 0.95
mappingWorkerMethod · 0.95
peerUpdateWorkerMethod · 0.95
newHeartbeatsFunction · 0.85
NamedMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected