Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

*: add print sample config #28

Merged
merged 11 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ LDFLAGS += -X "github.com/pingcap/dm/pkg/utils.GitHash=$(shell git rev-parse HEA
LDFLAGS += -X "github.com/pingcap/dm/pkg/utils.GitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
LDFLAGS += -X "github.com/pingcap/dm/pkg/utils.GoVersion=$(shell go version)"


CURDIR := $(shell pwd)
GO := GO111MODULE=on go
GOBUILD := CGO_ENABLED=0 $(GO) build
Expand All @@ -21,10 +20,18 @@ ifeq ("$(WITH_RACE)", "1")
GOBUILD = CGO_ENABLED=1 $(GO) build
endif

ARCH := "`uname -s`"
ARCH := "$(shell uname -s)"
LINUX := "Linux"
MAC := "Darwin"

ifeq ($(ARCH), $(LINUX))
LDFLAGS += -X "github.com/pingcap/dm/dm/worker.SampleConfigFile=$(shell cat dm/worker/dm-worker.toml | base64 -w 0)"
LDFLAGS += -X "github.com/pingcap/dm/dm/master.SampleConfigFile=$(shell cat dm/master/dm-master.toml | base64 -w 0)"
else
LDFLAGS += -X "github.com/pingcap/dm/dm/worker.SampleConfigFile=$(shell cat dm/worker/dm-worker.toml | base64)"
LDFLAGS += -X "github.com/pingcap/dm/dm/master.SampleConfigFile=$(shell cat dm/master/dm-master.toml | base64)"
endif

.PHONY: build test dm_integration_test_build integration_test coverage check \
dm-worker dm-master dmctl

Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ make dmctl # build dmctl

When DM is built successfully, you can find binaries in the `bin` directory.

## Installing

* The best way to install DM is via [DM-Ansible](https://pingcap.com/docs/tools/data-migration-deployment/)
* deploy DM manually
```
# Download the DM package.
wget http://download.pingcap.org/dm-latest-linux-amd64.tar.gz
wget http://download.pingcap.org/dm-latest-linux-amd64.sha256

# Check the file integrity. If the result is OK, the file is correct.
sha256sum -c dm-latest-linux-amd64.sha256

# Extract the package.
tar -xzf dm-latest-linux-amd64.tar.gz
cd dm-latest-linux-amd64
```

## Config File

* all sample config files can be found in directory `conf` of dm tarball
* sample config file of dm-master: `bin/dm-master -print-sample-config`
* sample config file of dm-worker: `bin/dm-worker -print-sample-config`


## Contributing
Contributions are welcomed and greatly appreciated. See [CONTRIBUTING.md](./CONTRIBUTING.md)
for details on submitting patches and the contribution workflow.
Expand Down
25 changes: 24 additions & 1 deletion dm/master/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,32 @@
package master

import (
"encoding/base64"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"strings"

"github.com/BurntSushi/toml"
"github.com/pingcap/dm/pkg/log"
"github.com/pingcap/dm/pkg/utils"
"github.com/pingcap/errors"
)

// SampleConfigFile is sample config file of dm-master
// later we can read it from dm/master/dm-master.toml
// and assign it to SampleConfigFile while we build dm-master
var SampleConfigFile string

// NewConfig creates a config for dm-master
func NewConfig() *Config {
cfg := &Config{}
cfg.FlagSet = flag.NewFlagSet("dm-master", flag.ContinueOnError)
fs := cfg.FlagSet

fs.BoolVar(&cfg.printVersion, "V", false, "prints version and exit")
fs.BoolVar(&cfg.printSampleConfig, "print-sample-config", false, "print sample config file of dm-worker")
fs.StringVar(&cfg.ConfigFile, "config", "", "path to config file")
fs.StringVar(&cfg.MasterAddr, "master-addr", "", "master API server and status addr")
fs.StringVar(&cfg.LogLevel, "L", "info", "log level: debug, info, warn, error, fatal")
Expand Down Expand Up @@ -72,7 +80,8 @@ type Config struct {

ConfigFile string `json:"config-file"`

printVersion bool
printVersion bool
printSampleConfig bool
}

func (c *Config) String() string {
Expand All @@ -96,6 +105,20 @@ func (c *Config) Parse(arguments []string) error {
return flag.ErrHelp
}

if c.printSampleConfig {
if strings.TrimSpace(SampleConfigFile) == "" {
fmt.Println("sample config file of dm-master is empty")
} else {
rawConfig, err := base64.StdEncoding.DecodeString(SampleConfigFile)
if err != nil {
fmt.Println("base64 decode config error:", err)
csuzhangxc marked this conversation as resolved.
Show resolved Hide resolved
} else {
fmt.Println(string(rawConfig))
}
}
return flag.ErrHelp
}

// Load config file if specified.
if c.ConfigFile != "" {
err = c.configFromFile(c.ConfigFile)
Expand Down
6 changes: 3 additions & 3 deletions dm/master/dm-master.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Master Configuration.

#log configuration
log-level = "info"
log-file = "dm-master.log"
log-rotate = "day"

#dm-master listen address
master-addr = ":8261"

# mysql <-> Worker deployment, we'll refine it when new deployment function is available

# replication group <-> dm-Worker deployment, we'll refine it when new deployment function is available
[[deploy]]
source-id = "mysql-replica-01"
dm-worker = "172.16.10.72:8262"
Expand Down
26 changes: 24 additions & 2 deletions dm/worker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ package worker

import (
"bytes"
"encoding/base64"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"strings"

"github.com/BurntSushi/toml"
"github.com/pingcap/dm/pkg/log"
Expand All @@ -31,13 +33,19 @@ import (
"github.com/pingcap/dm/relay/purger"
)

// SampleConfigFile is sample config file of dm-worker
// later we can read it from dm/worker/dm-worker.toml
// and assign it to SampleConfigFile while we build dm-worker
var SampleConfigFile string

// NewConfig creates a new base config for worker.
func NewConfig() *Config {
cfg := &Config{}
cfg.flagSet = flag.NewFlagSet("worker", flag.ContinueOnError)
fs := cfg.flagSet

fs.BoolVar(&cfg.printVersion, "V", false, "prints version and exit")
fs.BoolVar(&cfg.printSampleConfig, "print-sample-config", false, "print sample config file of dm-worker")
fs.StringVar(&cfg.ConfigFile, "config", "", "path to config file")
fs.StringVar(&cfg.WorkerAddr, "worker-addr", "", "worker API server and status addr")
fs.StringVar(&cfg.LogLevel, "L", "info", "log level: debug, info, warn, error, fatal")
Expand All @@ -63,7 +71,6 @@ type Config struct {

EnableGTID bool `toml:"enable-gtid" json:"enable-gtid"`
AutoFixGTID bool `toml:"auto-fix-gtid" json:"auto-fix-gtid"`
MetaFile string `toml:"meta-file" json:"meta-file"`
RelayDir string `toml:"relay-dir" json:"relay-dir"`
ServerID int `toml:"server-id" json:"server-id"`
Flavor string `toml:"flavor" json:"flavor"`
Expand All @@ -81,7 +88,8 @@ type Config struct {

ConfigFile string `json:"config-file"`

printVersion bool
printVersion bool
printSampleConfig bool
}

// Clone clones a config
Expand Down Expand Up @@ -141,6 +149,20 @@ func (c *Config) Parse(arguments []string) error {
return flag.ErrHelp
}

if c.printSampleConfig {
if strings.TrimSpace(SampleConfigFile) == "" {
fmt.Println("sample config file of dm-worker is empty")
} else {
rawConfig, err := base64.StdEncoding.DecodeString(SampleConfigFile)
if err != nil {
fmt.Println("base64 decode config error:", err)
} else {
fmt.Println(string(rawConfig))
}
}
return flag.ErrHelp
}

// Load config file if specified.
if c.ConfigFile != "" {
err = c.configFromFile(c.ConfigFile)
Expand Down
20 changes: 16 additions & 4 deletions dm/worker/dm-worker.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
# Worker Configuration.

#log configuration
log-level = "info"
log-file = "dm-worker.log"
log-rotate = "day"

#dm-worker listen address
worker-addr = ":8262"


#server id of slave for binlog replication
#each instance (master and slave) in replication group should have different server id
server-id = 101
source-id = "127.0.0.1:3306"

#represents a MySQL/MariaDB instance or a replication group
source-id = "mysql-replica-01"

#flavor: mysql/mariadb
flavor = "mysql"

#directory that used to store relay log
relay-dir = "./relay_log"
meta-file = "relay.meta"

#enable gtid in relay log unit
enable-gtid = false

#charset of DSN of source mysql/mariadb instance
# charset= ""

[from]
Expand All @@ -21,6 +32,7 @@ user = "root"
password = ""
port = 3306

#relay log purge strategy
#[purge]
#interval = 3600
#expires = 24
Expand Down
1 change: 0 additions & 1 deletion dm/worker/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func NewRelayHolder(cfg *Config) *RelayHolder {
EnableGTID: cfg.EnableGTID,
AutoFixGTID: cfg.AutoFixGTID,
Flavor: cfg.Flavor,
MetaFile: cfg.MetaFile,
RelayDir: cfg.RelayDir,
ServerID: cfg.ServerID,
Charset: cfg.Charset,
Expand Down
1 change: 0 additions & 1 deletion dm/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ func (w *Worker) copyConfigFromWorker(cfg *config.SubTaskConfig) {
// log config items, mydumper unit use it
cfg.LogLevel = w.cfg.LogLevel
cfg.LogFile = w.cfg.LogFile
cfg.LogRotate = w.cfg.LogRotate
}

// StopSubTask stops a running sub task
Expand Down
1 change: 0 additions & 1 deletion relay/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
type Config struct {
EnableGTID bool `toml:"enable-gtid" json:"enable-gtid"`
AutoFixGTID bool `toml:"auto-fix-gtid" json:"auto-fix-gtid"`
MetaFile string `toml:"meta-file" json:"meta-file"`
RelayDir string `toml:"relay-dir" json:"relay-dir"`
ServerID int `toml:"server-id" json:"server-id"`
Flavor string `toml:"flavor" json:"flavor"`
Expand Down