This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get subtask config and status of v1.0.x from dm-worker (#846)
- Loading branch information
1 parent
261d7b5
commit f571300
Showing
26 changed files
with
1,859 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2020 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package worker | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/pingcap/dm/dm/pb" | ||
"github.com/pingcap/dm/pkg/log" | ||
"github.com/pingcap/dm/pkg/v1workermeta" | ||
) | ||
|
||
// OperateV1Meta implements WorkerServer.OperateV1Meta. | ||
func (s *Server) OperateV1Meta(ctx context.Context, req *pb.OperateV1MetaRequest) (*pb.OperateV1MetaResponse, error) { | ||
log.L().Info("", zap.String("request", "OperateV1Meta"), zap.Stringer("payload", req)) | ||
|
||
switch req.Op { | ||
case pb.V1MetaOp_GetV1Meta: | ||
meta, err := v1workermeta.GetSubtasksMeta() | ||
if err != nil { | ||
return &pb.OperateV1MetaResponse{ | ||
Result: false, | ||
Msg: err.Error(), | ||
}, nil | ||
} | ||
return &pb.OperateV1MetaResponse{ | ||
Result: true, | ||
Meta: meta, | ||
}, nil | ||
case pb.V1MetaOp_RemoveV1Meta: | ||
err := v1workermeta.RemoveSubtasksMeta() | ||
if err != nil { | ||
return &pb.OperateV1MetaResponse{ | ||
Result: false, | ||
Msg: err.Error(), | ||
}, nil | ||
} | ||
return &pb.OperateV1MetaResponse{ | ||
Result: true, | ||
}, nil | ||
default: | ||
return &pb.OperateV1MetaResponse{ | ||
Result: false, | ||
Msg: fmt.Sprintf("invalid op %s", req.Op.String()), | ||
}, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright 2020 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package v1workermeta | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
|
||
"github.com/BurntSushi/toml" | ||
|
||
"github.com/pingcap/dm/dm/config" | ||
"github.com/pingcap/dm/dm/pb" | ||
"github.com/pingcap/dm/pkg/terror" | ||
"github.com/pingcap/dm/pkg/utils" | ||
) | ||
|
||
// `var` rather than `const` for testing. | ||
var ( | ||
// metaPath is the meta data path in v1.0.x. | ||
metaPath = "./dm_worker_meta" | ||
// dbPath is the levelDB path in v1.0.x. | ||
dbPath = "./dm_worker_meta/kv" | ||
) | ||
|
||
// v1SubTaskConfig represents the subtask config in v1.0.x. | ||
type v1SubTaskConfig struct { | ||
config.SubTaskConfig // embed the subtask config in v2.0.x. | ||
|
||
// NOTE: in v1.0.x, `ChunkFilesize` is `int64`, but in v2.0.x it's `string`. | ||
// (ref: https://github.com/pingcap/dm/pull/713). | ||
// if we decode data with v1.0.x from TOML directly, | ||
// an error of `toml: cannot load TOML value of type int64 into a Go string` will be reported, | ||
// so we overwrite it with another filed which has the same struct tag `chunk-filesize` here. | ||
// but if set `chunk-filesize: 64` in a YAML file, both v1.0.x (int64) and v2.0.x (string) can support it. | ||
ChunkFilesize int64 `yaml:"chunk-filesize" toml:"chunk-filesize" json:"chunk-filesize"` // -F, --chunk-filesize | ||
} | ||
|
||
// GetSubtasksMeta gets all subtasks' meta (config and status) from `dm_worker_meta` in v1.0.x. | ||
func GetSubtasksMeta() (map[string]*pb.V1SubTaskMeta, error) { | ||
// check if meta data exist. | ||
if !utils.IsDirExists(metaPath) || !utils.IsDirExists(dbPath) { | ||
return nil, nil | ||
} | ||
|
||
// open levelDB to get subtasks meta. | ||
db, err := openDB(dbPath, defaultKVConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer db.Close() | ||
|
||
// load subtasks' meta from levelDB. | ||
meta, err := newMeta(db) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return meta.TasksMeta(), nil | ||
} | ||
|
||
// RemoveSubtasksMeta removes subtasks' metadata. | ||
// this is often called after upgraded from v1.0.x to v2.0.x, | ||
// so no need to handle again after re-started the DM-worker process. | ||
func RemoveSubtasksMeta() error { | ||
// check is a valid v1.0.x meta path. | ||
if !utils.IsDirExists(metaPath) || !utils.IsDirExists(dbPath) { | ||
return terror.ErrInvalidV1WorkerMetaPath.Generate(filepath.Abs(metaPath)) | ||
} | ||
|
||
// try to open levelDB to check. | ||
db, err := openDB(dbPath, defaultKVConfig) | ||
if err != nil { | ||
return terror.ErrInvalidV1WorkerMetaPath.Generate(filepath.Abs(metaPath)) | ||
} | ||
defer db.Close() | ||
|
||
return os.RemoveAll(metaPath) | ||
} | ||
|
||
// SubTaskConfigFromV1TOML gets SubTaskConfig from subtask's TOML data with v1.0.x. | ||
func SubTaskConfigFromV1TOML(data []byte) (config.SubTaskConfig, error) { | ||
var v1Cfg v1SubTaskConfig | ||
_, err := toml.Decode(string(data), &v1Cfg) | ||
if err != nil { | ||
return config.SubTaskConfig{}, terror.ErrConfigTomlTransform.Delegate(err, "decode v1 subtask config from data") | ||
} | ||
|
||
cfg := v1Cfg.SubTaskConfig | ||
cfg.MydumperConfig.ChunkFilesize = strconv.FormatInt(v1Cfg.ChunkFilesize, 10) | ||
err = cfg.Adjust(true) | ||
if err != nil { | ||
return config.SubTaskConfig{}, terror.ErrConfigTomlTransform.Delegate(err, "transform `chunk-filesize`") | ||
} | ||
|
||
return cfg, nil | ||
} |
Oops, something went wrong.