当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Value方法代码示例

本文整理汇总了Golang中github.com/pingcap/tidb/context.Context.Value方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Value方法的具体用法?Golang Context.Value怎么用?Golang Context.Value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/pingcap/tidb/context.Context的用法示例。


在下文中一共展示了Context.Value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: isAutocommit

// IsAutocommit checks if it is in the auto-commit mode.
func (s *session) isAutocommit(ctx context.Context) bool {
	if ctx.Value(&sqlexec.RestrictedSQLExecutorKeyType{}) != nil {
		return false
	}
	autocommit, ok := variable.GetSessionVars(ctx).Systems["autocommit"]
	if !ok {
		if s.initing {
			return false
		}
		var err error
		autocommit, err = s.GetGlobalSysVar(ctx, "autocommit")
		if err != nil {
			log.Errorf("Get global sys var error: %v", err)
			return false
		}
		variable.GetSessionVars(ctx).Systems["autocommit"] = autocommit
		ok = true
	}
	if ok && (autocommit == "ON" || autocommit == "on" || autocommit == "1") {
		variable.GetSessionVars(ctx).SetStatusFlag(mysql.ServerStatusAutocommit, true)
		return true
	}
	variable.GetSessionVars(ctx).SetStatusFlag(mysql.ServerStatusAutocommit, false)
	return false
}
开发者ID:losas,项目名称:tidb,代码行数:26,代码来源:session.go

示例2: GetSessionVars

// GetSessionVars gets the session vars from context.
func GetSessionVars(ctx context.Context) *SessionVars {
	v, ok := ctx.Value(sessionVarsKey).(*SessionVars)
	if !ok {
		return nil
	}
	return v
}
开发者ID:lovedboy,项目名称:tidb,代码行数:8,代码来源:session.go

示例3: GetCurrentSchema

// GetCurrentSchema gets current schema name from context.
func GetCurrentSchema(ctx context.Context) string {
	v, ok := ctx.Value(currentDBKey).(string)
	if !ok {
		return ""
	}
	return v
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:8,代码来源:db.go

示例4: GetGlobalVarAccessor

// GetGlobalVarAccessor gets accessor from ctx.
func GetGlobalVarAccessor(ctx context.Context) GlobalVarAccessor {
	v, ok := ctx.Value(accessorKey).(GlobalVarAccessor)
	if !ok {
		panic("Miss global sysvar accessor")
	}
	return v
}
开发者ID:jmptrader,项目名称:tidb,代码行数:8,代码来源:sysvar.go

示例5: GetExecArgs

// GetExecArgs gets executive args from context.
func GetExecArgs(ctx context.Context) []interface{} {
	v, ok := ctx.Value(execArgsKey).([]interface{})
	if !ok {
		return nil
	}
	return v
}
开发者ID:rorovic,项目名称:tidb,代码行数:8,代码来源:stmt.go

示例6: isAutocommit

// IsAutocommit checks if it is in the auto-commit mode.
func (s *session) isAutocommit(ctx context.Context) (bool, error) {
	sessionVar := variable.GetSessionVars(ctx)
	autocommit := sessionVar.GetSystemVar("autocommit")
	if autocommit.IsNull() {
		if ctx.Value(context.Initing) != nil {
			return false, nil
		}
		autocommitStr, err := s.GetGlobalSysVar(ctx, "autocommit")
		if err != nil {
			return false, errors.Trace(err)
		}
		autocommit.SetString(autocommitStr)
		err = sessionVar.SetSystemVar("autocommit", autocommit)
		if err != nil {
			return false, errors.Trace(err)
		}
	}
	autocommitStr := autocommit.GetString()
	if autocommitStr == "ON" || autocommitStr == "on" || autocommitStr == "1" {
		variable.GetSessionVars(ctx).SetStatusFlag(mysql.ServerStatusAutocommit, true)
		return true, nil
	}
	variable.GetSessionVars(ctx).SetStatusFlag(mysql.ServerStatusAutocommit, false)
	return false, nil
}
开发者ID:jmptrader,项目名称:tidb,代码行数:26,代码来源:session.go

示例7: ExecRestrictedSQL

// ExecRestrictedSQL implements SQLHelper interface.
// This is used for executing some restricted sql statements.
func (s *session) ExecRestrictedSQL(ctx context.Context, sql string) (rset.Recordset, error) {
	if ctx.Value(&sqlexec.RestrictedSQLExecutorKeyType{}) != nil {
		// We do not support run this function concurrently.
		// TODO: Maybe we should remove this restriction latter.
		return nil, errors.New("Should not call ExecRestrictedSQL concurrently.")
	}
	statements, err := Compile(ctx, sql)
	if err != nil {
		log.Errorf("Compile %s with error: %v", sql, err)
		return nil, errors.Trace(err)
	}
	if len(statements) != 1 {
		log.Errorf("ExecRestrictedSQL only executes one statement. Too many/few statement in %s", sql)
		return nil, errors.New("Wrong number of statement.")
	}
	st := statements[0]
	// Check statement for some restriction
	// For example only support DML on system meta table.
	// TODO: Add more restrictions.
	log.Debugf("Executing %s [%s]", st.OriginText(), sql)
	ctx.SetValue(&sqlexec.RestrictedSQLExecutorKeyType{}, true)
	defer ctx.ClearValue(&sqlexec.RestrictedSQLExecutorKeyType{})
	rs, err := st.Exec(ctx)
	return rs, errors.Trace(err)
}
开发者ID:losas,项目名称:tidb,代码行数:27,代码来源:session.go

示例8: GetSchemaVersion

// GetSchemaVersion gets schema version in the context.
func GetSchemaVersion(ctx context.Context) int64 {
	v, ok := ctx.Value(schemaVersionKey).(int64)
	if !ok {
		log.Error("get schema version failed")
	}
	return v
}
开发者ID:jmptrader,项目名称:tidb,代码行数:8,代码来源:binloginfo.go

示例9: GetTiDBSystemVar

// GetTiDBSystemVar get variable value for name.
// The variable should be a TiDB specific system variable (The vars in tidbSysVars map).
// If the session scope variable is not set, it will get global scope value and fill session scope value.
func (s *SessionVars) GetTiDBSystemVar(ctx context.Context, name string) (string, error) {
	key := strings.ToLower(name)
	_, ok := tidbSysVars[key]
	if !ok {
		return "", errors.Errorf("%s is not a TiDB specific system variable.", name)
	}

	sVal, ok := s.systems[key]
	if ok {
		return sVal, nil
	}

	if ctx.Value(context.Initing) != nil {
		// When running bootstrap or upgrade job, we should not access global storage.
		return SysVars[key].Value, nil
	}

	if key == DistSQLScanConcurrencyVar {
		// Get global variable need to scan table which depends on DistSQLScanConcurrencyVar.
		// So we should add it here to break the dependency loop.
		s.systems[DistSQLScanConcurrencyVar] = SysVars[key].Value
	}

	globalVars := GetGlobalVarAccessor(ctx)
	globalVal, err := globalVars.GetGlobalSysVar(ctx, key)
	if err != nil {
		if key == DistSQLScanConcurrencyVar {
			// Clean up.
			delete(s.systems, DistSQLScanConcurrencyVar)
		}
		return "", errors.Trace(err)
	}
	s.systems[key] = globalVal
	return globalVal, nil
}
开发者ID:jmptrader,项目名称:tidb,代码行数:38,代码来源:session.go

示例10: ShouldAutocommit

// ShouldAutocommit gets checker from ctx and checks if it should autocommit.
func ShouldAutocommit(ctx context.Context) (bool, error) {
	v, ok := ctx.Value(key).(Checker)
	if !ok {
		panic("Miss autocommit checker")
	}
	return v.ShouldAutocommit(ctx)
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:8,代码来源:autocommit.go

示例11: GetDomain

// GetDomain gets domain from context.
func GetDomain(ctx context.Context) *domain.Domain {
	v, ok := ctx.Value(domainKey).(*domain.Domain)
	if !ok {
		return nil
	}
	return v
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:8,代码来源:domainctx.go

示例12: getRowStack

func getRowStack(ctx context.Context) *RowStack {
	v := ctx.Value(rowStackKey)
	if v == nil {
		return nil
	}
	// must be RowStack
	t := v.(*RowStack)
	return t
}
开发者ID:lovedboy,项目名称:tidb,代码行数:9,代码来源:row_stack.go

示例13: GetPrewriteValue

// GetPrewriteValue gets binlog prewrite value in the context.
func GetPrewriteValue(ctx context.Context, createIfNotExists bool) *binlog.PrewriteValue {
	v, ok := ctx.Value(binlogKey).(*binlog.PrewriteValue)
	if !ok && createIfNotExists {
		schemaVer := GetSchemaVersion(ctx)
		v = &binlog.PrewriteValue{SchemaVersion: schemaVer}
		ctx.SetValue(binlogKey, v)
	}
	return v
}
开发者ID:jmptrader,项目名称:tidb,代码行数:10,代码来源:binloginfo.go

示例14: ShouldAutocommit

func (s *session) ShouldAutocommit(ctx context.Context) bool {
	if ctx.Value(&sqlexec.RestrictedSQLExecutorKeyType{}) != nil {
		return false
	}
	// With START TRANSACTION, autocommit remains disabled until you end
	// the transaction with COMMIT or ROLLBACK.
	if variable.GetSessionVars(ctx).Status&mysql.ServerStatusInTrans == 0 && s.isAutocommit(ctx) {
		return true
	}
	return false
}
开发者ID:losas,项目名称:tidb,代码行数:11,代码来源:session.go

示例15: getDirtyDB

func getDirtyDB(ctx context.Context) *dirtyDB {
	var udb *dirtyDB
	x := ctx.Value(DirtyDBKey)
	if x == nil {
		udb = &dirtyDB{tables: make(map[int64]*dirtyTable)}
		ctx.SetValue(DirtyDBKey, udb)
	} else {
		udb = x.(*dirtyDB)
	}
	return udb
}
开发者ID:yubobo,项目名称:tidb,代码行数:11,代码来源:union_scan.go


注:本文中的github.com/pingcap/tidb/context.Context.Value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。