Skip to content

Commit

Permalink
cmd: Make changefeed sort dir visible (#2222) (#2239)
Browse files Browse the repository at this point in the history
* make sort-dir field visible in changefeed info struct.

* fix related tests.

* add a simple test for sort-dir field.

* add dir checker .

* do not remove new created directory.

* update log.

* print log to make debug for data-dir easier.

Co-authored-by: Ling Jin <[email protected]>
  • Loading branch information
ti-chi-bot and 3AceShowHand authored Jul 8, 2021
1 parent b5c7b35 commit bf28daa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cdc/kv/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func (s *etcdSuite) TestOpChangeFeedDetail(c *check.C) {
ctx := context.Background()
detail := &model.ChangeFeedInfo{
SinkURI: "root@tcp(127.0.0.1:3306)/mysql",
SortDir: "/old-version/sorter",
}
cfID := "test-op-cf"

Expand All @@ -236,6 +237,7 @@ func (s *etcdSuite) TestOpChangeFeedDetail(c *check.C) {
d, err := s.client.GetChangeFeedInfo(ctx, cfID)
c.Assert(err, check.IsNil)
c.Assert(d.SinkURI, check.Equals, detail.SinkURI)
c.Assert(d.SortDir, check.Equals, detail.SortDir)

err = s.client.LeaseGuardDeleteChangeFeedInfo(ctx, cfID, sess.Lease())
c.Assert(err, check.IsNil)
Expand Down
4 changes: 3 additions & 1 deletion cdc/model/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ type ChangeFeedInfo struct {
AdminJobType AdminJobType `json:"admin-job-type"`
Engine SortEngine `json:"sort-engine"`
// SortDir is deprecated
SortDir string `json:"-"`
// it cannot be set by user in changefeed level, any assignment to it should be ignored.
// but can be fetched for backward compatibility
SortDir string `json:"sort-dir"`

Config *config.ReplicaConfig `json:"config"`
State FeedState `json:"state"`
Expand Down
1 change: 1 addition & 0 deletions cdc/model/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (s *configSuite) TestFillV1(c *check.C) {
},
StartTs: 417136892416622595,
Engine: "memory",
SortDir: ".",
Config: &config.ReplicaConfig{
CaseSensitive: true,
Filter: &config.FilterConfig{
Expand Down
25 changes: 17 additions & 8 deletions cdc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,8 @@ func (s *Server) initDataDir(ctx context.Context) error {
return errors.Trace(err)
}

if diskInfo.Avail < dataDirThreshold {
log.Warn(fmt.Sprintf("%s is set as data-dir (%dGB available), ticdc recommend disk for data-dir "+
"at least have %dGB available space", conf.DataDir, diskInfo.Avail, dataDirThreshold))
}
log.Info(fmt.Sprintf("%s is set as data-dir (%dGB available), ticdc recommend disk for data-dir "+
"at least have %dGB available space", conf.DataDir, diskInfo.Avail, dataDirThreshold))

return nil
}
Expand Down Expand Up @@ -424,14 +422,25 @@ func (s *Server) setUpDataDir(ctx context.Context) error {
// at the moment, only consider available disk space
func findBestDataDir(candidates []string) (result string, ok bool) {
var low uint64 = 0
for _, dir := range candidates {

checker := func(dir string) (*util.DiskInfo, error) {
if err := os.MkdirAll(dir, 0o755); err != nil {
return nil, err
}
if err := util.IsDirReadWritable(dir); err != nil {
log.Warn("try to get disk info failed", zap.String("dir", dir), zap.Error(err))
continue
return nil, err
}
info, err := util.GetDiskInfo(dir)
if err != nil {
log.Warn("try to get disk info failed", zap.String("dir", dir), zap.Error(err))
return nil, err
}
return info, err
}

for _, dir := range candidates {
info, err := checker(dir)
if err != nil {
log.Warn("check the availability of dir", zap.String("dir", dir), zap.Error(err))
continue
}
if info.Avail > low {
Expand Down

0 comments on commit bf28daa

Please sign in to comment.