Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: integrate tispark #531

Merged
merged 23 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
eece8d5
[WIP] cluster: add basic specs for tispark
AstroProfundis Jun 10, 2020
47da5b6
makefile: update default target
AstroProfundis Jun 22, 2020
67a235e
meta: add tispark specs as instances
AstroProfundis Jun 23, 2020
50f531b
cluster: add tispark templates from tidb-ansible
AstroProfundis Jun 24, 2020
52b5111
cluster: implement downloading of tispark packages
AstroProfundis Jun 24, 2020
5165119
cluster: implement templates for tispark
AstroProfundis Jun 28, 2020
1b5295f
cluster: render tispark configs and scripts
AstroProfundis Jun 30, 2020
09a4f7f
cluster: deploy spark as dependency of tispark
AstroProfundis Jun 30, 2020
a046744
cluster: exclude spark from start/stop actions
AstroProfundis Jun 30, 2020
e2f177a
cluster: fix paths for tispark
AstroProfundis Jul 1, 2020
7c68253
update failpoint depend
AstroProfundis Jul 2, 2020
1cbc868
cluster: fix ports for tispark
AstroProfundis Jul 2, 2020
5db4400
cluster: implement start/stop operations for tispark
AstroProfundis Jul 2, 2020
7e6c314
cluster: fix template for tispark
AstroProfundis Jul 6, 2020
d303adf
cluster: make scaling work for tispark
AstroProfundis Jul 7, 2020
aca6570
cluster/spec: check for tispark node counts
AstroProfundis Jul 8, 2020
ba3b525
cluster: add tests for tispark
AstroProfundis Jul 8, 2020
74484f7
cluster: fix topology validation
AstroProfundis Jul 9, 2020
3fb9ce6
cluster: simplify spec validation & deploy process
AstroProfundis Jul 13, 2020
75951b9
cluster: fix compatiability with `patch` sub command
AstroProfundis Jul 13, 2020
e9c9064
cluster: fix spec validation
AstroProfundis Jul 14, 2020
75f40d1
cluster: add status check for tispark nodes
AstroProfundis Jul 14, 2020
0bf52f3
cluster/spec: remove tispark_{config,env} form worker spec
AstroProfundis Jul 16, 2020
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
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.PHONY: server
.PHONY: cmd components server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change expected? There is no target named cmd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a directory cmd, so if run make cmd, it will try to make the directory. We don't have any Makefile in cmd so it's not a problem for now.

.DEFAULT_GOAL := default

GOVER := $(shell go version)

Expand All @@ -24,11 +25,10 @@ FILES := $$(find . -name "*.go")
FAILPOINT_ENABLE := $$(tools/bin/failpoint-ctl enable)
FAILPOINT_DISABLE := $$(tools/bin/failpoint-ctl disable)

default: build check
default: check build

include ./tests/Makefile


# Build TiUP and all components
build: tiup components

Expand Down Expand Up @@ -120,8 +120,6 @@ fmt:
@echo "goimports (if installed)"
$(shell gimports -w $(FILES) 2>/dev/null)

.PHONY: cmd

tools/bin/errcheck: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/errcheck github.com/kisielk/errcheck
Expand Down
1 change: 1 addition & 0 deletions components/cluster/command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func checkSystemInfo(s *cliutil.SSHConnectionProps, topo *spec.Specification, op
inst.OS(),
inst.Arch(),
insightVer,
"", // use default srcPath
Copy link
Contributor

@lonng lonng Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to define an interface for the component source file. e.g:

type ComponentSource interface {
    FilePath() string
}

type OSArchComponent struct {
    OS string
    Arch string
    Version string
}

func (...) FilePath() string {
    return fmt.sprintf()
}

type PatchedComponent string
func (p PatchedComponent) FilePath() string {
    return string(p)
}

func (b *Builder) CopyComponent(src ComponentSource, dstHost, dstDir string) *Builder {
...
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should go further:

  • Define a Component interface which contains Deploy or other needed methods
  • Implement the Component interface in TiDBComponent, TiSparkComponent etc. So that we don't need to check what the component it is.

Copy link
Contributor Author

@AstroProfundis AstroProfundis Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a huge refactor and is already out of the scope of this PR.

We could discuss that in #601

inst.GetHost(),
task.CheckToolsPathDir,
).
Expand Down
60 changes: 42 additions & 18 deletions components/cluster/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func confirmTopology(clusterName, version string, topo *spec.Specification, patc
log.Errorf(" 3. The component marked as `patched` has been replaced by previours patch command.")
}

if len(topo.TiSparkMasters) > 0 || len(topo.TiSparkWorkers) > 0 {
log.Warnf("There are TiSpark nodes defined in the topology, please note that you'll need to manually install Java Runtime Environment (JRE) 8 on the host, other wise the TiSpark nodes will fail to start.")
log.Warnf("You may read the OpenJDK doc for a reference: https://openjdk.java.net/install/")
}

return cliutil.PromptForConfirmOrAbortError("Do you want to continue? [y/N]: ")
}

Expand Down Expand Up @@ -270,37 +275,50 @@ func deploy(clusterName, clusterVersion, topoFile string, opt deployOptions) err
// log dir will always be with values, but might not used by the component
logDir := clusterutil.Abs(globalOptions.User, inst.LogDir())
// Deploy component
// prepare deployment server
t := task.NewBuilder().
UserSSH(inst.GetHost(), inst.GetSSHPort(), globalOptions.User, gOpt.SSHTimeout).
Mkdir(globalOptions.User, inst.GetHost(),
deployDir, logDir,
filepath.Join(deployDir, "bin"),
filepath.Join(deployDir, "conf"),
filepath.Join(deployDir, "scripts")).
Mkdir(globalOptions.User, inst.GetHost(), dataDirs...).
CopyComponent(
Mkdir(globalOptions.User, inst.GetHost(), dataDirs...)

// copy dependency component if needed
switch inst.ComponentName() {
case spec.ComponentTiSpark:
t = t.DeploySpark(inst, version, "" /* default srcPath */, deployDir)
default:
t = t.CopyComponent(
inst.ComponentName(),
inst.OS(),
inst.Arch(),
version,
"", // use default srcPath
inst.GetHost(),
deployDir,
).
InitConfig(
clusterName,
clusterVersion,
inst,
globalOptions.User,
opt.ignoreConfigCheck,
meta.DirPaths{
Deploy: deployDir,
Data: dataDirs,
Log: logDir,
Cache: spec.ClusterPath(clusterName, spec.TempConfigPath),
},
).
BuildAsStep(fmt.Sprintf(" - Copy %s -> %s", inst.ComponentName(), inst.GetHost()))
deployCompTasks = append(deployCompTasks, t)
)
}

// generate configs for the component
t = t.InitConfig(
clusterName,
clusterVersion,
inst,
globalOptions.User,
opt.ignoreConfigCheck,
meta.DirPaths{
Deploy: deployDir,
Data: dataDirs,
Log: logDir,
Cache: spec.ClusterPath(clusterName, spec.TempConfigPath),
},
)

deployCompTasks = append(deployCompTasks,
t.BuildAsStep(fmt.Sprintf(" - Copy %s -> %s", inst.ComponentName(), inst.GetHost())),
)
})

nodeInfoTask := task.NewBuilder().Func("Check status", func(ctx *task.Context) error {
Expand Down Expand Up @@ -373,6 +391,11 @@ func buildMonitoredDeployTask(
version := spec.ComponentVersion(comp, version)

for host, info := range uniqueHosts {
// FIXME: as the uniqueHosts list is built with os-arch as part of the key,
// for platform independent packages, it will be downloaded multiple times
// and be saved with different file names in the packages dir, the tarballs
// are identical and the only difference is platform in filename.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind creating an issue for it and link the URL here?


// populate unique os/arch set
key := fmt.Sprintf("%s-%s-%s", comp, info.os, info.arch)
if _, found := uniqueCompOSArch[key]; !found {
Expand Down Expand Up @@ -404,6 +427,7 @@ func buildMonitoredDeployTask(
info.os,
info.arch,
version,
"", // use default srcPath
host,
deployDir,
).
Expand Down
3 changes: 2 additions & 1 deletion components/cluster/command/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ You can retain some nodes and roles data when destroy cluster, eg:

logger.EnableAuditLog()
metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
AstroProfundis marked this conversation as resolved.
Show resolved Hide resolved
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) {
return err
}

Expand Down
12 changes: 8 additions & 4 deletions components/cluster/command/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func newDisplayCmd() *cobra.Command {
}

metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) {
return perrs.AddStack(err)
}
return destroyTombstoneIfNeed(clusterName, metadata, gOpt)
Expand All @@ -88,7 +89,8 @@ func newDisplayCmd() *cobra.Command {

func displayDashboardInfo(clusterName string) error {
metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) {
return err
}

Expand Down Expand Up @@ -121,7 +123,8 @@ func displayDashboardInfo(clusterName string) error {

func displayClusterMeta(clusterName string, opt *operator.Options) error {
clsMeta, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) {
return err
}

Expand Down Expand Up @@ -175,7 +178,8 @@ func destroyTombstoneIfNeed(clusterName string, metadata *spec.ClusterMeta, opt

func displayClusterTopology(clusterName string, opt *operator.Options) error {
metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) {
return err
}

Expand Down
10 changes: 9 additions & 1 deletion components/cluster/command/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,15 @@ func buildReloadTask(
case spec.ComponentGrafana, spec.ComponentPrometheus, spec.ComponentAlertManager:
version := spec.ComponentVersion(compName, metadata.Version)
tb.Download(compName, inst.OS(), inst.Arch(), version).
CopyComponent(compName, inst.OS(), inst.Arch(), version, inst.GetHost(), deployDir)
CopyComponent(
compName,
inst.OS(),
inst.Arch(),
version,
"", // use default srcPath
inst.GetHost(),
deployDir,
)
}
hasImported = true
}
Expand Down
10 changes: 9 additions & 1 deletion components/cluster/command/scale_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@ func scaleIn(clusterName string, options operator.Options) error {
case spec.ComponentGrafana, spec.ComponentPrometheus, spec.ComponentAlertManager:
version := spec.ComponentVersion(compName, metadata.Version)
tb.Download(compName, instance.OS(), instance.Arch(), version).
CopyComponent(compName, instance.OS(), instance.Arch(), version, instance.GetHost(), deployDir)
CopyComponent(
compName,
instance.OS(),
instance.Arch(),
version,
"", // use default srcPath
instance.GetHost(),
deployDir,
)
}
hasImported = true
}
Expand Down
51 changes: 41 additions & 10 deletions components/cluster/command/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ package command

import (
"context"
"errors"
"io/ioutil"
"path/filepath"
"strings"

"github.com/joomcode/errorx"
"github.com/pingcap/errors"
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cliutil/prepare"
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
Expand Down Expand Up @@ -72,11 +73,11 @@ func newScaleOutCmd() *cobra.Command {
func scaleOut(clusterName, topoFile string, opt scaleOutOptions) error {
exist, err := tidbSpec.Exist(clusterName)
if err != nil {
return errors.AddStack(err)
return perrs.AddStack(err)
}

if !exist {
return errors.Errorf("cannot scale-out non-exists cluster %s", clusterName)
return perrs.Errorf("cannot scale-out non-exists cluster %s", clusterName)
}

metadata, err := spec.ClusterMetadata(clusterName)
Expand All @@ -91,7 +92,12 @@ func scaleOut(clusterName, topoFile string, opt scaleOutOptions) error {
MonitoredOptions: metadata.Topology.MonitoredOptions,
ServerConfigs: metadata.Topology.ServerConfigs,
}
if err := clusterutil.ParseTopologyYaml(topoFile, &newPart); err != nil {

// The no tispark master error is ignored, as if the tispark master is removed from the topology
// file for some reason (manual edit, for example), it is still possible to scale-out it to make
// the whole topology back to normal state.
if err := clusterutil.ParseTopologyYaml(topoFile, &newPart); err != nil &&
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) {
return err
}

Expand Down Expand Up @@ -146,7 +152,7 @@ func scaleOut(clusterName, topoFile string, opt scaleOutOptions) error {
// FIXME: Map possible task errors and give suggestions.
return err
}
return errors.Trace(err)
return perrs.Trace(err)
}

log.Infof("Scaled cluster `%s` out successfully", clusterName)
Expand Down Expand Up @@ -247,11 +253,28 @@ func buildScaleOutTask(
filepath.Join(deployDir, "conf"),
filepath.Join(deployDir, "scripts")).
Mkdir(metadata.User, inst.GetHost(), dataDirs...)

srcPath := ""
if patchedComponents.Exist(inst.ComponentName()) {
tb.InstallPackage(spec.ClusterPath(clusterName, spec.PatchDirName, inst.ComponentName()+".tar.gz"), inst.GetHost(), deployDir)
} else {
tb.CopyComponent(inst.ComponentName(), inst.OS(), inst.Arch(), version, inst.GetHost(), deployDir)
srcPath = spec.ClusterPath(clusterName, spec.PatchDirName, inst.ComponentName()+".tar.gz")
}

// copy dependency component if needed
switch inst.ComponentName() {
AstroProfundis marked this conversation as resolved.
Show resolved Hide resolved
case spec.ComponentTiSpark:
tb = tb.DeploySpark(inst, version, srcPath, deployDir)
default:
tb.CopyComponent(
inst.ComponentName(),
inst.OS(),
inst.Arch(),
version,
srcPath,
inst.GetHost(),
deployDir,
)
}

t := tb.ScaleConfig(clusterName,
metadata.Version,
metadata.Topology,
Expand Down Expand Up @@ -282,7 +305,15 @@ func buildScaleOutTask(
case spec.ComponentGrafana, spec.ComponentPrometheus, spec.ComponentAlertManager:
version := spec.ComponentVersion(compName, metadata.Version)
tb.Download(compName, inst.OS(), inst.Arch(), version).
CopyComponent(compName, inst.OS(), inst.Arch(), version, inst.GetHost(), deployDir)
CopyComponent(
compName,
inst.OS(),
inst.Arch(),
version,
"", // use default srcPath
inst.GetHost(),
deployDir,
)
}
hasImported = true
}
Expand Down Expand Up @@ -367,7 +398,7 @@ func validateNewTopo(topo *spec.Specification) (err error) {
topo.IterInstance(func(instance spec.Instance) {
// check for "imported" parameter, it can not be true when scaling out
if instance.IsImported() {
err = errors.New(
err = perrs.New(
"'imported' is set to 'true' for new instance, this is only used " +
"for instances imported from tidb-ansible and make no sense when " +
"scaling out, please delete the line or set it to 'false' for new instances")
Expand Down
36 changes: 29 additions & 7 deletions components/cluster/command/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,38 @@ func upgrade(clusterName, clusterVersion string, opt operator.Options) error {
if inst.IsImported() {
switch inst.ComponentName() {
case spec.ComponentPrometheus, spec.ComponentGrafana, spec.ComponentAlertManager:
tb.CopyComponent(inst.ComponentName(), inst.OS(), inst.Arch(), version, inst.GetHost(), deployDir)
default:
tb.BackupComponent(inst.ComponentName(), metadata.Version, inst.GetHost(), deployDir).
CopyComponent(inst.ComponentName(), inst.OS(), inst.Arch(), version, inst.GetHost(), deployDir)
tb.CopyComponent(
inst.ComponentName(),
inst.OS(),
inst.Arch(),
version,
"", // use default srcPath
inst.GetHost(),
deployDir,
)
}
hasImported = true
} else {
tb.BackupComponent(inst.ComponentName(), metadata.Version, inst.GetHost(), deployDir).
CopyComponent(inst.ComponentName(), inst.OS(), inst.Arch(), version, inst.GetHost(), deployDir)
}

// backup files of the old version
tb = tb.BackupComponent(inst.ComponentName(), metadata.Version, inst.GetHost(), deployDir)

// copy dependency component if needed
switch inst.ComponentName() {
case spec.ComponentTiSpark:
tb = tb.DeploySpark(inst, version, "" /* default srcPath */, deployDir)
default:
tb = tb.CopyComponent(
inst.ComponentName(),
inst.OS(),
inst.Arch(),
version,
"", // use default srcPath
inst.GetHost(),
deployDir,
)
}

tb.InitConfig(
clusterName,
clusterVersion,
Expand Down
1 change: 1 addition & 0 deletions components/dm/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func deploy(clusterName, clusterVersion, topoFile string, opt deployOptions) err
inst.OS(),
inst.Arch(),
version,
"", // use default srcPath
inst.GetHost(),
deployDir,
).
Expand Down
Loading