Skip to content

Commit dcb4169

Browse files
Sync for commit 893cc9d7b6f80eab3b103ec327330ad501e16e4f
Signed-off-by: Rohit Nayak <[email protected]>
1 parent adb976d commit dcb4169

13 files changed

+206
-163
lines changed

examples/env.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function fail() {
77
exit 1
88
}
99

10+
1011
if [[ $EUID -eq 0 ]]; then
1112
fail "This script refuses to be run as root. Please switch to a regular user."
1213
fi
@@ -18,17 +19,17 @@ for binary in mysqld etcd etcdctl curl vtctlclient vttablet vtgate vtctld mysqlc
1819
done;
1920

2021
ETCD_SERVER="localhost:2379"
21-
TOPOLOGY_FLAGS="-topo_implementation etcd2 -topo_global_server_address $ETCD_SERVER -topo_global_root /vitess/global"
22+
TOPOLOGY_FLAGS="--topo_implementation etcd2 --topo_global_server_address $ETCD_SERVER --topo_global_root /vitess/global"
2223

2324
mkdir -p "${VTDATAROOT}/etcd"
2425

2526
mkdir -p "${VTDATAROOT}/tmp"
2627

2728
alias mysql="command mysql -h 127.0.0.1 -P 15306"
28-
alias vtctlclient="command vtctlclient -server localhost:15999 -log_dir ${VTDATAROOT}/tmp"
29+
alias vtctlclient="command vtctlclient --server localhost:15999 --log_dir ${VTDATAROOT}/tmp"
2930

3031
# Make sure aliases are expanded in non-interactive shell
3132
shopt -s expand_aliases
3233

3334
export MYSQL="command mysql -h 127.0.0.1 -P 15306"
34-
export LVTCTL="command vtctlclient -server localhost:15999 -log_dir ${VTDATAROOT}/tmp"
35+
export LVTCTL="command vtctlclient --server localhost:15999 --log_dir ${VTDATAROOT}/tmp"

examples/load.sh

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1-
2-
setup(){
1+
setup() {
32
echo ">>>>> Cleaning up previous runs, if any"
43
./cleanup.sh
54

6-
75
echo ">>>>>> Starting etcd"
86
scripts/etcd-up.sh
7+
98
echo ">>>>>> Starting vtctld"
109
scripts/vtctld-up.sh
10+
11+
}
12+
13+
startVTGate() {
1114
echo ">>>>>> Starting vtgate"
1215
scripts/vtgate-up.sh
1316
sleep 2
1417
mysql -h 127.0.0.1 -P 19327 -u msandbox --password=msandbox commerce -e "truncate table _vt.resharding_journal"
1518
mysql -h 127.0.0.1 -P 19327 -u msandbox --password=msandbox commerce -e "truncate table _vt.vreplication"
16-
}
1719

18-
unmanaged(){
20+
}
21+
unmanaged() {
1922
echo ">>>>>> Step 1: Starting unmanaged tablet (load1 keyspace)"
2023
scripts/unmanaged_load.sh
2124
sleep 5
2225
}
2326

24-
movetables(){
27+
movetables() {
2528
echo ">>>>>> Step 2: Starting load2 tablets"
2629
for shard in "0"; do
27-
for i in 200 201 202; do
30+
for i in 200 201 202; do
2831
CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-up.sh
2932
CELL=zone1 KEYSPACE=load2 TABLET_UID=$i SHARD=$shard ./scripts/vttablet-up.sh
3033
done
@@ -33,7 +36,7 @@ movetables(){
3336
sleep 10
3437

3538
$LVTCTL InitShardMaster -force load2/0 zone1-200
36-
exit
39+
exit
3740
sleep 2
3841
echo ">>>>>> Step 3. Calling MoveTables"
3942
TABLE=Email
@@ -42,10 +45,9 @@ exit
4245
TARGET_KS=load2
4346
KSWF=$TARGET_KS.$WORKFLOW
4447
$LVTCTL MoveTables -tablet_types=MASTER -workflow=$WORKFLOW $SOURCE_KS $TARGET_KS $TABLE
45-
if [ $? -eq 1 ]
46-
then
47-
echo "Error in MoveTables, exiting"
48-
exit
48+
if [ $? -eq 1 ]; then
49+
echo "Error in MoveTables, exiting"
50+
exit
4951
fi
5052

5153
# TABLE2=c3
@@ -64,10 +66,9 @@ exit
6466

6567
echo ">>>>>> Step 6. Calling SwitchReads"
6668
$LVTCTL SwitchReads -tablet_type=rdonly $KSWF
67-
if [ $? -eq 1 ]
68-
then
69-
echo "Error in SwitchReads, exiting"
70-
exit
69+
if [ $? -eq 1 ]; then
70+
echo "Error in SwitchReads, exiting"
71+
exit
7172
fi
7273
$LVTCTL SwitchReads -tablet_type=replica $KSWF
7374
sleep 5
@@ -87,16 +88,16 @@ reshard() {
8788

8889
echo ">>>>>>>> applying schema/vschema"
8990
$LVTCTL ApplySchema -sql-file sql/c2_seq.sql $TARGET_KS
90-
$LVTCTL ApplyVSchema -vschema_file sql/load2_sharded_vschema.json $TARGET_KS
91-
$LVTCTL RebuildVSchemaGraph -cells=zone1
91+
$LVTCTL ApplyVSchema --vschema_file sql/load2_sharded_vschema.json $TARGET_KS
92+
$LVTCTL RebuildVSchemaGraph --cells=zone1
9293

9394
echo ">>>>>> Step 8: Starting $TARGET_KS tablets"
9495
shards=('-80' '80-')
95-
for ((idx=0; idx<${#shards[@]}; ++idx)); do
96+
for ((idx = 0; idx < ${#shards[@]}; ++idx)); do
9697
shard=${shards[idx]}
9798
echo "idx $idx, shard is $shard"
98-
for i in 1 2 3; do
99-
TID=`expr 299 + $idx \* 100 + $i`
99+
for i in 1 2 3; do
100+
TID=$(expr 299 + $idx \* 100 + $i)
100101
echo "Creating tablet $TID"
101102
CELL=zone1 TABLET_UID=$TID ./scripts/mysqlctl-up.sh
102103
CELL=zone1 KEYSPACE=$TARGET_KS TABLET_UID=$TID SHARD="$shard" ./scripts/vttablet-up.sh
@@ -111,10 +112,9 @@ reshard() {
111112
echo ">>>>>> Step 9. Calling Reshard"
112113

113114
$LVTCTL Reshard -tablet_types=MASTER $KSWF "0" "-80,80-"
114-
if [ $? -eq 1 ]
115-
then
116-
echo "Error in Reshard, exiting"
117-
exit
115+
if [ $? -eq 1 ]; then
116+
echo "Error in Reshard, exiting"
117+
exit
118118
fi
119119
echo ">>>>> Step 4. Waiting for Vreplication to copy the data ..."
120120
sleep 5
@@ -129,35 +129,38 @@ reshard() {
129129
$LVTCTL SwitchWrites $KSWF
130130
}
131131

132-
133132
source ./env.sh
134133

135134
main() {
136135
source ./step.sh
137136
STEP="${STEP:=0}"
138-
NEXTSTEP="$(($STEP+1))"
139-
echo "export STEP='$NEXTSTEP'" > step.sh
137+
NEXTSTEP="$(($STEP + 1))"
138+
echo "export STEP='$NEXTSTEP'" >step.sh
140139

141140
case "$NEXTSTEP" in
142141

143-
"1") setup
144-
unmanaged
145-
movetables
146-
;;
147-
"2") reshard
148-
;;
149-
*) echo "Unknown parameter"
150-
;;
142+
"1")
143+
setup
144+
unmanaged
145+
movetables
146+
;;
147+
"2")
148+
reshard
149+
;;
150+
*)
151+
echo "Unknown parameter"
152+
;;
151153
esac
152154
}
153155

154156
mt() {
155-
setup
156-
unmanaged
157-
movetables
157+
setup
158+
unmanaged
159+
movetables
158160
}
159161
rs() {
160162
reshard
161163
}
162-
mt
164+
setup
165+
unmanaged
163166
#rs

examples/scripts/etcd-up.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export ETCDCTL_API=2
55

66
# Check that etcd is not already running
77
curl "http://${ETCD_SERVER}" > /dev/null 2>&1 && fail "etcd is already running. Exiting."
8+
set -x
89

910
etcd --enable-v2=true --data-dir "${VTDATAROOT}/etcd/" --listen-client-urls "http://${ETCD_SERVER}" --advertise-client-urls "http://${ETCD_SERVER}" > "${VTDATAROOT}"/tmp/etcd.out 2>&1 &
1011
PID=$!
@@ -22,10 +23,11 @@ etcdctl --endpoints "http://${ETCD_SERVER}" mkdir /vitess/$cell &
2223
echo "add $cell CellInfo"
2324
set +e
2425
# shellcheck disable=SC2086
25-
vtctl $TOPOLOGY_FLAGS AddCellInfo \
26-
-root /vitess/$cell \
27-
-server_address "${ETCD_SERVER}" \
26+
vtctl $TOPOLOGY_FLAGS VtctldCommand AddCellInfo \
27+
--root /vitess/$cell \
28+
--server-address "${ETCD_SERVER}" \
2829
$cell
30+
2931
set -e
3032

3133
echo "etcd start done..."

examples/scripts/mysqlctl-up.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if [ -d $VTDATAROOT/$tablet_dir ]; then
1919
fi
2020

2121
mysqlctl \
22-
-log_dir $VTDATAROOT/tmp \
23-
-tablet_uid $uid \
24-
-mysql_port $mysql_port \
22+
--log_dir $VTDATAROOT/tmp \
23+
--tablet_uid $uid \
24+
--mysql_port $mysql_port \
2525
$action

examples/scripts/populate2.go

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,58 @@
11
package main
2+
23
import (
3-
"fmt"
4-
"time"
5-
"database/sql"
6-
_ "github.com/go-sql-driver/mysql"
7-
"github.com/paulbellamy/ratecounter"
4+
"database/sql"
5+
"fmt"
6+
_ "github.com/go-sql-driver/mysql"
7+
"github.com/paulbellamy/ratecounter"
8+
"time"
89
)
910

10-
func PrepareTx(db *sql.DB,qry string) (tx *sql.Tx, s *sql.Stmt, e error) {
11-
if tx,e=db.Begin(); e!=nil {
12-
return
13-
}
11+
func PrepareTx(db *sql.DB, qry string) (tx *sql.Tx, s *sql.Stmt, e error) {
12+
if tx, e = db.Begin(); e != nil {
13+
return
14+
}
1415

15-
if s, e = tx.Prepare(qry);e!=nil {
16-
panic(e.Error())
17-
}
18-
return
16+
if s, e = tx.Prepare(qry); e != nil {
17+
panic(e.Error())
18+
}
19+
return
1920
}
2021

2122
func main() {
22-
counter := ratecounter.NewRateCounter(1 * time.Second)
23-
done := false
24-
var i int64
25-
query := "insert into c1(c1) values (?)"
26-
i = 0
27-
db, err := sql.Open("mysql", "msandbox:msandbox@tcp(127.0.0.1:19327)/test")
28-
fmt.Println("connection opened")
29-
if err != nil {
30-
panic(err.Error())
31-
}
32-
defer db.Close()
33-
now := time.Now().UnixNano()
34-
tx, stmt, err := PrepareTx(db, query)
35-
if err != nil {
36-
panic(err.Error())
37-
}
38-
for !done {
39-
//time.Sleep(1 * time.Millisecond)
23+
counter := ratecounter.NewRateCounter(1 * time.Second)
24+
done := false
25+
var i int64
26+
query := "insert into c1(c1) values (?)"
27+
i = 0
28+
db, err := sql.Open("mysql", "msandbox:msandbox@tcp(127.0.0.1:19327)/test")
29+
fmt.Println("connection opened")
30+
if err != nil {
31+
panic(err.Error())
32+
}
33+
defer db.Close()
34+
now := time.Now().UnixNano()
35+
tx, stmt, err := PrepareTx(db, query)
36+
if err != nil {
37+
panic(err.Error())
38+
}
39+
for !done {
40+
//time.Sleep(1 * time.Millisecond)
4041
i++
4142
counter.Incr(1)
42-
if _,err := stmt.Exec(now+i); err != nil {
43-
panic(err)
43+
if _, err := stmt.Exec(now + i); err != nil {
44+
panic(err)
4445
}
45-
if i % 10000 == 0 {
46+
if i%10000 == 0 {
4647
fmt.Printf("QPS: %d\n", counter.Rate())
47-
if err := tx.Commit(); err!=nil {
48+
if err := tx.Commit(); err != nil {
4849
panic(err)
4950
}
5051
tx, stmt, err = PrepareTx(db, query)
5152
if err != nil {
5253
panic(err.Error())
5354
}
5455
}
55-
}
56+
}
5657

5758
}

0 commit comments

Comments
 (0)