// suToGlobal returns whether or not a schema.Unit refers to a global unit
354319
func suToGlobal(su schema.Unit) bool {
	u := job.Unit{
		Unit: *schema.MapSchemaUnitOptionsToUnitFile(su.Options),
	}
	return u.IsGlobal()
}
275703
func (s *GlobalCluster) SetGlobalClusterArn(v string) *GlobalCluster {
	s.GlobalClusterArn = &v
	return s
}
404523
func (s *GlobalTableDescription) SetGlobalTableStatus(v string) *GlobalTableDescription {
	s.GlobalTableStatus = &v
	return s
}
613261
func SetGlobals(reg template.Registry, globals data.Map) error {
	for _, t := range reg.Templates {
		if err := SetNodeGlobals(t.Node, globals); err != nil {
			return fmt.Errorf("template %v: %v", t.Node.Name, err)
		}
	}
	return nil
}
440406
func initGlobal() error {
	// disable stats update.
	session.SetStatsLease(0)
	var err error
	storeGlobal, domGlobal, err = newMockTikvWithBootstrap()
	if err == nil {
		return nil
	}

	if storeGlobal != nil {
		if err1 := storeGlobal.Close(); err1 != nil {
			logutil.Logger(context.Background()).Error("storeGlobal close error", zap.Error(err1))
		}
	}
	if domGlobal != nil {
		domGlobal.Close()
	}
	return err
}
25047
func CreateGlobal(stateDriver core.StateDriver, gc *intent.ConfigGlobal) error {
	log.Infof("Received global create with intent {%v}", gc)
	var err error
	gcfgUpdateList := []string{}

	masterGc := &mastercfg.GlobConfig{}
	masterGc.StateDriver = stateDriver
	masterGc.Read("global")

	gstate.GlobalMutex.Lock()
	defer gstate.GlobalMutex.Unlock()
	gCfg := &gstate.Cfg{}
	gCfg.StateDriver = stateDriver
	gCfg.Read("global")

	// check for valid values
	if gc.NwInfraType != "" {
		switch gc.NwInfraType {
		case "default", "aci", "aci-opflex":
			// These values are acceptable.
		default:
			return errors.New("invalid fabric mode")
		}
		masterGc.NwInfraType = gc.NwInfraType
	}
	if gc.VLANs != "" {
		_, err := netutils.ParseTagRanges(gc.VLANs, "vlan")
		if err != nil {
			return err
		}
		gCfg.Auto.VLANs = gc.VLANs
		gcfgUpdateList = append(gcfgUpdateList, "vlan")
	}

	if gc.VXLANs != "" {
		_, err = netutils.ParseTagRanges(gc.VXLANs, "vxlan")
		if err != nil {
			return err
		}
		gCfg.Auto.VXLANs = gc.VXLANs
		gcfgUpdateList = append(gcfgUpdateList, "vxlan")
	}

	if gc.FwdMode != "" {
		masterGc.FwdMode = gc.FwdMode
	}

	if gc.ArpMode != "" {
		masterGc.ArpMode = gc.ArpMode
	}

	if gc.PvtSubnet != "" {
		masterGc.PvtSubnet = gc.PvtSubnet
	}

	if len(gcfgUpdateList) > 0 {
		// Delete old state

		gOper := &gstate.Oper{}
		gOper.StateDriver = stateDriver
		err = gOper.Read("")
		if err == nil {
			for _, res := range gcfgUpdateList {
				err = gCfg.UpdateResources(res)
				if err != nil {
					return err
				}
			}
		} else {

			for _, res := range gcfgUpdateList {
				// setup resources
				err = gCfg.Process(res)
				if err != nil {
					log.Errorf("Error updating the config %+v. Error: %s", gCfg, err)
					return err
				}
			}
		}

		err = gCfg.Write()
		if err != nil {
			log.Errorf("error updating global config.Error: %s", err)
			return err
		}
	}
	return masterGc.Write()
}
483772
func (s *schemaVersionSyncer) MustGetGlobalVersion(ctx context.Context) (int64, error) {
	startTime := time.Now()
	var (
		err  error
		ver  int
		resp *clientv3.GetResponse
	)
	failedCnt := 0
	intervalCnt := int(time.Second / keyOpRetryInterval)

	defer func() {
		metrics.OwnerHandleSyncerHistogram.WithLabelValues(metrics.OwnerGetGlobalVersion, metrics.RetLabel(err)).Observe(time.Since(startTime).Seconds())
	}()
	for {
		if err != nil {
			if failedCnt%intervalCnt == 0 {
				logutil.Logger(ddlLogCtx).Info("[ddl] syncer get global version failed", zap.Error(err))
			}
			time.Sleep(keyOpRetryInterval)
			failedCnt++
		}

		if isContextDone(ctx) {
			err = errors.Trace(ctx.Err())
			return 0, err
		}

		resp, err = s.etcdCli.Get(ctx, DDLGlobalSchemaVersion)
		if err != nil {
			continue
		}
		if len(resp.Kvs) > 0 {
			ver, err = strconv.Atoi(string(resp.Kvs[0].Value))
			if err == nil {
				return int64(ver), nil
			}
		}
	}
}
599106
func IsGlobalService(service *api.Service) bool {
	if service == nil {
		return false
	}
	_, ok := service.Spec.GetMode().(*api.ServiceSpec_Global)
	return ok
}
296609
func (r *Relation) Unit(u *Unit) (*RelationUnit, error) {
	const isLocalUnit = true
	return r.unit(u.Name(), u.doc.Principal, u.IsPrincipal(), isLocalUnit)
}
1147023
func GetGlobalSystemVar(s *SessionVars, key string) (string, error) {
	key = strings.ToLower(key)
	gVal, ok, err := GetScopeNoneSystemVar(key)
	if err != nil || ok {
		return gVal, err
	}
	gVal, err = s.GlobalVarsAccessor.GetGlobalSysVar(key)
	if err != nil {
		return "", err
	}
	return gVal, nil
}
993126
func DeleteGlobal(stateDriver core.StateDriver) error {
	masterGc := &mastercfg.GlobConfig{}
	masterGc.StateDriver = stateDriver
	err := masterGc.Read("")
	if err == nil {
		err = masterGc.Clear()
		if err != nil {
			return err
		}
	}

	// Setup global state
	gCfg := &gstate.Cfg{}
	gCfg.StateDriver = stateDriver
	err = gCfg.Read("")
	if err == nil {
		err = gCfg.DeleteResources("vlan")
		if err != nil {
			return err
		}
		err = gCfg.DeleteResources("vxlan")
		if err != nil {
			return err
		}

		err = gCfg.Clear()
		if err != nil {
			return err
		}
	}

	// Delete old state
	gOper := &gstate.Oper{}
	gOper.StateDriver = stateDriver
	err = gOper.Read("")
	if err == nil {
		err = gOper.Clear()
		if err != nil {
			return err
		}
	}

	return nil
}
960616
func (s *Set) AddGlobal(key string, i interface{}) *Set {
	s.gmx.Lock()
	if s.globals == nil {
		s.globals = make(VarMap)
	}
	s.globals[key] = reflect.ValueOf(i)
	s.gmx.Unlock()
	return s
}
227965
func (m *Mrb) GetGlobalVariable(name string) *MrbValue {
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	return newValue(m.state, C._go_mrb_gv_get(m.state, C.mrb_intern_cstr(m.state, cs)))
}
1297555
func initGlobals() {
	shutdownFuncs = nil
	shutdownRequested = false
	testingResetC = make(chan struct{})
	// initContext is different for < go1.7 and >=go1.7
	initContext()
	shutdownC = shutdownCtx.Done()
}
168633
func coalesceGlobals(dest, src map[string]interface{}) map[string]interface{} {
	var dg, sg map[string]interface{}

	if destglob, ok := dest[GlobalKey]; !ok {
		dg = map[string]interface{}{}
	} else if dg, ok = destglob.(map[string]interface{}); !ok {
		glog.Infof("warning: skipping globals because destination %s is not a table.", GlobalKey)
		return dg
	}

	if srcglob, ok := src[GlobalKey]; !ok {
		sg = map[string]interface{}{}
	} else if sg, ok = srcglob.(map[string]interface{}); !ok {
		glog.Infof("warning: skipping globals because source %s is not a table.", GlobalKey)
		return dg
	}

	// EXPERIMENTAL: In the past, we have disallowed globals to test tables. This
	// reverses that decision. It may somehow be possible to introduce a loop
	// here, but I haven't found a way. So for the time being, let's allow
	// tables in globals.
	for key, val := range sg {
		if istable(val) {
			vv := copyMap(val.(map[string]interface{}))
			if destv, ok := dg[key]; ok {
				if destvmap, ok := destv.(map[string]interface{}); ok {
					// Basically, we reverse order of coalesce here to merge
					// top-down.
					coalesceTables(vv, destvmap)
					dg[key] = vv
					continue
				} else {
					glog.Infof("Conflict: cannot merge map onto non-map for %q. Skipping.", key)
				}
			} else {
				// Here there is no merge. We're just adding.
				dg[key] = vv
			}
		} else if dv, ok := dg[key]; ok && istable(dv) {
			// It's not clear if this condition can actually ever trigger.
			glog.Infof("key %s is table. Skipping", key)
			continue
		}
		// TODO: Do we need to do any additional checking on the value?
		dg[key] = val
	}
	dest[GlobalKey] = dg
	return dest
}
149227
func (c *Context) GlobalGeneric(name string) interface{} {
	if fs := lookupGlobalFlagSet(name, c); fs != nil {
		return lookupGeneric(name, fs)
	}
	return nil
}
931903
func GetOperGlobal(obj *GlobalInspect) error {
	// Check if we handle this object
	if objCallbackHandler.GlobalCb == nil {
		log.Errorf("No callback registered for global object")
		return errors.New("Invalid object type")
	}

	// Perform callback
	err := objCallbackHandler.GlobalCb.GlobalGetOper(obj)
	if err != nil {
		log.Errorf("GlobalDelete retruned error for: %+v. Err: %v", obj, err)
		return err
	}

	return nil
}