// NewConstFetch node constructor
973194
func NewConstFetch(Constant node.Node) *ConstFetch {
	return &ConstFetch{
		FreeFloating: nil,
		Constant:     Constant,
	}
}
780709
func NewConfig() Config {
	return Config{
		MaxConcurrentOpens: DefaultMaxConcurrentOpens,
		MADVWillNeed:       DefaultMADVWillNeed,

		Cache: CacheConfig{
			MaxMemorySize:             toml.Size(DefaultCacheMaxMemorySize),
			SnapshotMemorySize:        toml.Size(DefaultCacheSnapshotMemorySize),
			SnapshotWriteColdDuration: toml.Duration(DefaultCacheSnapshotWriteColdDuration),
		},
		Compaction: CompactionConfig{
			FullWriteColdDuration: toml.Duration(DefaultCompactFullWriteColdDuration),
			Throughput:            toml.Size(DefaultCompactThroughput),
			ThroughputBurst:       toml.Size(DefaultCompactThroughputBurst),
			MaxConcurrent:         DefaultCompactMaxConcurrent,
		},
	}
}
963317
func (n *NetStore) getOrCreateFetcher(ctx context.Context, ref Address) *fetcher {
	if f := n.getFetcher(ref); f != nil {
		return f
	}

	// no fetcher for the given address, we have to create a new one
	key := hex.EncodeToString(ref)
	// create the context during which fetching is kept alive
	cctx, cancel := context.WithTimeout(ctx, fetcherTimeout)
	// destroy is called when all requests finish
	destroy := func() {
		// remove fetcher from fetchers
		n.fetchers.Remove(key)
		// stop fetcher by cancelling context called when
		// all requests cancelled/timedout or chunk is delivered
		cancel()
	}
	// peers always stores all the peers which have an active request for the chunk. It is shared
	// between fetcher and the NewFetchFunc function. It is needed by the NewFetchFunc because
	// the peers which requested the chunk should not be requested to deliver it.
	peers := &sync.Map{}

	cctx, sp := spancontext.StartSpan(
		cctx,
		"netstore.fetcher",
	)

	sp.LogFields(olog.String("ref", ref.String()))
	fetcher := newFetcher(sp, ref, n.NewNetFetcherFunc(cctx, ref, peers), destroy, peers, n.closeC)
	n.fetchers.Add(key, fetcher)

	return fetcher
}
417397
func NewCachingFetcher(cache blobserver.Cache, fetcher blob.Fetcher) *CachingFetcher {
	return &CachingFetcher{c: cache, sf: fetcher}
}
165646
func NewPropertyFetch(Variable node.Node, Property node.Node) *PropertyFetch {
	return &PropertyFetch{
		FreeFloating: nil,
		Variable:     Variable,
		Property:     Property,
	}
}
1221025
func NewWithCache(server string, client *Client, cache cache.Cache) *Config {
	return &Config{
		Server: server,
		Client: client,
		cache:  cache,
	}
}
300983
func simpleFetch(ctx context.Context, gs []storage.Graph, cls *semantic.GraphClause, lo *storage.LookupOptions, stmLimit int64, chanSize int, w io.Writer) (*table.Table, error) {
	s, p, o := cls.S, cls.P, cls.O
	lo = updateTimeBounds(lo, cls)
	tbl, err := table.New(cls.Bindings())
	if err != nil {
		return nil, err
	}
	if s != nil && p != nil && o != nil {
		// Fully qualified triple.
		t, err := triple.New(s, p, o)
		if err != nil {
			return nil, err
		}
		tracer.Trace(w, func() []string {
			return []string{fmt.Sprintf("g.Exist(%v, %v)", t, lo)}
		})
		for _, g := range gs {
			b, err := g.Exist(ctx, t)
			if err != nil {
				return nil, err
			}
			if b {
				ts := make(chan *triple.Triple, 1)
				ts <- t
				close(ts)
				if err := addTriples(ts, cls, tbl); err != nil {
					return nil, err
				}
			}
		}
		return tbl, nil
	}
	if s != nil && p != nil && o == nil {
		// SP request.
		for _, g := range gs {
			var (
				oErr error
				aErr error
				lErr error
				wg   sync.WaitGroup
			)
			tracer.Trace(w, func() []string {
				return []string{fmt.Sprintf("g.Objects(%v, %v, %v)", s, p, lo)}
			})
			wg.Add(2)
			os := make(chan *triple.Object, chanSize)
			go func() {
				defer wg.Done()
				oErr = g.Objects(ctx, s, p, lo, os)
			}()
			ts := make(chan *triple.Triple, chanSize)
			go func() {
				defer wg.Done()
				aErr = addTriples(ts, cls, tbl)
			}()
			for o := range os {
				if lErr != nil {
					// Drain the channel to avoid leaking goroutines.
					continue
				}
				t, err := triple.New(s, p, o)
				if err != nil {
					lErr = err
					continue
				}
				ts <- t
			}
			close(ts)
			wg.Wait()
			if oErr != nil {
				return nil, oErr
			}
			if aErr != nil {
				return nil, aErr
			}
			if lErr != nil {
				return nil, lErr
			}
		}
		return tbl, nil
	}
	if s != nil && p == nil && o != nil {
		// SO request.
		for _, g := range gs {
			var (
				pErr error
				aErr error
				lErr error
				wg   sync.WaitGroup
			)
			tracer.Trace(w, func() []string {
				return []string{fmt.Sprintf("g.PredicatesForSubjectAndObject(%v, %v, %v)", s, o, lo)}
			})
			wg.Add(2)
			ps := make(chan *predicate.Predicate, chanSize)
			go func() {
				defer wg.Done()
				pErr = g.PredicatesForSubjectAndObject(ctx, s, o, lo, ps)
			}()
			ts := make(chan *triple.Triple, chanSize)
			go func() {
				defer wg.Done()
				aErr = addTriples(ts, cls, tbl)
			}()
			for p := range ps {
				if lErr != nil {
					// Drain the channel to avoid leaking goroutines.
					continue
				}
				t, err := triple.New(s, p, o)
				if err != nil {
					lErr = err
					continue
				}
				ts <- t
			}
			close(ts)
			wg.Wait()
			if pErr != nil {
				return nil, pErr
			}
			if aErr != nil {
				return nil, aErr
			}
			if lErr != nil {
				return nil, lErr
			}
		}
		return tbl, nil
	}
	if s == nil && p != nil && o != nil {
		// PO request.
		for _, g := range gs {
			var (
				pErr error
				aErr error
				lErr error
				wg   sync.WaitGroup
			)
			tracer.Trace(w, func() []string {
				return []string{fmt.Sprintf("g.Subjects(%v, %v, %v)", p, o, lo)}
			})
			wg.Add(2)
			ss := make(chan *node.Node, chanSize)
			go func() {
				defer wg.Done()
				pErr = g.Subjects(ctx, p, o, lo, ss)
			}()
			ts := make(chan *triple.Triple, chanSize)
			go func() {
				defer wg.Done()
				aErr = addTriples(ts, cls, tbl)
			}()
			for s := range ss {
				if lErr != nil {
					// Drain the channel to avoid leaking goroutines.
					continue
				}
				t, err := triple.New(s, p, o)
				if err != nil {
					lErr = err
					continue
				}
				ts <- t
			}
			close(ts)
			wg.Wait()
			if pErr != nil {
				return nil, pErr
			}
			if aErr != nil {
				return nil, aErr
			}
			if lErr != nil {
				return nil, lErr
			}
		}
		return tbl, nil
	}
	if s != nil && p == nil && o == nil {
		// S request.
		for _, g := range gs {
			var (
				tErr error
				aErr error
				wg   sync.WaitGroup
			)
			tracer.Trace(w, func() []string {
				return []string{fmt.Sprintf("g.TriplesForSubject(%v, %v)", s, lo)}
			})
			ts := make(chan *triple.Triple, chanSize)
			wg.Add(1)
			go func() {
				defer wg.Done()
				tErr = g.TriplesForSubject(ctx, s, lo, ts)
			}()
			aErr = addTriples(ts, cls, tbl)
			wg.Wait()
			if tErr != nil {
				return nil, tErr
			}
			if aErr != nil {
				return nil, aErr
			}
		}
		return tbl, nil
	}
	if s == nil && p != nil && o == nil {
		// P request.
		for _, g := range gs {
			var (
				tErr error
				aErr error
				wg   sync.WaitGroup
			)
			tracer.Trace(w, func() []string {
				return []string{fmt.Sprintf("g.TriplesForPredicate(%v, %v)", p, lo)}
			})
			ts := make(chan *triple.Triple, chanSize)
			wg.Add(1)
			go func() {
				defer wg.Done()
				tErr = g.TriplesForPredicate(ctx, p, lo, ts)
			}()
			aErr = addTriples(ts, cls, tbl)
			wg.Wait()
			if tErr != nil {
				return nil, tErr
			}
			if aErr != nil {
				return nil, aErr
			}
		}
		return tbl, nil
	}
	if s == nil && p == nil && o != nil {
		// O request.
		for _, g := range gs {
			var (
				tErr error
				wg   sync.WaitGroup
			)
			tracer.Trace(w, func() []string {
				return []string{fmt.Sprintf("g.TriplesForObject(%v, %v)", o, lo)}
			})
			ts := make(chan *triple.Triple, chanSize)
			wg.Add(1)
			go func() {
				defer wg.Done()
				tErr = g.TriplesForObject(ctx, o, lo, ts)
			}()
			aErr := addTriples(ts, cls, tbl)
			wg.Wait()
			if tErr != nil {
				return nil, tErr
			}
			if aErr != nil {
				return nil, aErr
			}
		}
		return tbl, nil
	}
	if s == nil && p == nil && o == nil {
		// Full data request.
		for _, g := range gs {
			var (
				tErr error
				aErr error
				wg   sync.WaitGroup
			)
			tracer.Trace(w, func() []string {
				return []string{fmt.Sprintf("g.Triples(%v)", lo)}
			})
			ts := make(chan *triple.Triple, chanSize)
			wg.Add(1)
			go func() {
				defer wg.Done()
				// Push global limit down.
				nlo := *lo
				if stmLimit > 0 {
					nlo.MaxElements = int(stmLimit)
				}
				tErr = g.Triples(ctx, &nlo, ts)
			}()
			aErr = addTriples(ts, cls, tbl)
			wg.Wait()
			if tErr != nil {
				return nil, tErr
			}
			if aErr != nil {
				return nil, aErr
			}
		}
		return tbl, nil
	}

	return nil, fmt.Errorf("planner.simpleFetch could not recognize request in clause %v", cls)
}
294907
func New(config Config) (*Cache, error) {
	if err := config.CheckAndSetDefaults(); err != nil {
		return nil, trace.Wrap(err)
	}
	wrapper := backend.NewWrapper(config.Backend)
	ctx, cancel := context.WithCancel(config.Context)
	cs := &Cache{
		wrapper:            wrapper,
		ctx:                ctx,
		cancel:             cancel,
		Config:             config,
		trustCache:         local.NewCAService(wrapper),
		clusterConfigCache: local.NewClusterConfigurationService(wrapper),
		provisionerCache:   local.NewProvisioningService(wrapper),
		usersCache:         local.NewIdentityService(wrapper),
		accessCache:        local.NewAccessService(wrapper),
		presenceCache:      local.NewPresenceService(wrapper),
		eventsCache:        local.NewEventsService(config.Backend),
		Entry: log.WithFields(log.Fields{
			trace.Component: config.Component,
		}),
	}
	collections, err := setupCollections(cs, config.Watches)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	cs.collections = collections

	err = cs.fetch()
	if err != nil {
		// "only recent" behavior does not tolerate
		// stale data, so it has to initialize itself
		// with recent data on startup or fail
		if cs.OnlyRecent.Enabled {
			return nil, trace.Wrap(err)
		}
	}
	go cs.update()
	return cs, nil
}
1224304
func NewCache(size int64) *Storage {
	return &Storage{
		maxSize: size,
		lru:     lru.New(0), // infinite items; we evict by size, not count
	}
}
900022
func NewConfig(accessToken string) *Config {
	return &Config{
		HTTPClient:  http.DefaultClient,
		AccessToken: accessToken,
	}
}
104327
func New(conf pruner.Config) (worker.Worker, error) {
	if err := conf.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	w := &Worker{
		pruner.New(conf),
	}

	err := catacomb.Invoke(catacomb.Plan{
		Site: w.Catacomb(),
		Work: w.loop,
	})

	return w, errors.Trace(err)
}
421335
func (c *Configurator) NewDispatcher(serviceName string, data interface{}) (*yarpc.Dispatcher, error) {
	cfg, err := c.LoadConfig(serviceName, data)
	if err != nil {
		return nil, err
	}
	return yarpc.NewDispatcher(cfg), nil
}
844306
func (_m *QueryCreator) NewQuery() (cc.Query, error) {
	ret := _m.Called()

	var r0 cc.Query
	if rf, ok := ret.Get(0).(func() cc.Query); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(cc.Query)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func() error); ok {
		r1 = rf()
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
535880
func NewPatchLink(cl *buildbucketpb.GerritChange) *Link {
	return NewLink(
		fmt.Sprintf("Gerrit CL %d (ps#%d)", cl.Change, cl.Patchset),
		protoutil.GerritChangeURL(cl),
		fmt.Sprintf("gerrit changelist number %d patchset %d", cl.Change, cl.Patchset))
}
170413
func NewNodeAffinityIterator(ctx Context, source RankIterator) *NodeAffinityIterator {
	return &NodeAffinityIterator{
		ctx:    ctx,
		source: source,
	}
}
564163
func NewContract(parent *Contracts) *Contract {
	contract := &Contract{
		parent: parent,
	}
	contract.Init()
	return contract
}
627861
func NewBlockPrefetchClient(f BlockFetcher) *BlockPrefetchClient {
	p := &BlockPrefetchClient{
		f:            f,
		retargetChan: make(chan *chainhash.Hash, 10),
		current:      new(blockData),
		next:         new(blockData),
	}
	// Start the block fetcher goroutine, waiting for a signal on retargetChan.
	go p.fetcher()
	return p
}