// Freeze is a part of starlark.Value interface.
//
// It finalizes the graph, panicking on errors. Users of Graph are expected to
// finalize the graph themselves (checking errors) before Starlark tries to
// freeze it.
432562
func (g *Graph) Freeze() {
	if err := g.Finalize(); err != nil {
		panic(err)
	}
}
1157270
func (log *Log) Add(g *Graph) int64 {

	b := g.Binary()

	if b == nil {
		return 0
	}

	i, _ := log.f.Seek(0, 2)

	log.f.Write(b)

	if log.autoSync {
		log.f.Sync()
	}

	return i
}
556685
func (s *memoryStore) Graph(ctx context.Context, id string) (storage.Graph, error) {
	s.rwmu.RLock()
	defer s.rwmu.RUnlock()
	if g, ok := s.graphs[id]; ok {
		return g, nil
	}
	return nil, fmt.Errorf("memory.Graph(%q): graph does not exist", id)
}
982578
func (p *Plot) Save() *Plot {
	p.env = &plotEnv{
		parent: p.env,
		data:   p.env.data,
	}
	return p
}
1326864
func (t *BucketRateLimiter) Close() (err error) {
	t.cancel()
	return t.egCleaner.Wait()
}
919223
func (p *binParser) parse() *Graph {

	if p == nil || !p.header() {
		return nil
	}

	ev := &SimpleEventHandler{}

	for {
		lev, bin, b := p.line(true)
		if lev == 0 {
			break
		}
		// Store the content in the same format as it was sent (string or []byte)
		if bin {
			ev.AddBytesAt(b, lev-1)
		} else {
			ev.AddAt(string(b), lev-1)
		}
	}
	return ev.Tree()
}
474462
func (m *GroupByFinal) Close() error {
	m.Lock()
	if m.closed {
		m.Unlock()
		return nil
	}
	m.closed = true
	m.Unlock()

	ticker := time.NewTicker(30 * time.Second)
	defer ticker.Stop()

	//u.Infof("%p group by final Close() waiting for complete", m)
	select {
	case <-ticker.C:
		u.Warnf("timeout???? ")
	case <-m.complete:
		//u.Warnf("%p got groupbyfinal complete", m)
	}

	return m.TaskBase.Close()
}
55460
func (sn *SimNode) Stop() error {
	sn.lock.Lock()
	if sn.client != nil {
		sn.client.Close()
		sn.client = nil
	}
	sn.lock.Unlock()
	return sn.node.Stop()
}
19129
func (p *queryPlan) filterOnExistence(ctx context.Context, cls *semantic.GraphClause, lo *storage.LookupOptions) error {
	data := p.tbl.Rows()
	p.tbl.Truncate()
	var (
		gErr error
		mu   sync.RWMutex
		wg   sync.WaitGroup
	)
	for _, tmp := range data {
		mu.RLock()
		if gErr != nil {
			// Try to stop early if an error occurred and we are still ussuing requests.
			mu.RUnlock()
			break
		}
		mu.RUnlock()
		wg.Add(1)
		go func(r table.Row, cls semantic.GraphClause) {
			defer wg.Done()
			sbj, prd, obj := cls.S, cls.P, cls.O
			// Attempt to rebind the subject.
			if sbj == nil && p.tbl.HasBinding(cls.SBinding) {
				v, ok := r[cls.SBinding]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.SBinding)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a node, got %+v instead", cls.SBinding, v)
					mu.Unlock()
					return
				}
				sbj = v.N
			}
			if sbj == nil && p.tbl.HasBinding(cls.SAlias) {
				v, ok := r[cls.SAlias]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.SAlias)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a node, got %+v instead", cls.SAlias, v)
					mu.Unlock()
					return
				}
				sbj = v.N
			}
			// Attempt to rebind the predicate.
			if prd == nil && p.tbl.HasBinding(cls.PBinding) {
				v, ok := r[cls.PBinding]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.PBinding)
					mu.Unlock()
					return
				}
				if v.P == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a predicate, got %+v instead", cls.PBinding, v)
					mu.Unlock()
					return
				}
				prd = v.P
			}
			if prd == nil && p.tbl.HasBinding(cls.PAlias) {
				v, ok := r[cls.PAlias]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.SAlias)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a predicate, got %+v instead", cls.SAlias, v)
					mu.Unlock()
					return
				}
				prd = v.P
			}
			// Attempt to rebind the object.
			if obj == nil && p.tbl.HasBinding(cls.OBinding) {
				v, ok := r[cls.OBinding]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.OBinding)
					mu.Unlock()
					return
				}
				co, err := cellToObject(v)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
				}
				obj = co
			}
			if obj == nil && p.tbl.HasBinding(cls.OAlias) {
				v, ok := r[cls.OAlias]
				if !ok {
					mu.Unlock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.OAlias)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a object, got %+v instead", cls.OAlias, v)
					mu.Unlock()
					return
				}
				co, err := cellToObject(v)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
					return
				}
				obj = co
			}
			// Attempt to filter.
			if sbj == nil || prd == nil || obj == nil {
				mu.Lock()
				gErr = fmt.Errorf("failed to fully specify clause %v for row %+v", cls, r)
				mu.Unlock()
				return
			}
			exist := false
			for _, g := range p.stm.InputGraphs() {
				t, err := triple.New(sbj, prd, obj)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
					return
				}
				b, err := g.Exist(ctx, t)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
					return
				}
				exist = exist || b
				if exist {
					break
				}
			}
			if exist {
				p.tbl.AddRow(r)
			}
		}(tmp, *cls)
	}
	wg.Wait()
	return gErr
}
582682
func (l *LogParserPlugin) Stop() {
	l.Lock()
	defer l.Unlock()

	for _, t := range l.tailers {
		err := t.Stop()

		//message for a stopped tailer
		log.Printf("D! tail dropped for file: %v", t.Filename)

		if err != nil {
			log.Printf("E! Error stopping tail on file %s\n", t.Filename)
		}
		t.Cleanup()
	}
	close(l.done)
	l.wg.Wait()
}
648011
func (s *RemotelyControlledSampler) Close() {
	if swapped := atomic.CompareAndSwapInt64(&s.closed, 0, 1); !swapped {
		s.logger.Error("Repeated attempt to close the sampler is ignored")
		return
	}

	var wg sync.WaitGroup
	wg.Add(1)
	s.doneChan <- &wg
	wg.Wait()
}
595722
func (s *state) Close() error {
	if s.cancel != nil {
		s.cancel()
	}
	return nil
}
59172
func lock() error {
	var err error
	var lock lockfile.Lockfile

	daemonMutex.Lock()
	lock, err = getLockfile()
	if err != nil {
		daemonMutex.Unlock()
		return fmt.Errorf("[lock] cannot init lockfile: %v", err)
	}

	// Try to acquire the lock and in case of a temporary error, sleep for
	// two seconds until the next retry (at most 10 times).  Return fatal
	// errors immediately, as we can't recover.
	for i := 0; i < 10; i++ {
		if err = lock.TryLock(); err != nil {
			switch err.(type) {
			case lockfile.TemporaryError:
				logrus.Debugf("[lock] busy: next retry in two seconds")
				time.Sleep(2 * time.Second)
			default:
				daemonMutex.Unlock()
				return fmt.Errorf("[lock] error acquiring lock: %s", err)
			}
		}
	}
	if err != nil {
		daemonMutex.Unlock()
		return fmt.Errorf("[lock] error acquiring lock: too many tries")
	}

	logrus.Debugf("[lock] lock acquired")
	return nil
}
523765
func Close(xs XStater) error {
	if c, ok := xs.(io.Closer); ok {
		return c.Close()
	}
	return nil
}
1271906
func (ae ArangoError) Temporary() bool {
	return ae.HasError && ae.Code == http.StatusServiceUnavailable
}
1236967
func (iter *Iterx) Close() error {
	err := iter.Iter.Close()
	if iter.err == nil {
		iter.err = err
	}
	return iter.err
}
1362291
func init() {
	snowflake, err := gosnow.Default()
	if err != nil {
		panic(err)
	}

	sf = snowflake
}