Skip to content

Instantly share code, notes, and snippets.

@morgo morgo/setup_dm
Created Feb 27, 2019

Embed
What would you like to do?
#!/bin/bash
source ./sb_include
# Setup DM between sandboxes
SOURCE=$1
if [ -z "$SOURCE" ]; then
echo "Usage: "
echo "setup_dm [source-port]"
echo "i.e. setup_dm 5725"
exit 1
fi
MYSQL_PORT="$SOURCE"
# From template
TIDB_PORT="3000"
DM_MASTER_PORT="13000"
DM_WORKER_PORT="23000"
if [ ! -f $BASEDIR/bin/dm-master ]; then
cd $SBDIR/tmp
wget http://download.pingcap.org/dm-latest-linux-amd64.tar.gz
tar -xzf dm-latest-linux-amd64.tar.gz
mv dm-latest-linux-amd64/bin/* $BASEDIR/bin/
rm -rf dm-latest*
cd $SBDIR
fi
if [ ! -f $BASEDIR/bin/mydumper ]; then
cd $SBDIR/tmp
wget http://download.pingcap.org/tidb-enterprise-tools-latest-linux-amd64.tar.gz
tar -xzf tidb-enterprise-tools-latest-linux-amd64.tar.gz
mv tidb-enterprise-tools-latest-linux-amd64/bin/* $BASEDIR/bin/
rm -rf tidb-enterprise-tools*
cd $SBDIR
fi
cat << EOF > dm-master.toml
# Master Configuration.
#log configuration
log-level = "info"
log-file = "data/dm-master.log"
#dm-master listen address
master-addr = ":$DM_MASTER_PORT"
# replication group <-> dm-Worker deployment, we'll refine it when new deployment function is available
[[deploy]]
source-id = "mysql-replica-01"
dm-worker = ":$DM_WORKER_PORT"
EOF
cat << EOF > dm-worker.toml
# Worker Configuration.
#log configuration
log-level = "info"
log-file = "data/dm-worker.log"
#dm-worker listen address
worker-addr = ":$DM_WORKER_PORT"
#server id of worker (acts like a mysql slave)
server-id = 101
#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"
#enable gtid in relay log unit
enable-gtid = false
#charset of DSN of source mysql/mariadb instance
# charset= ""
[from]
host = "127.0.0.1"
user = "msandbox"
password = "UakOD6Hj2HezXTrta6Qs40DFFGoDWMkcgQ=="
port = $MYSQL_PORT
EOF
cat << EOF > task.yaml
---
name: test
task-mode: all
is-sharding: false
meta-schema: "dm_meta"
remove-meta: false
enable-heartbeat: false
target-database:
host: "127.0.0.1"
port: $TIDB_PORT
user: "root"
password: "UakOD6Hj2HezXTrta6Qs40DFFGoDWMkcgQ=="
mysql-instances:
-
source-id: "mysql-replica-01"
mydumpers:
global:
mydumper-path: "./bin/mydumper"
threads: 4
chunk-filesize: 64
skip-tz-utc: true
loaders:
global:
pool-size: 16
dir: "./dumped_data"
syncers:
global:
worker-count: 16
batch: 100
max-retry: 100
EOF
export MASTER_PID_FILE="$SBDIR/tmp/dmmaster.pid"
export WORKER_PID_FILE="$SBDIR/tmp/dmworker.pid"
cat << EOF > dmstart
#!/bin/bash
source /home/morgo/sandboxes/msb_3_0_0/sb_include
echo "# dmstart"
# check if TiDB is listening first
node_status=off
if [ -f $PIDFILE ]
then
MYPID=\$(cat $PIDFILE)
running=\$(ps -p \$MYPID | grep \$MYPID)
if [ -n "\$running" ]
then
node_status=on
exit_code=0
fi
fi
if [ "\$node_status" == "off" ]; then
echo "tidb-server has not started"
exit 0
fi
if [ -e $MASTER_PID_FILE ]
then
PID=\$(< "$MASTER_PID_FILE")
if kill -0 "\$PID" > /dev/null 2>&1
then
echo "dm already started (found pid file $MASTER_PID_FILE)"
exit 0
else
rm -f $MASTER_PID_FILE
fi
fi
if [ -e $WORKER_PID_FILE ]
then
PID=\$(< "$WORKER_PID_FILE")
if kill -0 "\$PID" > /dev/null 2>&1
then
echo "dm already started (found pid file $WORKER_PID_FILE)"
exit 0
else
rm -f $WORKER_PID_FILE
fi
fi
\$BASEDIR/bin/dm-master -config dm-master.toml &
echo \$! > $MASTER_PID_FILE
\$BASEDIR/bin/dm-worker -config dm-worker.toml &
echo \$! > $WORKER_PID_FILE
sleep 1
echo "start-task task.yaml" | \$BASEDIR/bin/dmctl -master-addr 127.0.0.1:$DM_MASTER_PORT
EOF
cat << EOF > dmstop
#!/bin/bash
echo "# dmstop"
if [ -e $MASTER_PID_FILE ]
then
PID=\$(< "$MASTER_PID_FILE")
if kill -0 "\$PID" > /dev/null 2>&1
then
kill -9 \$PID
rm -f $MASTER_PID_FILE
fi
fi
if [ -e $WORKER_PID_FILE ]
then
PID=\$(< "$WORKER_PID_FILE")
if kill -0 "\$PID" > /dev/null 2>&1
then
kill -9 \$PID
rm -f $WORKER_PID_FILE
fi
fi
EOF
chmod +x dmstart
chmod +x dmstop
# start it
./dmstart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.