Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用rebalance工具进行数据均衡,默认会使用default数据库 #45

Closed
FoolishWall opened this issue Apr 26, 2021 · 0 comments

Comments

@FoolishWall
Copy link

问题描述:使用rebalance工具进行数据均衡,制定均衡计划的时候,表的名称是db.table,执行的时候,表的名称就剩table了,导致会默认使用default数据库,然后报错。

报错日志:got error code: 60, message: Table default.store_sales_local doesn't exist

相关代码(目前猜测原因,见如下代码注释)

func (this *CKRebalance) DoRebalance() (err error) {
	globalPool = common.NewWorkerPool(len(this.Hosts), len(this.CKConns))
	for _, database := range this.Databases {
		tables := this.DBTables[database]
		for _, table := range tables {
			tablename := fmt.Sprintf("%s.%s", database, table)
			if _, ok := this.RepTables[tablename]; !ok {
				// initialize SSH connections only if there are some non-replicated tables
				if sshErr = this.InitSshConns(database); sshErr != nil {
					log.Logger.Warnf("failed to init ssh connections, error: %+v", sshErr)
				}
				break
			}
		}
		for _, table := range tables {
			var tbls []*TblPartitions
			if tbls, err = this.GetState(database, table); err != nil {
				log.Logger.Errorf("got error %+v", err)
				return err
			}
			this.GeneratePlan(fmt.Sprintf("%s.%s", database, table), tbls)
			wg := sync.WaitGroup{}
			wg.Add(len(tbls))
			var gotError bool
			for i := 0; i < len(tbls); i++ {
				tbl := tbls[i]
				_ = globalPool.Submit(func() {
//主要原因:执行rebalance计划的时候,使用的是tbl中的table信息,tbl中的table信息并没有带上database的信息
					if err := this.ExecutePlan(database, tbl); err != nil {
						log.Logger.Errorf("host: %s, got error %+v", tbl.Host, err)
						gotError = true
					} else {
						log.Logger.Infof("table %s host %s rebalance done", tbl.Table, tbl.Host)
					}
					wg.Done()
				})
			}
			wg.Wait()
			if gotError {
				return err
			}
			log.Logger.Infof("table %s rebalance done", table)
		}
	}
	return nil
}
YenchangChan added a commit to YenchangChan/ckman that referenced this issue Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant