Skip to content
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
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ embed_static:
go run github.com/GeertJohan/go.rice/rice embed-go
go build .

embed_config:
cd go/vt/mysqlctl
go run github.com/GeertJohan/go.rice/rice embed-go
go build .

build_web:
echo $$(date): Building web artifacts
cd web/vtctld2 && ng build -prod
cp -f web/vtctld2/src/{favicon.ico,plotly-latest.min.js,primeui-ng-all.min.css} web/vtctld2/dist/

build:
build: embed_config
ifndef NOBANNER
echo $$(date): Building source tree
endif
Expand Down
2 changes: 1 addition & 1 deletion examples/local/203_vertical_split.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ script_root=$(dirname "${BASH_SOURCE}")
source "$script_root/env.sh"

# shellcheck disable=SC2086
"$VTROOT"/bin/vtworker \
vtworker \
$TOPOLOGY_FLAGS \
-cell zone1 \
-log_dir "$VTDATAROOT"/tmp \
Expand Down
2 changes: 1 addition & 1 deletion examples/local/303_horizontal_split.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ script_root=$(dirname "${BASH_SOURCE}")
source "${script_root}/env.sh"

# shellcheck disable=SC2086
"$VTROOT"/bin/vtworker \
vtworker \
$TOPOLOGY_FLAGS \
-cell zone1 \
-log_dir "$VTDATAROOT"/tmp \
Expand Down
6 changes: 1 addition & 5 deletions examples/local/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

hostname=`hostname -f`
vtctld_web_port=15000
export VTDATAROOT="${VTDATAROOT:-${VTROOT}/vtdataroot}"
export VTDATAROOT="${VTDATAROOT:-${PWD}/vtdataroot}"

function fail() {
echo "ERROR: $1"
Expand All @@ -33,10 +33,6 @@ for binary in mysqld etcd etcdctl curl vtctlclient vttablet vtgate vtctld mysqlc
command -v "$binary" > /dev/null || fail "${binary} is not installed in PATH. See https://vitess.io/docs/get-started/local/ for install instructions."
done;

if [ -z "$VTROOT" ]; then
fail "VTROOT is not set. See https://vitess.io/docs/get-started/local/ for install instructions."
fi

if [ "${TOPO}" = "zk2" ]; then
# Each ZooKeeper server needs a list of all servers in the quorum.
# Since we're running them all locally, we need to give them unique ports.
Expand Down
2 changes: 1 addition & 1 deletion examples/local/etcd-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ etcdctl --endpoints "http://${ETCD_SERVER}" mkdir /vitess/$cell &
echo "add $cell CellInfo"
set +e
# shellcheck disable=SC2086
"${VTROOT}"/bin/vtctl $TOPOLOGY_FLAGS AddCellInfo \
vtctl $TOPOLOGY_FLAGS AddCellInfo \
-root /vitess/$cell \
-server_address "${ETCD_SERVER}" \
$cell
Expand Down
2 changes: 1 addition & 1 deletion examples/local/vtctld-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fi

echo "Starting vtctld..."
# shellcheck disable=SC2086
$VTROOT/bin/vtctld \
vtctld \
$TOPOLOGY_FLAGS \
-cell $cell \
-workflow_manager_init \
Expand Down
2 changes: 1 addition & 1 deletion examples/local/vtgate-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fi

# Start vtgate.
# shellcheck disable=SC2086
$VTROOT/bin/vtgate \
vtgate \
$TOPOLOGY_FLAGS \
-log_dir $VTDATAROOT/tmp \
-log_queries_to_file $VTDATAROOT/tmp/vtgate_querylog.txt \
Expand Down
2 changes: 1 addition & 1 deletion examples/local/vttablet-down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ for uid_index in $uids; do
wait_pids="$wait_pids $pid"

echo "Stopping MySQL for tablet $alias..."
$VTROOT/bin/mysqlctl \
mysqlctl \
-tablet_uid $uid \
shutdown &
done
Expand Down
8 changes: 3 additions & 5 deletions examples/local/vttablet-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ fi
script_root=`dirname "${BASH_SOURCE}"`
source $script_root/env.sh

init_db_sql_file="$VTROOT/config/init_db.sql"

mkdir -p $VTDATAROOT/backups

# Start 3 vttablets by default.
Expand Down Expand Up @@ -65,7 +63,7 @@ for uid_index in $uids; do
export TABLET_TYPE=$tablet_type

echo "Starting MySQL for tablet $alias..."
action="init -init_db_sql_file $init_db_sql_file"
action="init"
if [ -d $VTDATAROOT/$tablet_dir ]; then
echo "Resuming from existing vttablet dir:"
echo " $VTDATAROOT/$tablet_dir"
Expand All @@ -74,7 +72,7 @@ for uid_index in $uids; do

set +e

$VTROOT/bin/mysqlctl \
mysqlctl \
-log_dir $VTDATAROOT/tmp \
-tablet_uid $uid \
-mysql_port $mysql_port \
Expand Down Expand Up @@ -119,7 +117,7 @@ for uid_index in $uids; do

echo "Starting vttablet for $alias..."
# shellcheck disable=SC2086
$VTROOT/bin/vttablet \
vttablet \
$TOPOLOGY_FLAGS \
-log_dir $VTDATAROOT/tmp \
-log_queries_to_file $VTDATAROOT/tmp/$tablet_logfile \
Expand Down
2 changes: 1 addition & 1 deletion examples/local/vtworker-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ script_root=`dirname "${BASH_SOURCE}"`
source $script_root/env.sh

echo "Starting vtworker..."
exec $VTROOT/bin/vtworker \
vtworker \
$TOPOLOGY_FLAGS \
-cell $cell \
-log_dir $VTDATAROOT/tmp \
Expand Down
2 changes: 1 addition & 1 deletion examples/local/zk-down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ source $script_root/env.sh
# Stop ZooKeeper servers.
echo "Stopping zk servers..."
for zkid in $zkids; do
$VTROOT/bin/zkctl -zk.myid $zkid -zk.cfg $zkcfg -log_dir $VTDATAROOT/tmp shutdown
zkctl -zk.myid $zkid -zk.cfg $zkcfg -log_dir $VTDATAROOT/tmp shutdown
done

4 changes: 2 additions & 2 deletions examples/local/zk-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ for zkid in $zkids; do
echo " $VTDATAROOT/$zkdir"
action='start'
fi
$VTROOT/bin/zkctl -zk.myid $zkid -zk.cfg $zkcfg -log_dir $VTDATAROOT/tmp $action \
zkctl -zk.myid $zkid -zk.cfg $zkcfg -log_dir $VTDATAROOT/tmp $action \
> $VTDATAROOT/tmp/zkctl_$zkid.out 2>&1 &
pids[$zkid]=$!
done
Expand All @@ -56,7 +56,7 @@ echo "Started zk servers."
# If the node already exists, it's fine, means we used existing data.
set +e
# shellcheck disable=SC2086
$VTROOT/bin/vtctl $TOPOLOGY_FLAGS AddCellInfo \
vtctl $TOPOLOGY_FLAGS AddCellInfo \
-root /vitess/$cell \
-server_address $ZK_SERVER \
$cell
Expand Down
5 changes: 3 additions & 2 deletions go/vt/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
const (
// DefaultVtDataRoot is the default value for VTROOT environment variable
DefaultVtDataRoot = "/vt"
// DefaultVtRoot is only required for hooks
DefaultVtRoot = "/usr/local/vitess"
)

// VtRoot returns $VTROOT or tries to guess its value if it's not set.
Expand All @@ -47,8 +49,7 @@ func VtRoot() (root string, err error) {
if strings.HasSuffix(dir, "/bin") {
return path.Dir(dir), nil
}
err = errors.New("VTROOT could not be guessed from the executable location. Please set $VTROOT")
return
return DefaultVtRoot, nil
}

// VtDataRoot returns $VTDATAROOT or the default if $VTDATAROOT is not
Expand Down
17 changes: 3 additions & 14 deletions go/vt/mysqlctl/mycnf_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"bytes"
"crypto/rand"
"fmt"
"io/ioutil"
"math/big"
"path"
"text/template"
Expand Down Expand Up @@ -121,19 +120,9 @@ func (cnf *Mycnf) directoryList() []string {
}
}

// makeMycnf will join cnf files cnfPaths and substitute in the right values.
func (cnf *Mycnf) makeMycnf(cnfFiles []string) (string, error) {
myTemplateSource := new(bytes.Buffer)
myTemplateSource.WriteString("[mysqld]\n")
for _, path := range cnfFiles {
data, dataErr := ioutil.ReadFile(path)
if dataErr != nil {
return "", dataErr
}
myTemplateSource.WriteString("## " + path + "\n")
myTemplateSource.Write(data)
}
return cnf.fillMycnfTemplate(myTemplateSource.String())
// makeMycnf will substitute values
func (cnf *Mycnf) makeMycnf(partialcnf string) (string, error) {
return cnf.fillMycnfTemplate(partialcnf)
}

// fillMycnfTemplate will fill in the passed in template with the values
Expand Down
18 changes: 6 additions & 12 deletions go/vt/mysqlctl/mycnf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,29 @@ limitations under the License.
package mysqlctl

import (
"bytes"
"io/ioutil"
"os"
"path"
"strings"
"testing"

"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/env"
"vitess.io/vitess/go/vt/servenv"
)

var MycnfPath = "/tmp/my.cnf"

func TestMycnf(t *testing.T) {
os.Setenv("MYSQL_FLAVOR", "MariaDB")
uid := uint32(11111)
cnf := NewMycnf(uid, 6802)
myTemplateSource := new(bytes.Buffer)
myTemplateSource.WriteString("[mysqld]\n")
// Assigning ServerID to be different from tablet UID to make sure that there are no
// assumptions in the code that those IDs are the same.
cnf.ServerID = 22222
root, err := env.VtRoot()
if err != nil {
t.Errorf("err: %v", err)
}
cnfTemplatePaths := []string{
path.Join(root, "config/mycnf/default.cnf"),
}
data, err := cnf.makeMycnf(cnfTemplatePaths)
f, _ := ioutil.ReadFile("../../../config/mycnf/default.cnf")
myTemplateSource.Write(f)
data, err := cnf.makeMycnf(myTemplateSource.String())
if err != nil {
t.Errorf("err: %v", err)
} else {
Expand Down Expand Up @@ -85,7 +80,6 @@ func TestMycnf(t *testing.T) {
// 4. \rm $VTROOT/vthook/make_mycnf
// 5. Add No Prefix back
func NoTestMycnfHook(t *testing.T) {
os.Setenv("MYSQL_FLAVOR", "MariaDB")
uid := uint32(11111)
cnf := NewMycnf(uid, 6802)
// Assigning ServerID to be different from tablet UID to make sure that there are no
Expand Down
Loading