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


Golang tidb.NewStore函数代码示例

本文整理汇总了Golang中github.com/pingcap/tidb.NewStore函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStore函数的具体用法?Golang NewStore怎么用?Golang NewStore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: SetUpSuite

func (s *testKVSuite) SetUpSuite(c *C) {
	store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *testStore, *testStorePath))
	c.Assert(err, IsNil)
	s.s = store

	cacheS, _ := tidb.NewStore(fmt.Sprintf("%s://%s", *testStore, *testStorePath))
	c.Assert(cacheS, Equals, store)
}
开发者ID:lovedboy,项目名称:tidb,代码行数:8,代码来源:store_test.go

示例2: SetUpSuite

func (s *testKVSuite) SetUpSuite(c *C) {
	store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *testStore, *testStorePath))
	c.Assert(err, IsNil)
	s.s = store

	cacheS, _ := tidb.NewStore(fmt.Sprintf("%s://%s", *testStore, *testStorePath))
	c.Assert(cacheS, Equals, store)
	logLevel := os.Getenv("log_level")
	log.SetLevelByString(logLevel)
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:10,代码来源:store_test.go

示例3: TestInc

func (t *testIsolationSuite) TestInc(c *C) {
	store, err := tidb.NewStore("memory://test/test_isolation")
	c.Assert(err, IsNil)
	defer store.Close()

	threadCnt := 4

	ids := make(map[int64]struct{}, threadCnt*100)
	var m sync.Mutex
	var wg sync.WaitGroup

	wg.Add(threadCnt)
	for i := 0; i < threadCnt; i++ {
		go func() {
			defer wg.Done()
			for j := 0; j < 100; j++ {
				var id int64
				err := kv.RunInNewTxn(store, true, func(txn kv.Transaction) error {
					var err1 error
					id, err1 = kv.IncInt64(txn, []byte("key"), 1)
					return err1
				})
				c.Assert(err, IsNil)

				m.Lock()
				_, ok := ids[id]
				ids[id] = struct{}{}
				m.Unlock()
				c.Assert(ok, IsFalse)
			}
		}()
	}

	wg.Wait()
}
开发者ID:lovedboy,项目名称:tidb,代码行数:35,代码来源:isolation_test.go

示例4: TestInfoBinder

func (ts *testInfoBinderSuite) TestInfoBinder(c *C) {
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	defer store.Close()
	testKit := testkit.NewTestKit(c, store)
	testKit.MustExec("use test")
	testKit.MustExec("create table t (c1 int, c2 int)")
	domain := sessionctx.GetDomain(testKit.Se.(context.Context))

	src := "SELECT c1 from t"
	l := parser.NewLexer(src)
	c.Assert(parser.YYParse(l), Equals, 0)
	stmts := l.Stmts()
	c.Assert(len(stmts), Equals, 1)
	v := &optimizer.InfoBinder{
		Info:          domain.InfoSchema(),
		DefaultSchema: model.NewCIStr("test"),
	}
	selectStmt := stmts[0].(*ast.SelectStmt)
	selectStmt.Accept(v)

	verifier := &binderVerifier{
		c: c,
	}
	selectStmt.Accept(verifier)
}
开发者ID:yzl11,项目名称:vessel,代码行数:26,代码来源:infobinder_test.go

示例5: main

func main() {
	flag.Parse()

	if *lease < 0 {
		log.Fatalf("invalid lease seconds %d", *lease)
	}

	tidb.SetSchemaLease(time.Duration(*lease) * time.Second)

	log.SetLevelByString(*logLevel)
	store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *store, *storePath))
	if err != nil {
		log.Fatal(err)
	}

	var driver relay.IDriver
	driver = relay.NewTiDBDriver(store)
	replayer, err := relay.NewReplayer(driver, *relayPath, *check)
	if err != nil {
		log.Fatal(err)
	}

	replayer.OnRecordRead = func(rec *relay.Record) {
		fmt.Printf("%s\n", rec)
	}

	err = replayer.Run()
	if err != nil {
		log.Fatal(errors.ErrorStack(err))
	}
}
开发者ID:pingcap,项目名称:mysqlrelay,代码行数:31,代码来源:main.go

示例6: TestInsert

func (p *testPerfSchemaSuit) TestInsert(c *C) {
	defer testleak.AfterTest(c)()
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	defer store.Close()
	se := newSession(c, store, "")
	defer se.Close()
	mustExec(c, se, `insert into performance_schema.setup_actors values("localhost", "nieyy", "contributor", "NO", "NO");`)
	checkResult(c, se, 0, 0)

	cnt := mustQuery(c, se, "select * from performance_schema.setup_actors")
	c.Assert(cnt, Equals, 2)

	mustExec(c, se, `insert into performance_schema.setup_actors (host, user, role) values ("localhost", "lijian", "contributor");`)
	checkResult(c, se, 0, 0)
	cnt = mustQuery(c, se, "select * from performance_schema.setup_actors")
	c.Assert(cnt, Equals, 3)

	mustExec(c, se, `insert into performance_schema.setup_objects values("EVENT", "test", "%", "NO", "NO")`)
	checkResult(c, se, 0, 0)
	cnt = mustQuery(c, se, "select * from performance_schema.setup_objects")
	c.Assert(cnt, Equals, 13)

	mustExec(c, se, `insert into performance_schema.setup_objects (object_schema, object_name) values ("test1", "%")`)
	checkResult(c, se, 0, 0)
	cnt = mustQuery(c, se, "select * from performance_schema.setup_objects")
	c.Assert(cnt, Equals, 14)

	mustFailExec(c, se, `insert into performance_schema.setup_actors (host) values (null);`)
	mustFailExec(c, se, `insert into performance_schema.setup_objects (object_type) values (null);`)
	mustFailExec(c, se, `insert into performance_schema.setup_instruments values("select", "N/A", "N/A");`)
	mustFailExec(c, se, `insert into performance_schema.setup_consumers values("events_stages_current", "N/A");`)
	mustFailExec(c, se, `insert into performance_schema.setup_timers values("timer1", "XXXSECOND");`)
}
开发者ID:pingcap,项目名称:tidb,代码行数:34,代码来源:perfschema_test.go

示例7: TestConcurrentStatement

func (p *testPerfSchemaSuit) TestConcurrentStatement(c *C) {
	defer testleak.AfterTest(c)()
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory + "/test_con_stmt")
	c.Assert(err, IsNil)
	defer store.Close()
	se := newSession(c, store, "test_con_stmt")

	mustExec(c, se, "drop table if exists test")
	mustExec(c, se, "create table test (a int, b int)")

	var wg sync.WaitGroup
	iFunc := func(a, b int) {
		defer wg.Done()
		sess := newSession(c, store, "test_con_stmt")
		mustExec(c, sess, fmt.Sprintf(`INSERT INTO test VALUES (%d, %d);`, a, b))
	}
	sFunc := func() {
		defer wg.Done()
		sess := newSession(c, store, "test_con_stmt")
		mustQuery(c, sess, "select * from performance_schema.events_statements_current")
		mustQuery(c, sess, "select * from performance_schema.events_statements_history")
	}

	cnt := 10
	for i := 0; i < cnt; i++ {
		wg.Add(2)
		go iFunc(i, i)
		go sFunc()
	}
	wg.Wait()
}
开发者ID:pingcap,项目名称:tidb,代码行数:31,代码来源:perfschema_test.go

示例8: TestNameResolver

func (ts *testNameResolverSuite) TestNameResolver(c *C) {
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	defer store.Close()
	testKit := testkit.NewTestKit(c, store)
	testKit.MustExec("use test")
	testKit.MustExec("create table t1 (c1 int, c2 int)")
	testKit.MustExec("create table t2 (c1 int, c2 int)")
	testKit.MustExec("create table t3 (c1 int, c2 int)")
	ctx := testKit.Se.(context.Context)
	domain := sessionctx.GetDomain(ctx)
	db.BindCurrentSchema(ctx, "test")
	for _, tc := range resolverTestCases {
		node, err := parser.ParseOneStmt(tc.src, "", "")
		c.Assert(err, IsNil)
		resolveErr := plan.ResolveName(node, domain.InfoSchema(), ctx)
		if tc.valid {
			c.Assert(resolveErr, IsNil)
			verifier := &resolverVerifier{c: c, src: tc.src}
			node.Accept(verifier)
		} else {
			c.Assert(resolveErr, NotNil, Commentf("%s", tc.src))
		}
	}
}
开发者ID:anywhy,项目名称:tidb,代码行数:25,代码来源:resolver_test.go

示例9: SetUpSuite

func (s *testDBSuite) SetUpSuite(c *C) {
	trySkipDBTest(c)

	var err error

	s.schemaName = "test_db"

	uri := "memory://test"
	s.store, err = tidb.NewStore(uri)
	c.Assert(err, IsNil)

	s.db, err = sql.Open("tidb", fmt.Sprintf("%s/%s", uri, s.schemaName))
	c.Assert(err, IsNil)

	s.s, err = tidb.CreateSession(s.store)
	c.Assert(err, IsNil)

	s.mustExec(c, "create table t1 (c1 int, c2 int, c3 int, primary key(c1))")
	s.mustExec(c, "create table t2 (c1 int, c2 int, c3 int)")

	// set proper schema lease
	s.lease = 500 * time.Millisecond
	ctx := s.s.(context.Context)
	sessionctx.GetDomain(ctx).SetLease(s.lease)
}
开发者ID:duzhanyuan,项目名称:tidb,代码行数:25,代码来源:ddl_db_test.go

示例10: SetUpSuite

func (p *testFromSuit) SetUpSuite(c *C) {
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	p.vars = map[string]interface{}{}
	p.txn, _ = store.Begin()
	p.cols = []*column.Col{
		{
			ColumnInfo: model.ColumnInfo{
				ID:           0,
				Name:         model.NewCIStr("id"),
				Offset:       0,
				DefaultValue: 0,
				FieldType:    *types.NewFieldType(mysql.TypeLonglong),
			},
		},
		{
			ColumnInfo: model.ColumnInfo{
				ID:           1,
				Name:         model.NewCIStr("name"),
				Offset:       1,
				DefaultValue: nil,
				FieldType:    *types.NewFieldType(mysql.TypeVarchar),
			},
		},
	}
	p.tbl = tables.NewTable(1, "t", "test", p.cols, &simpleAllocator{})
	variable.BindSessionVars(p)

	var i int64
	for i = 0; i < 10; i++ {
		p.tbl.AddRecord(p, []interface{}{i * 10, "hello"})
	}
}
开发者ID:rose1988c,项目名称:tidb,代码行数:33,代码来源:from_test.go

示例11: TestValidator

func (s *testValidatorSuite) TestValidator(c *C) {
	cases := []struct {
		sql       string
		inPrepare bool
		err       error
	}{
		{"select ?", false, parser.ErrSyntax},
		{"select ?", true, nil},
		{"create table t(id int not null auto_increment default 2, key (id))", true,
			errors.New("Invalid default value for 'id'")},
		{"create table t(id int not null default 2 auto_increment, key (id))", true,
			errors.New("Invalid default value for 'id'")},
		{"create table t(id int not null auto_increment)", true,
			errors.New("Incorrect table definition; there can be only one auto column and it must be defined as a key")},
		{"create table t(id int not null auto_increment, c int auto_increment, key (id, c))", true,
			errors.New("Incorrect table definition; there can be only one auto column and it must be defined as a key")},
		{"create table t(id int not null auto_increment, c int, key (c, id))", true,
			errors.New("Incorrect table definition; there can be only one auto column and it must be defined as a key")},
		{"create table t(id decimal auto_increment, key (id))", true,
			errors.New("Incorrect column specifier for column 'id'")},
		{"create table t(id float auto_increment, key (id))", true, nil},
	}
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	se, err := tidb.CreateSession(store)
	c.Assert(err, IsNil)
	for _, ca := range cases {
		stmts, err1 := tidb.Parse(se.(context.Context), ca.sql)
		c.Assert(err1, IsNil)
		c.Assert(stmts, HasLen, 1)
		stmt := stmts[0]
		err = optimizer.Validate(stmt, ca.inPrepare)
		c.Assert(terror.ErrorEqual(err, ca.err), IsTrue)
	}
}
开发者ID:astaxie,项目名称:tidb,代码行数:35,代码来源:validator_test.go

示例12: main

func main() {
	tidb.RegisterLocalStore("boltdb", boltdb.Driver{})
	tidb.RegisterStore("tikv", tikv.Driver{})

	metric.RunMetric(3 * time.Second)
	printer.PrintTiDBInfo()
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Parse()

	if *lease < 0 {
		log.Fatalf("invalid lease seconds %d", *lease)
	}

	tidb.SetSchemaLease(time.Duration(*lease) * time.Second)

	cfg := &server.Config{
		Addr:       fmt.Sprintf(":%s", *port),
		LogLevel:   *logLevel,
		StatusAddr: fmt.Sprintf(":%s", *statusPort),
		Socket:     *socket,
	}

	log.SetLevelByString(cfg.LogLevel)
	store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *store, *storePath))
	if err != nil {
		log.Fatal(errors.ErrorStack(err))
	}
	// Create a session to load information schema.
	se, err := tidb.CreateSession(store)
	if err != nil {
		log.Fatal(errors.ErrorStack(err))
	}
	se.Close()

	var driver server.IDriver
	driver = server.NewTiDBDriver(store)
	var svr *server.Server
	svr, err = server.NewServer(cfg, driver)
	if err != nil {
		log.Fatal(errors.ErrorStack(err))
	}

	sc := make(chan os.Signal, 1)
	signal.Notify(sc,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGTERM,
		syscall.SIGQUIT)

	go func() {
		sig := <-sc
		log.Infof("Got signal [%d] to exit.", sig)
		svr.Close()
		os.Exit(0)
	}()

	log.Error(svr.Run())
}
开发者ID:anywhy,项目名称:tidb,代码行数:59,代码来源:main.go

示例13: SetUpSuite

func (p *testShowSuit) SetUpSuite(c *C) {
	var err error
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	p.vars = map[string]interface{}{}
	p.txn, _ = store.Begin()
	variable.BindSessionVars(p)
}
开发者ID:kevinhuo88888,项目名称:tidb,代码行数:8,代码来源:show_test.go

示例14: SetUpSuite

func (p *testShowSuit) SetUpSuite(c *C) {
	var err error
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	p.ctx = mock.NewContext()
	p.txn, _ = store.Begin()
	variable.BindSessionVars(p.ctx)
}
开发者ID:stumaxim28,项目名称:tidb,代码行数:8,代码来源:show_test.go

示例15: createStore

func createStore() kv.Storage {
	fullPath := fmt.Sprintf("%s://%s", *store, *storePath)
	store, err := tidb.NewStore(fullPath)
	if err != nil {
		log.Fatal(errors.ErrorStack(err))
	}
	return store
}
开发者ID:pingcap,项目名称:tidb,代码行数:8,代码来源:main.go


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