Merge pull request #5823 from ywk253100/180905_adminserver

Test TCP connection before upgrading database schema
This commit is contained in:
Daniel Jiang 2018-09-06 14:19:55 +08:00 committed by GitHub
commit f0f1c4ed0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -262,13 +262,16 @@ func Init() (err error) {
return err
}
db := GetDatabaseFromCfg(envCfgs)
// Initialize the schema, then register the DB.
if err := dao.UpgradeSchema(db); err != nil {
return err
}
if err := dao.InitDatabase(db); err != nil {
return err
}
if err := dao.UpgradeSchema(db); err != nil {
return err
}
if err := dao.CheckSchemaVersion(); err != nil {
return err
}
if err := initCfgStore(); err != nil {
return err
}

View File

@ -81,6 +81,13 @@ func InitDatabase(database *models.Database) error {
if err := db.Register(); err != nil {
return err
}
log.Info("Register database completed")
return nil
}
// CheckSchemaVersion checks that whether the schema version matches with the expected one
func CheckSchemaVersion() error {
version, err := GetSchemaVersion()
if err != nil {
return err
@ -89,8 +96,6 @@ func InitDatabase(database *models.Database) error {
return fmt.Errorf("unexpected database schema version, expected %s, got %s",
SchemaVersion, version.Version)
}
log.Info("Register database completed")
return nil
}

View File

@ -88,15 +88,17 @@ func TestTCPConn(addr string, timeout, interval int) error {
cancel := make(chan int)
go func() {
n := 1
for {
select {
case <-cancel:
break
default:
conn, err := net.DialTimeout("tcp", addr, time.Duration(timeout)*time.Second)
conn, err := net.DialTimeout("tcp", addr, time.Duration(n)*time.Second)
if err != nil {
log.Errorf("failed to connect to tcp://%s, retry after %d seconds :%v",
addr, interval, err)
n = n * 2
time.Sleep(time.Duration(interval) * time.Second)
continue
}