func (s *Server) resetSchemaInfo() error { for _, c := range s.clients { if len(c.txConns) > 0 { return errors.Errorf("transaction exist") } } cfg, err := config.ParseConfigFile(s.configFile) if err != nil { log.Error(err) return err } s.cleanup() s.autoSchamas = make(map[string]*tabletserver.SchemaInfo) for _, n := range s.shards { n.Close() } s.shards = nil s.schemas = nil log.Warningf("%#v", cfg) log.SetLevelByString(cfg.LogLevel) s.cfg = cfg return s.loadSchemaInfo() }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() if len(*configFile) == 0 { log.Error("must use a config file") return } cfg, err := config.ParseConfigFile(*configFile) if err != nil { log.Error(err.Error()) return } log.SetLevelByString(cfg.LogLevel) log.CrashLog("./cm-proxy.dump") var svr *proxy.Server svr, err = proxy.NewServer(*configFile) if err != nil { log.Error(err.Error()) return } 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 svr.Run() http.HandleFunc("/api/reload", svr.HandleReload) //todo: using configuration http.ListenAndServe(":8888", nil) }
func makeServer(configFile string) *Server { cfg, err := config.ParseConfigFile(configFile) if err != nil { log.Error(err.Error()) return nil } log.Warningf("%#v", cfg) s := &Server{ configFile: configFile, cfg: cfg, addr: cfg.Addr, user: cfg.User, password: cfg.Password, autoSchamas: make(map[string]*tabletserver.SchemaInfo), taskQ: make(chan *execTask, 100), concurrentLimiter: tokenlimiter.NewTokenLimiter(100), counter: stats.NewCounters("stats"), rwlock: &sync.RWMutex{}, clients: make(map[uint32]*Conn), } f := func(wg *sync.WaitGroup, rs []interface{}, i int, co *mysql.SqlConn, sql string, args []interface{}) { r, err := co.Execute(sql, args...) if err != nil { log.Warning(err) rs[i] = err } else { rs[i] = r } wg.Done() } for i := 0; i < 100; i++ { go func() { for task := range s.taskQ { f(task.wg, task.rs, task.idx, task.co, task.sql, task.args) } }() } return s }