func InitLog(runmode, path string) { log.SetLevelByString("info") if runmode == "dev" { log.SetLevelByString("debug") } log.SetOutputByName(path) }
func main() { flag.Parse() log.SetLevelByString(*logLevel) cfg := &server.Config{ Addr: *addr, ZKAddr: *zk, RootPath: *rootPath, SaveInterval: *interval, } oracle, err := server.NewTimestampOracle(cfg) if err != nil { log.Fatal(err) } go http.ListenAndServe(":5555", nil) 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) oracle.Close() os.Exit(0) }() oracle.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" 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 (s *testStmtSuite) SetUpTest(c *C) { log.SetLevelByString("error") s.dbName = "teststmts" var err error s.testDB, err = sql.Open(tidb.DriverName, tidb.EngineGoLevelDBMemory+"/"+s.dbName+"/"+s.dbName) c.Assert(err, IsNil) // create db s.createDBSql = fmt.Sprintf("create database if not exists %s;", s.dbName) s.dropDBSql = fmt.Sprintf("drop database if exists %s;", s.dbName) s.useDBSql = fmt.Sprintf("use %s;", s.dbName) s.createTableSql = ` CREATE TABLE test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id)); CREATE TABLE test1(id INT NOT NULL DEFAULT 2, name varchar(255), PRIMARY KEY(id), INDEX name(name)); CREATE TABLE test2(id INT NOT NULL DEFAULT 3, name varchar(255), PRIMARY KEY(id));` s.selectSql = `SELECT * from test limit 2;` mustExec(c, s.testDB, s.createDBSql) mustExec(c, s.testDB, s.useDBSql) s.createSystemDBSQL = fmt.Sprintf("create database if not exists %s;", mysql.SystemDB) s.createUserTableSQL = tidb.CreateUserTable mustExec(c, s.testDB, s.createSystemDBSQL) mustExec(c, s.testDB, s.createUserTableSQL) }
func (t *testPrivilegeSuite) SetUpTest(c *C) { log.SetLevelByString("error") t.dbName = "test" t.store = newStore(c, t.dbName) se := newSession(c, t.store, t.dbName) t.createDBSQL = fmt.Sprintf("create database if not exists %s;", t.dbName) t.createDB1SQL = fmt.Sprintf("create database if not exists %s1;", t.dbName) t.dropDBSQL = fmt.Sprintf("drop database if exists %s;", t.dbName) t.useDBSQL = fmt.Sprintf("use %s;", t.dbName) t.createTableSQL = `CREATE TABLE test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));` mustExec(c, se, t.createDBSQL) mustExec(c, se, t.createDB1SQL) // create database test1 mustExec(c, se, t.useDBSQL) mustExec(c, se, t.createTableSQL) t.createSystemDBSQL = fmt.Sprintf("create database if not exists %s;", mysql.SystemDB) t.createUserTableSQL = tidb.CreateUserTable t.createDBPrivTableSQL = tidb.CreateDBPrivTable t.createTablePrivTableSQL = tidb.CreateTablePrivTable t.createColumnPrivTableSQL = tidb.CreateColumnPrivTable mustExec(c, se, t.createSystemDBSQL) mustExec(c, se, t.createUserTableSQL) mustExec(c, se, t.createDBPrivTableSQL) mustExec(c, se, t.createTablePrivTableSQL) mustExec(c, se, t.createColumnPrivTableSQL) }
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)) } }
// OpenDB opens the database in the given directory; if required, the database // will be initialized. func OpenDB(dir string) (err error) { log.SetLevelByString("error") dir = filepath.Join(dir, "tidb") _, err = os.Stat(dir) init := os.IsNotExist(err) name := "tidb" db, err = sqlx.Open("tidb", "goleveldb://"+dir+"/"+name) if err != nil { return fmt.Errorf("db open failed: %s", err) } if err := db.Ping(); err != nil { return fmt.Errorf("db ping failed: %s", err) } if init { // b, err := ioutil.ReadFile(filepath.Join("data", "schema.sql")) // if err != nil { // return fmt.Errorf("read schema file failed: %s", err) // } // if _, err = db.Exec(string(b)); err != nil { if _, err = db.Exec(schemasql); err != nil { return fmt.Errorf("exec schema failed: %s", err) } if err = insertCards(); err != nil { return fmt.Errorf("insert cards failed: %s", err) } } return nil }
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 (s *testTableRsetSuite) SetUpSuite(c *C) { log.SetLevelByString("error") s.dbName = "rset_test" s.tableName = "rset_table" s.createTableSql = fmt.Sprintf("create table if not exists %s(id int);", s.tableName) s.querySql = fmt.Sprintf("select * from %s;", s.tableName) }
func main() { log.SetLevelByString(*logLevel) createTable(forceDrop) { timing("insert test data", func() { insertTestData(*concurrent) }) } }
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) log.SetLevelByString("warn") }
func main() { log.SetLevelByString(*logLevel) timing("create table", func() { createTable() }) timing("insert test data", func() { insertTestData(*rows, *concurrent) }) }
func main() { flag.Parse() log.SetLevelByString("warn") go http.ListenAndServe(":9191", nil) value := make([]byte, *valueSize) t := time.Now() batchRawPut(value) fmt.Printf("\nelapse:%v, total %v\n", time.Since(t), *dataCnt) }
func (s *testMainSuite) SetUpSuite(c *C) { s.dbName = "test_main_db" s.createDBSQL = fmt.Sprintf("create database if not exists %s;", s.dbName) s.dropDBSQL = fmt.Sprintf("drop database %s;", s.dbName) s.useDBSQL = fmt.Sprintf("use %s;", s.dbName) s.createTableSQL = ` CREATE TABLE tbl_test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id)); CREATE TABLE tbl_test1(id INT NOT NULL DEFAULT 2, name varchar(255), PRIMARY KEY(id), INDEX name(name)); CREATE TABLE tbl_test2(id INT NOT NULL DEFAULT 3, name varchar(255), PRIMARY KEY(id));` s.selectSQL = `SELECT * from tbl_test;` runtime.GOMAXPROCS(runtime.NumCPU()) log.SetLevelByString("error") }
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 (ts *TidbTestSuite) SetUpSuite(c *C) { log.SetLevelByString("error") store, err := tidb.NewStore("memory:///tmp/tidb") c.Assert(err, IsNil) ts.tidbdrv = NewTiDBDriver(store) cfg := &Config{ Addr: ":4001", LogLevel: "debug", StatusAddr: ":10090", } server, err := NewServer(cfg, ts.tidbdrv) c.Assert(err, IsNil) ts.server = server go ts.server.Run() time.Sleep(time.Millisecond * 100) }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) log.SetLevelByString("debug") log.Errorf("begin create table") dropTable(tblName1) createTable(tblName1) dropTable(tblName2) createTable(tblName2) log.Errorf("create table finish") go func() { log.Error(http.ListenAndServe("localhost:8889", nil)) }() batchInsert(5, 50000) }
func main() { log.SetLevelByString(*logLevel) createTable(forceDrop) { timing("insert test data", func() { insertTestData(*rows, *concurrent) }) if !*insertOnly { timing("select point data", func() { selectPointTestData(*rows, *N, *concurrent) }) timing("select range data", func() { selectRangeTestData(*rows, *N, *concurrent) }) } } }
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 init() { // set log settings log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlDebug, ext.FatalHandler(log15.StderrHandler))) // close tidb debug log.SetLevelByString("error") tidb.Debug = false // init global vars var ( config *Config = NewConfig() database *Db = NewDB(config.Db.Driver, config.Db.DSN) server *Web = NewWeb(config.Http.Host, config.Http.Port, config.Http.Protocol) ) Injector = pucore.NewInjector(config, database, server) Behavior = pucore.NewBehaviors() Modular = pucore.NewModular(Injector, Behavior) }
func main() { printer.PrintTiDBInfo() runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() cfg := &server.Config{ Addr: fmt.Sprintf(":%s", *port), User: "******", Password: "", LogLevel: *logLevel, } log.SetLevelByString(cfg.LogLevel) store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *store, *storePath)) if err != nil { log.Fatal(err) } server.CreateTiDBTestDatabase(store) 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 (ts *TidbTestSuite) SetUpSuite(c *C) { log.SetLevelByString("error") store, err := tidb.NewStore("memory:///tmp/tidb") c.Assert(err, IsNil) ts.tidbdrv = NewTiDBDriver(store) cfg := &Config{ Addr: ":4001", LogLevel: "debug", StatusAddr: ":10090", ReportStatus: true, } server, err := NewServer(cfg, ts.tidbdrv) c.Assert(err, IsNil) ts.server = server go ts.server.Run() waitUntilServerOnline() // Run this test here because parallel would affect the result of it. runTestStmtCount(c) }
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 (s *testRelaySuite) SetUpSuite(c *C) { log.SetLevelByString("error") store, err := tidb.NewStore("memory://test/test") c.Assert(err, IsNil) s.store = store s.path = "/tmp/test_mysqlrelay.log" server, err := NewServer(NewTiDBDriver(store), ":4001", s.path) c.Assert(err, IsNil) s.server = server go server.Run() time.Sleep(time.Millisecond * 100) dsn := "root@tcp(localhost:4001)/test?strict=true" db, err := sql.Open("mysql", dsn) c.Assert(err, IsNil) s.db = db }
func main() { // Default log level is debug, set it to error to turn off debug log. log.SetLevelByString("error") // DriverName is 'tidb', dataSourceName is in the form of "<engine>://<dbPath>/<dbName>". // dbPath is the directory that stores the data files if you use a local storage engine. // dbName is the name of the database which you want to use. dbPath := "/Users/carolove/Project/tidb" dbName := "tidb" db, err := sql.Open("tidb", "goleveldb://"+dbPath+"/"+dbName) if err != nil { log.Fatal(err) } defer db.Close() _, err = db.Exec("CREATE TABLE IF NOT EXISTS user (email CHAR(20), name CHAR(20), password CHAR(20))") if err != nil { log.Fatal(err) } _, err = db.Exec("INSERT INTO user VALUES (?,?,?)", "*****@*****.**", "chendan", "!honeywell1") if err != nil { log.Fatal(err) } row := db.QueryRow("SELECT email, name, password FROM user WHERE email = ?", "*****@*****.**") var email, name, password string err = row.Scan(&email, &name, &password) if err != nil { log.Fatal(err) } fmt.Printf("email is %s, name is %s, password is %s\n", email, name, password) _, err = db.Exec("DROP TABLE user") if err != nil { log.Fatal(err) } }
func main() { flag.Parse() log.SetLevelByString("error") Init() value := make([]byte, *valueSize) t := time.Now() batchRW(value) resp, err := http.Get("http://localhost:9191/metrics") if err != nil { log.Fatal(err) } defer resp.Body.Close() text, err1 := ioutil.ReadAll(resp.Body) if err1 != nil { log.Fatal(err) } fmt.Println(string(text)) fmt.Printf("\nelapse:%v, total %v\n", time.Since(t), *dataCnt) }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) log.SetLevelByString("debug") log.Errorf("begin create table") dropTable(tblName1) createTable(tblName1) dropTable(tblName2) createTable(tblName2) log.Errorf("create table finish") go func() { log.Error(http.ListenAndServe("localhost:8889", nil)) }() wg := &sync.WaitGroup{} for i := 0; i < 10; i++ { wg.Add(1) go func() { batchInsert(1, 50000) wg.Done() }() } wg.Wait() }
func init() { log.SetLevelByString("warn") }
func init() { // disable unittest annoying log log.SetLevelByString("error") }