// TriggerChord flags chord as triggered in the backend storage to make sure
// chord is never triggered multiple times. Returns a boolean flag to indicate
// whether the worker should trigger chord (true) or no if it has been triggered
// already (false)
558523
func (b *Backend) TriggerChord(groupUUID string) (bool, error) {
	query := bson.M{
		"_id":             groupUUID,
		"chord_triggered": false,
	}
	change := bson.M{
		"$set": bson.M{
			"chord_triggered": true,
		},
	}

	_, err := b.groupMetasCollection.UpdateOne(context.Background(), query, change, options.Update())

	if err != nil {
		if err == mongo.ErrNoDocuments {
			log.WARNING.Printf("Chord already triggered for group %s", groupUUID)
			return false, nil
		}
		return false, err
	}
	return true, nil
}
304082
func (c *DOMDebugger) SetInstrumentationBreakpoint(eventName string) (*gcdmessage.ChromeResponse, error) {
	var v DOMDebuggerSetInstrumentationBreakpointParams
	v.EventName = eventName
	return c.SetInstrumentationBreakpointWithParams(&v)
}
1327500
func NoopTrigger(id, data string) Trigger {
	return Trigger{
		Id:      id,
		Payload: &Trigger_Noop{Noop: &api.NoopTrigger{Data: data}},
	}
}
789978
func (c Cell) vertexChordDist2(p Point, xHi, yHi bool) s1.ChordAngle {
	x := c.uv.X.Lo
	y := c.uv.Y.Lo
	if xHi {
		x = c.uv.X.Hi
	}
	if yHi {
		y = c.uv.Y.Hi
	}

	return ChordAngleBetweenPoints(p, PointFromCoords(x, y, 1))
}
864519
func (c *FindCache) triggerBackoff() {
	log.Infof("memory-idx: findCache invalidate-queue full. Disabling cache for %s", c.backoffTime.String())
	findCacheBackoff.Inc()
	c.backoff = true
	time.AfterFunc(c.backoffTime, func() {
		findCacheBackoff.Dec()
		c.Lock()
		c.backoff = false
		c.Unlock()
	})
	c.cache = make(map[uint32]*lru.Cache)
	// drain queue
L:
	for {
		select {
		case <-c.invalidateReqs:
		default:
			break L
		}
	}
}
495124
func minChordAngle(x s1.ChordAngle, others ...s1.ChordAngle) s1.ChordAngle {
	min := x
	for _, y := range others {
		if y < min {
			min = y
		}
	}
	return min
}
1163706
func (r *RestartTracker) SetRestartTriggered(failure bool) *RestartTracker {
	r.lock.Lock()
	defer r.lock.Unlock()
	if failure {
		r.failure = true
	} else {
		r.restartTriggered = true
	}
	return r
}
142180
func AnnotateSpanWithChordInfo(span opentracing.Span, chord *tasks.Chord, sendConcurrency int) {
	// tag the span with chord specific info
	span.SetTag("chord.callback.uuid", chord.Callback.UUID)

	// inject the tracing span into the callback signature
	chord.Callback.Headers = HeadersWithSpan(chord.Callback.Headers, span)

	// tag the span for the group part of the chord
	AnnotateSpanWithGroupInfo(span, chord.Group, sendConcurrency)
}
839095
func (m *systemdUnitManager) TriggerStop(name string) error {
	jobID, err := m.systemd.StopUnit(name, "replace", nil)
	if err != nil {
		log.Errorf("Failed to trigger systemd unit %s stop: %v", name, err)
		return err
	}
	log.Infof("Triggered systemd unit %s stop: job=%d", name, jobID)
	return nil
}
666012
func triggerCacheIndexer(obj interface{}) ([]string, error) {
	entry := obj.(*trigger.CacheEntry)
	var keys []string
	for _, t := range entry.Triggers {
		if t.From.Kind != "ImageStreamTag" || len(t.From.APIVersion) != 0 || t.Paused {
			continue
		}
		name, _, ok := imageapi.SplitImageStreamTag(t.From.Name)
		if !ok {
			continue
		}
		namespace := t.From.Namespace
		if len(namespace) == 0 {
			namespace = entry.Namespace
		}
		keys = append(keys, namespace+"/"+name)
	}
	return keys, nil
}
1106972
func (r *Reflector) resyncChan() (<-chan time.Time, func() bool) {
	if r.resyncPeriod == 0 {
		r.nextResync = time.Time{}
		return neverExitWatch, func() bool { return false }
	}
	// The cleanup function is required: imagine the scenario where watches
	// always fail so we end up listing frequently. Then, if we don't
	// manually stop the timer, we could end up with many timers active
	// concurrently.
	r.nextResync = r.now().Add(r.resyncPeriod)
	t := time.NewTimer(r.resyncPeriod)
	return t.C, t.Stop
}
809357
func registerCallback(cbArg *callbackArg) uintptr {
	callbacksLock.Lock()
	defer callbacksLock.Unlock()
	cbArg.id = nextCallbackID
	nextCallbackID++
	if _, ok := callbacks[cbArg.id]; ok {
		panic(fmt.Sprintf("Callback ID %d already in use", cbArg.id))
	}
	callbacks[cbArg.id] = cbArg
	return cbArg.id
}
1025545
func NewTrigger(p Parameters) (*Trigger, error) {
	if p.sleepInterval == 0 {
		p.sleepInterval = time.Second
	}

	if p.TriggerFunc == nil {
		return nil, fmt.Errorf("trigger function is nil")
	}

	if p.PrometheusMetrics && p.Name == "" {
		return nil, fmt.Errorf("trigger name must be provided when enabling metrics")
	}

	t := &Trigger{
		params:        p,
		wakeupChan:    make(chan bool, 1),
		closeChan:     make(chan struct{}, 1),
		foldedReasons: newReasonStack(),
	}

	// Guarantee that initial trigger has no delay
	if p.MinInterval > time.Duration(0) {
		t.lastTrigger = time.Now().Add(-1 * p.MinInterval)
	}

	if p.PrometheusMetrics {
		t.triggerReasons = prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: metrics.Namespace,
			Subsystem: "triggers",
			Name:      p.Name + "_total",
			Help:      "Total number of trigger invocations labelled by reason",
		}, []string{metricLabelReason})

		if err := metrics.Register(t.triggerReasons); err != nil {
			return nil, fmt.Errorf("unable to register prometheus collector: %s", err)
		}

		t.triggerFolds = prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: metrics.Namespace,
			Subsystem: "triggers",
			Name:      p.Name + "_folds",
			Help:      "Current level of trigger folds",
		})

		if err := metrics.Register(t.triggerFolds); err != nil {
			metrics.Unregister(t.triggerReasons)
			return nil, fmt.Errorf("unable to register prometheus collector: %s", err)
		}

		t.callDurations = prometheus.NewHistogramVec(prometheus.HistogramOpts{
			Namespace: metrics.Namespace,
			Subsystem: "triggers",
			Name:      p.Name + "_call_duration_seconds",
			Help:      "Length of duration trigger used to execute",
		}, []string{"type"})

		if err := metrics.Register(t.callDurations); err != nil {
			metrics.Unregister(t.triggerReasons)
			metrics.Unregister(t.triggerFolds)
			return nil, err
		}
	}

	go t.waiter()

	return t, nil
}
681389
func (self *Service) CreateTrigger(createRequest TriggerCreateRequest) (Trigger, error) {

	url := "service/" + self.Uuid + "/trigger/"
	request := "POST"
	var response Trigger

	newTrigger, err := json.Marshal(createRequest)
	if err != nil {
		return response, err
	}

	data, err := TutumCall(url, request, newTrigger)
	if err != nil {
		return response, err
	}

	err = json.Unmarshal(data, &response)
	if err != nil {
		return response, err
	}

	return response, nil
}
121385
func (client *Client) SetLoadBalancerTCPListenerAttribute(args *SetLoadBalancerTCPListenerAttributeArgs) (err error) {
	response := &CommonLoadBalancerListenerResponse{}
	err = client.Invoke("SetLoadBalancerTCPListenerAttribute", args, response)
	return err
}
56180
func (m *HeaderCtxFlag) FlagStr() string {
	m.mu.RLock()
	ret := m.expectedVal
	m.mu.RUnlock()
	return ret
}
1128791
func (server *Server) SendChord(chord *tasks.Chord, sendConcurrency int) (*result.ChordAsyncResult, error) {
	return server.SendChordWithContext(context.Background(), chord, sendConcurrency)
}