func (s *testBinlogSuite) SetUpSuite(c *C) { logLevel := os.Getenv("log_level") log.SetLevelByString(logLevel) store, err := tikv.NewMockTikvStore() c.Assert(err, IsNil) s.store = store tidb.SetSchemaLease(0) s.unixFile = "/tmp/mock-binlog-pump" os.Remove(s.unixFile) l, err := net.Listen("unix", s.unixFile) c.Assert(err, IsNil) s.serv = grpc.NewServer() s.pump = new(mockBinlogPump) binlog.RegisterPumpServer(s.serv, s.pump) go s.serv.Serve(l) opt := grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { return net.DialTimeout("unix", addr, timeout) }) clientCon, err := grpc.Dial(s.unixFile, opt, grpc.WithInsecure()) c.Assert(err, IsNil) c.Assert(clientCon, NotNil) binloginfo.PumpClient = binlog.NewPumpClient(clientCon) s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") domain := sessionctx.GetDomain(s.tk.Se.(context.Context)) s.ddl = domain.DDL() }
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)) } }
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()) }
func main() { 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, } log.SetLevelByString(cfg.LogLevel) store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *store, *storePath)) if err != nil { log.Fatal(err) } var driver server.IDriver driver = server.NewTiDBDriver(store) var svr *server.Server svr, err = server.NewServer(cfg, driver) if err != nil { log.Fatal(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()) }
func (s *testSuite) SetUpSuite(c *C) { s.Parser = parser.New() flag.Lookup("mockTikv") useMockTikv := *mockTikv if useMockTikv { store, err := tikv.NewMockTikvStore() c.Assert(err, IsNil) s.store = store tidb.SetSchemaLease(0) } else { store, err := tidb.NewStore("memory://test/test") c.Assert(err, IsNil) s.store = store } logLevel := os.Getenv("log_level") log.SetLevelByString(logLevel) executor.BaseLookupTableTaskSize = 2 }
func (s *testDBSuite) SetUpSuite(c *C) { var err error s.lease = 100 * time.Millisecond tidb.SetSchemaLease(s.lease) s.schemaName = "test_db" s.store, err = tidb.NewStore(tidb.EngineGoLevelDBMemory) c.Assert(err, IsNil) localstore.MockRemoteStore = true s.s, err = tidb.CreateSession(s.store) c.Assert(err, IsNil) _, err = s.s.Execute("create database test_db") c.Assert(err, IsNil) _, err = s.s.Execute("use " + s.schemaName) c.Assert(err, IsNil) _, err = s.s.Execute("create table t1 (c1 int, c2 int, c3 int, primary key(c1))") c.Assert(err, IsNil) _, err = s.s.Execute("create table t2 (c1 int, c2 int, c3 int)") c.Assert(err, IsNil) }
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) var svr *relay.Server svr, err = relay.NewServer(driver, fmt.Sprintf(":%s", *port), *relayPath) if err != nil { log.Fatal(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() time.Sleep(1 * time.Second) os.Exit(0) }() log.Error(svr.Run()) }
func (s *testBinlogSuite) SetUpSuite(c *C) { logLevel := os.Getenv("log_level") log.SetLevelByString(logLevel) store, err := tikv.NewMockTikvStore() c.Assert(err, IsNil) s.store = store tidb.SetSchemaLease(0) s.unixFile = "/tmp/mock-binlog-pump" l, err := net.Listen("unix", s.unixFile) c.Assert(err, IsNil) s.serv = grpc.NewServer() s.pump = new(mockBinlogPump) binlog.RegisterPumpServer(s.serv, s.pump) go s.serv.Serve(l) opt := grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { return net.DialTimeout("unix", addr, timeout) }) clientCon, err := grpc.Dial(s.unixFile, opt, grpc.WithInsecure()) c.Assert(err, IsNil) c.Assert(clientCon, NotNil) binloginfo.PumpClient = binlog.NewPumpClient(clientCon) }
func main() { tidb.RegisterLocalStore("boltdb", boltdb.Driver{}) tidb.RegisterStore("tikv", tikv.Driver{}) runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() if *version { printer.PrintRawTiDBInfo() os.Exit(0) } leaseDuration := parseLease() tidb.SetSchemaLease(leaseDuration) cfg := &server.Config{ Addr: fmt.Sprintf("%s:%s", *host, *port), LogLevel: *logLevel, StatusAddr: fmt.Sprintf(":%s", *statusPort), Socket: *socket, ReportStatus: *reportStatus, } // set log options if len(*logFile) > 0 { err := log.SetOutputByName(*logFile) if err != nil { log.Fatal(errors.ErrorStack(err)) } log.SetRotateByDay() log.SetHighlighting(false) } if joinCon != nil && *joinCon > 0 { plan.JoinConcurrency = *joinCon } plan.AllowCartesianProduct = *crossJoin // Call this before setting log level to make sure that TiDB info could be printed. printer.PrintTiDBInfo() log.SetLevelByString(cfg.LogLevel) store := createStore() if *enablePS { perfschema.EnablePerfSchema() } if *binlogSocket != "" { createBinlogClient() } // 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) }() go systimemon.StartMonitor(time.Now, func() { log.Error("error: system time jump backward") }) pushMetric(*metricsAddr, time.Duration(*metricsInterval)*time.Second) log.Error(svr.Run()) }
func main() { printer.PrintTiDBInfo() flag.Parse() log.SetLevelByString(*logLevel) // support for signal notify runtime.GOMAXPROCS(runtime.NumCPU()) line = liner.NewLiner() defer line.Close() line.SetCtrlCAborts(true) openHistory() tidb.SetSchemaLease(time.Duration(*lease) * time.Second) mdb, err := sql.Open(tidb.DriverName, *store+"://"+*dbPath) if err != nil { log.Fatal(errors.ErrorStack(err)) } for { l, err := readStatement("tidb> ") if mayExit(err, l) { return } line.AppendHistory(l) // if we're in transaction if strings.HasPrefix(l, "BEGIN") || strings.HasPrefix(l, "begin") { tx, err := mdb.Begin() if err != nil { log.Error(errors.ErrorStack(err)) continue } for { txnLine, err := readStatement(">> ") if mayExit(err, txnLine) { return } line.AppendHistory(txnLine) if !strings.HasSuffix(txnLine, ";") { txnLine += ";" } if strings.HasPrefix(txnLine, "COMMIT") || strings.HasPrefix(txnLine, "commit") { err = tx.Commit() if err != nil { log.Error(errors.ErrorStack(err)) tx.Rollback() } break } // normal sql statement err = executeLine(tx, txnLine) if err != nil { log.Error(errors.ErrorStack(err)) tx.Rollback() break } } } else { tx, err := mdb.Begin() if err != nil { log.Error(errors.ErrorStack(err)) continue } err = executeLine(tx, l) if err != nil { log.Error(errors.ErrorStack(err)) tx.Rollback() continue } err = tx.Commit() if err != nil { log.Error(errors.ErrorStack(err)) } } } }
func main() { tidb.RegisterLocalStore("boltdb", boltdb.Driver{}) tidb.RegisterStore("tikv", tikv.Driver{}) metric.RunMetric(3 * time.Second) 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:%s", *host, *port), LogLevel: *logLevel, StatusAddr: fmt.Sprintf(":%s", *statusPort), Socket: *socket, ReportStatus: *reportStatus, } // set log options if len(*logFile) > 0 { err := log.SetOutputByName(*logFile) if err != nil { log.Fatal(errors.ErrorStack(err)) } log.SetRotateByDay() } // Call this before setting log level to make sure that TiDB info could be printed. printer.PrintTiDBInfo() log.SetLevelByString(cfg.LogLevel) store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *store, *storePath)) if err != nil { log.Fatal(errors.ErrorStack(err)) } if *enablePS { perfschema.EnablePerfSchema() } if !*useNewPlan { plan.UseNewPlanner = false } parser.UseNewLexer = *useNewLexer // 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) }() go systimemon.StartMonitor(time.Now, func() { log.Error("error: system time jump backward") }) log.Error(svr.Run()) }