Beispiel #1
0
func (c *Conf) CheckConfigUpdate(notifyChans ...chan bool) {
	if c.proxyConfig.Global.ConfAutoload == 1 {
		for {
			//TODO sleep config by the config file
			time.Sleep(time.Second * 10)
			//log.Infof("CheckConfigUpdate checking")
			fileinfo, err := os.Stat(c.path)
			if err != nil {
				log.Errorf("CheckConfigUpdate error %s", err.Error())
				continue
			}
			if c.lastModifiedTime.Before(fileinfo.ModTime()) {
				log.Infof("CheckConfigUpdate config change and load new config")
				defaultProxyConfig := getDefaultProxyConfig()
				err = c.parseConfigFile(defaultProxyConfig)
				if err != nil {
					log.Errorf("CheckConfigUpdate error %s", err.Error())
					continue
				}
				c.lastModifiedTime = fileinfo.ModTime()
				//goroutine need mutex lock
				c.mu.Lock()
				c.proxyConfig = defaultProxyConfig
				c.mu.Unlock()
				//modify the log level when update
				log.SetLevel(log.LogLevel(conf.proxyConfig.Global.LogLevel))

				for _, notifyChan := range notifyChans {
					notifyChan <- true
				}
			}
		}

	}
}
Beispiel #2
0
func prepareBenchSession() Session {
	store, err := NewStore("memory://bench")
	if err != nil {
		log.Fatal(err)
	}
	log.SetLevel(log.LOG_LEVEL_ERROR)
	se, err := CreateSession(store)
	if err != nil {
		log.Fatal(err)
	}
	mustExecute(se, "use test")
	return se
}
Beispiel #3
0
func LoadConfig(path string) (*Conf, error) {
	fileinfo, err := os.Stat(path)
	if err != nil {
		return nil, err
	}
	conf.path = path
	defaultProxyConfig := getDefaultProxyConfig()
	err = conf.parseConfigFile(defaultProxyConfig)
	if err != nil {
		return nil, err
	}
	conf.lastModifiedTime = fileinfo.ModTime()
	conf.proxyConfig = defaultProxyConfig
	//set the log lever from base on conf
	log.SetLevel(log.LogLevel(conf.proxyConfig.Global.LogLevel))
	return &conf, err
}
Beispiel #4
0
func newTestServer() (*Server, error) {
	f := func() {

		path, err := tmpFile(testConfigData)
		if err != nil {
			testServer, testServerError = nil, err
			return
		}

		defer os.Remove(path) // clean up tmp file

		cfg, err := config.LoadConfig(path)
		if err != nil {
			testServer, testServerError = nil, err
			return
		}

		if err := cluster.Init(cfg); err != nil {
			testServer, testServerError = nil, err
			return
		}

		log.SetLevel(log.LogLevel(cfg.GetConfig().Global.LogLevel))
		mysql.SetLogger(log.Logger())

		testServer, err = NewServer(cfg)
		if err != nil {
			testServer, testServerError = nil, err
			return
		}

		go testServer.Serve()

		time.Sleep(1 * time.Second)
	}

	testServerOnce.Do(f)

	return testServer, testServerError
}
Beispiel #5
0
func BenchmarkBasic(b *testing.B) {
	store, err := NewStore("memory://bench")
	if err != nil {
		b.Fatal(err)
	}
	log.SetLevel(log.LOG_LEVEL_ERROR)
	se, err := CreateSession(store)
	if err != nil {
		b.Fatal(err)
	}
	for i := 0; i < b.N; i++ {
		rs, err := se.Execute("select 1")
		if err != nil {
			b.Fatal(err)
		}
		row, err := rs[0].Next()
		if err != nil || row == nil {
			b.Fatal(err)
		}
		rs[0].Close()
	}
}
Beispiel #6
0
func init() {
	log.SetLevel(log.LOG_LEVEL_INFO)
}
Beispiel #7
0
func init() {
	log.SetLevel(log.LOG_LEVEL_ERROR)
}