Beispiel #1
0
// CreateSession creates a new session environment.
func CreateSession(store kv.Storage) (Session, error) {
	s := &session{
		values: make(map[fmt.Stringer]interface{}),
		store:  store,
		sid:    atomic.AddInt64(&sessionID, 1),
	}
	domain, err := domap.Get(store)
	if err != nil {
		return nil, err
	}
	sessionctx.BindDomain(s, domain)

	variable.BindSessionVars(s)
	variable.GetSessionVars(s).SetStatusFlag(mysql.ServerStatusAutocommit, true)

	// session implements variable.GlobalVarAccessor. Bind it to ctx.
	variable.BindGlobalVarAccessor(s, s)

	// session implements autocommit.Checker. Bind it to ctx
	autocommit.BindAutocommitChecker(s, s)
	sessionMu.Lock()
	defer sessionMu.Unlock()

	_, ok := storeBootstrapped[store.UUID()]
	if !ok {
		s.initing = true
		bootstrap(s)
		s.initing = false
		storeBootstrapped[store.UUID()] = true
	}
	// TODO: Add auth here
	privChecker := &privileges.UserPrivileges{}
	privilege.BindPrivilegeChecker(s, privChecker)
	return s, nil
}
Beispiel #2
0
func (p *testShowSuit) SetUpSuite(c *C) {
	nc := mock.NewContext()
	p.ctx = nc
	variable.BindSessionVars(p.ctx)
	variable.BindGlobalVarAccessor(p.ctx, nc)
	variable.RegisterStatistics(p.ms)

	p.dbName = "testshowplan"
	p.store = newStore(c, p.dbName)
	p.txn, _ = p.store.Begin()
	se := newSession(c, p.store, p.dbName)
	p.createDBSQL = fmt.Sprintf("create database if not exists %s;", p.dbName)
	p.dropDBSQL = fmt.Sprintf("drop database if exists %s;", p.dbName)
	p.useDBSQL = fmt.Sprintf("use %s;", p.dbName)
	p.createTableSQL = `CREATE TABLE test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));`

	mustExecSQL(c, se, p.createDBSQL)
	mustExecSQL(c, se, p.useDBSQL)
	mustExecSQL(c, se, p.createTableSQL)

	p.createSystemDBSQL = fmt.Sprintf("create database if not exists %s;", mysql.SystemDB)
	p.createUserTableSQL = tidb.CreateUserTable
	p.createDBPrivTableSQL = tidb.CreateDBPrivTable
	p.createTablePrivTableSQL = tidb.CreateTablePrivTable
	p.createColumnPrivTableSQL = tidb.CreateColumnPrivTable

	mustExecSQL(c, se, p.createSystemDBSQL)
	mustExecSQL(c, se, p.createUserTableSQL)
	mustExecSQL(c, se, p.createDBPrivTableSQL)
	mustExecSQL(c, se, p.createTablePrivTableSQL)
	mustExecSQL(c, se, p.createColumnPrivTableSQL)

}
Beispiel #3
0
// CreateSession creates a new session environment.
func CreateSession(store kv.Storage) (Session, error) {
	s := &session{
		values:      make(map[fmt.Stringer]interface{}),
		store:       store,
		sid:         atomic.AddInt64(&sessionID, 1),
		debugInfos:  make(map[string]interface{}),
		maxRetryCnt: 10,
		parser:      parser.New(),
	}
	domain, err := domap.Get(store)
	if err != nil {
		return nil, errors.Trace(err)
	}
	sessionctx.BindDomain(s, domain)

	variable.BindSessionVars(s)
	variable.GetSessionVars(s).SetStatusFlag(mysql.ServerStatusAutocommit, true)

	// session implements variable.GlobalVarAccessor. Bind it to ctx.
	variable.BindGlobalVarAccessor(s, s)

	// session implements autocommit.Checker. Bind it to ctx
	autocommit.BindAutocommitChecker(s, s)
	sessionMu.Lock()
	defer sessionMu.Unlock()

	ver := getStoreBootstrapVersion(store)
	if ver == notBootstrapped {
		// if no bootstrap and storage is remote, we must use a little lease time to
		// bootstrap quickly, after bootstrapped, we will reset the lease time.
		// TODO: Using a bootstap tool for doing this may be better later.
		if !localstore.IsLocalStore(store) {
			sessionctx.GetDomain(s).SetLease(chooseMinLease(100*time.Millisecond, schemaLease))
		}

		s.SetValue(context.Initing, true)
		bootstrap(s)
		s.ClearValue(context.Initing)

		if !localstore.IsLocalStore(store) {
			sessionctx.GetDomain(s).SetLease(schemaLease)
		}

		finishBootstrap(store)
	} else if ver < currentBootstrapVersion {
		s.SetValue(context.Initing, true)
		upgrade(s)
		s.ClearValue(context.Initing)
	}

	// TODO: Add auth here
	privChecker := &privileges.UserPrivileges{}
	privilege.BindPrivilegeChecker(s, privChecker)
	return s, nil
}
Beispiel #4
0
func (s *testVariableSuite) SetUpSuite(c *C) {
	nc := mock.NewContext()
	s.ctx = nc
	variable.BindSessionVars(s.ctx)
	variable.BindGlobalVarAccessor(s.ctx, nc)
}