// doGC6 iterates through a CTv6 map and drops entries based on the given
// filter.
557466
func doGC6(m *Map, filter *GCFilter) gcStats {
	natMap := mapInfo[m.mapType].natMap
	stats := statStartGc(m)
	defer stats.finish()

	err := natMap.Open()
	if err == nil {
		defer natMap.Close()
	} else {
		natMap = nil
	}

	filterCallback := func(key bpf.MapKey, value bpf.MapValue) {
		currentKey := key.(*tuple.TupleKey6Global)
		entry := value.(*CtEntry)

		// In CT entries, the source address of the conntrack entry (`SourceAddr`) is
		// the destination of the packet received, therefore it's the packet's
		// destination IP
		action := filter.doFiltering(currentKey.DestAddr.IP(), currentKey.SourceAddr.IP(), currentKey.SourcePort,
			uint8(currentKey.NextHeader), currentKey.Flags, entry)

		switch action {
		case deleteEntry:
			err := purgeCtEntry6(m, currentKey, natMap)
			if err != nil {
				log.WithError(err).WithField(logfields.Key, currentKey.String()).Error("Unable to delete CT entry")
			} else {
				stats.deleted++
			}
		default:
			stats.aliveEntries++
		}
	}
	stats.dumpError = m.DumpReliablyWithCallback(filterCallback, stats.DumpStats)

	return stats
}
425309
func (w *gcTaskWorker) doGCForRegion(bo *tikv.Backoffer, safePoint uint64, region tikv.RegionVerID) (*errorpb.Error, error) {
	req := &tikvrpc.Request{
		Type: tikvrpc.CmdGC,
		GC: &kvrpcpb.GCRequest{
			SafePoint: safePoint,
		},
	}

	resp, err := w.store.SendReq(bo, req, region, tikv.GCTimeout)
	if err != nil {
		return nil, errors.Trace(err)
	}
	regionErr, err := resp.GetRegionError()
	if err != nil {
		return nil, errors.Trace(err)
	}
	if regionErr != nil {
		return regionErr, nil
	}

	gcResp := resp.GC
	if gcResp == nil {
		return nil, errors.Trace(tikv.ErrBodyMissing)
	}
	if gcResp.GetError() != nil {
		return nil, errors.Errorf("unexpected gc error: %s", gcResp.GetError())
	}

	return nil, nil
}
1176956
func (f *aclFilter) filterNodeServices(services **structs.NodeServices) {
	if *services == nil {
		return
	}

	if !f.allowNode((*services).Node.Node) {
		*services = nil
		return
	}

	for svc := range (*services).Services {
		if f.allowService(svc) {
			continue
		}
		f.logger.Printf("[DEBUG] consul: dropping service %q from result due to ACLs", svc)
		delete((*services).Services, svc)
	}
}
628180
func (o *MultiCastList) MultiCastChannelMaps(info *bambou.FetchingInfo) (MultiCastChannelMapsList, *bambou.Error) {

	var list MultiCastChannelMapsList
	err := bambou.CurrentSession().FetchChildren(o, MultiCastChannelMapIdentity, &list, info)
	return list, err
}
192223
func (ed *Dispatcher) clearChaincodeRegistrations(closeChannel bool) {
	if closeChannel {
		for _, reg := range ed.ccRegistrations {
			logger.Debugf("Closing chaincode registration event channel for CC ID [%s] and event filter [%s].", reg.ChaincodeID, reg.EventFilter)
			close(reg.Eventch)
		}
	}
	ed.ccRegistrations = make(map[string]*ChaincodeReg)
}
1142025
func DeleteRuleIPv6(fwmark int, table int) error {
	rule := netlink.NewRule()
	rule.Mark = fwmark
	rule.Table = table
	rule.Family = netlink.FAMILY_V6
	return netlink.RuleDel(rule)
}
438860
func FilterUndeletedSeriesIDIterator(sfile *SeriesFile, itr SeriesIDIterator) (SeriesIDIterator, error) {
	if itr == nil {
		return nil, nil
	}
	sfileref, err := sfile.Acquire()
	if err != nil {
		return nil, err
	}
	return &filterUndeletedSeriesIDIterator{
		sfile:    sfile,
		sfileref: sfileref,
		itr:      itr,
	}, nil
}
1058871
func (pmux *PubSubMux) ClosePubCh(channel string) bool {
	pmux.muxLock.Lock()
	defer pmux.muxLock.Unlock()

	p, ok := pmux.mux[channel]
	if !ok {
		return false
	}

	close(p.src)
	delete(pmux.mux, channel)
	return true
}
968920
func (c *ChiMergeFilter) GetAttributesAfterFiltering() []base.FilteredAttribute {
	oldAttrs := c.train.AllAttributes()
	ret := make([]base.FilteredAttribute, len(oldAttrs))
	for i, a := range oldAttrs {
		if c.attrs[a] {
			retAttr := new(base.CategoricalAttribute)
			retAttr.SetName(a.GetName())
			for _, k := range c.tables[a] {
				retAttr.GetSysValFromString(fmt.Sprintf("%f", k.Value))
			}
			ret[i] = base.FilteredAttribute{a, retAttr}
		} else {
			ret[i] = base.FilteredAttribute{a, a}
		}
	}
	return ret
}
1182785
func (c *Cluster) Clear() {
	c.mu.Lock()

	c.members = make(map[uint64]*Member)
	c.removed = make(map[uint64]bool)
	c.mu.Unlock()
}
985707
func (api *RegionAPI) FilterMultiBy(key string, value interface{}) *RegionAPI {
	api.filterBy(key, value, true)
	return api
}
480626
func (dd *DatadogMetricSink) FlushOtherSamples(ctx context.Context, samples []ssf.SSFSample) {

	events := []DDEvent{}

	span, _ := trace.StartSpanFromContext(ctx, "")
	defer span.ClientFinish(dd.traceClient)

	// fill in the default hostname for packets that didn't set it
	for _, sample := range samples {

		if _, ok := sample.Tags[dogstatsd.EventIdentifierKey]; ok {
			// This is an event!
			ret := DDEvent{
				Title:     sample.Name,
				Text:      sample.Message,
				Timestamp: sample.Timestamp,
				Priority:  "normal",
				AlertType: "info",
			}

			// Defensively copy the tags that came in
			tags := map[string]string{}
			for k, v := range sample.Tags {
				tags[k] = v
			}
			// Remove the tag that flagged this as an event
			delete(tags, dogstatsd.EventIdentifierKey)

			// The parser uses special tags to encode the fields for us from DogStatsD
			// that don't fit into a normal SSF Sample. We'll hunt for each one and
			// delete the tag if we find it.
			if v, ok := tags[dogstatsd.EventAggregationKeyTagKey]; ok {
				ret.Aggregation = v
				delete(tags, dogstatsd.EventAggregationKeyTagKey)
			}
			if v, ok := tags[dogstatsd.EventPriorityTagKey]; ok {
				ret.Priority = v
				delete(tags, dogstatsd.EventPriorityTagKey)
			}
			if v, ok := tags[dogstatsd.EventSourceTypeTagKey]; ok {
				ret.Source = v
				delete(tags, dogstatsd.EventSourceTypeTagKey)
			}
			if v, ok := tags[dogstatsd.EventAlertTypeTagKey]; ok {
				ret.AlertType = v
				delete(tags, dogstatsd.EventAlertTypeTagKey)
			}
			if v, ok := tags[dogstatsd.EventHostnameTagKey]; ok {
				ret.Hostname = v
				delete(tags, dogstatsd.EventHostnameTagKey)
			} else {
				// Default hostname since there isn't one
				ret.Hostname = dd.hostname
			}
			// Do our last bit of tag housekeeping
			finalTags := []string{}
			for k, v := range tags {
				finalTags = append(finalTags, fmt.Sprintf("%s:%s", k, v))
			}

			ret.Tags = append(finalTags, dd.tags...)
			events = append(events, ret)
		} else {
			dd.log.Warn("Received an SSF Sample that wasn't an event or service check, ack!")
		}
	}

	if len(events) != 0 {
		// this endpoint is not documented at all, its existence is only known from
		// the official dd-agent
		// we don't actually pass all the body keys that dd-agent passes here... but
		// it still works
		err := vhttp.PostHelper(context.Background(), dd.HTTPClient, dd.traceClient, http.MethodPost, fmt.Sprintf("%s/intake?api_key=%s", dd.DDHostname, dd.APIKey), map[string]map[string][]DDEvent{
			"events": {
				"api": events,
			},
		}, "flush_events", true, map[string]string{"sink": "datadog"}, dd.log)

		if err == nil {
			dd.log.WithField("events", len(events)).Info("Completed flushing events to Datadog")
		} else {
			dd.log.WithFields(logrus.Fields{
				"events":        len(events),
				logrus.ErrorKey: err}).Warn("Error flushing events to Datadog")
		}
	}
}
1296008
func (sm *ServiceMap) filter(other ServiceMap) {
	for svcPortName := range *sm {
		// skip the delete for Update event.
		if _, ok := other[svcPortName]; ok {
			delete(*sm, svcPortName)
		}
	}
}
1138269
func ListByFilter(ctx context.Context, clientInstance client.ContainerAPIClient, containerFilters ...map[string][]string) ([]types.Container, error) {
	filterArgs := filters.NewArgs()

	// FIXME(vdemeester) I don't like 3 for loops >_<
	for _, filter := range containerFilters {
		for key, filterValue := range filter {
			for _, value := range filterValue {
				filterArgs.Add(key, value)
			}
		}
	}

	return clientInstance.ContainerList(ctx, types.ContainerListOptions{
		All:     true,
		Filters: filterArgs,
	})
}
830942
func gorocksdb_compactionfilter_filter(idx int, cLevel C.int, cKey *C.char, cKeyLen C.size_t, cVal *C.char, cValLen C.size_t, cNewVal **C.char, cNewValLen *C.size_t, cValChanged *C.uchar) C.int {
	key := charToByte(cKey, cKeyLen)
	val := charToByte(cVal, cValLen)

	remove, newVal := compactionFilters.Get(idx).(compactionFilterWrapper).filter.Filter(int(cLevel), key, val)
	if remove {
		return C.int(1)
	} else if newVal != nil {
		*cNewVal = byteToChar(newVal)
		*cNewValLen = C.size_t(len(newVal))
		*cValChanged = C.uchar(1)
	}
	return C.int(0)
}
1155625
func deleteMultiMutator(shardClient Client, mapping *ShardMapping) []MutateResponse {
	return shardClient.DeleteMulti(mapping.Keys)
}
1276591
func FilterInt64(s []int64, cb func(s int64) bool) []int64 {
	results := []int64{}

	for _, i := range s {
		result := cb(i)

		if result {
			results = append(results, i)
		}
	}

	return results
}