本文整理汇总了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)
}
示例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)
}
示例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()
}
示例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)
}
示例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))
}
}
示例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");`)
}
示例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()
}
示例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))
}
}
}
示例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)
}
示例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"})
}
}
示例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)
}
}
示例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())
}
示例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)
}
示例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)
}
示例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
}