-
Notifications
You must be signed in to change notification settings - Fork 314
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
[DMN] playground: add dm support for playground #2464
Draft
siddontang
wants to merge
1
commit into
pingcap:master
Choose a base branch
from
siddontang:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package instance | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/pingcap/tiup/pkg/utils" | ||
) | ||
|
||
type DMMaster struct { | ||
instance | ||
Process | ||
initEndpoints []*DMMaster | ||
} | ||
|
||
var _ Instance = &DMMaster{} | ||
|
||
func NewDMMaster(binPath string, dir, host, configPath string, portOffset int, id int, port int) *DMMaster { | ||
if port <= 0 { | ||
port = 8261 | ||
} | ||
return &DMMaster{ | ||
instance: instance{ | ||
BinPath: binPath, | ||
ID: id, | ||
Dir: dir, | ||
Host: host, | ||
Port: utils.MustGetFreePort(host, 8291, portOffset), | ||
// Similar like PD's client port, here use StatusPort for Master Port. | ||
StatusPort: utils.MustGetFreePort(host, port, portOffset), | ||
ConfigPath: configPath, | ||
}, | ||
} | ||
} | ||
|
||
func (m *DMMaster) Name() string { | ||
return fmt.Sprintf("dm-master-%d", m.ID) | ||
} | ||
|
||
func (m *DMMaster) Start(ctx context.Context) error { | ||
args := []string{ | ||
fmt.Sprintf("--name=%s", m.Name()), | ||
fmt.Sprintf("--master-addr=http://%s", utils.JoinHostPort(m.Host, m.StatusPort)), | ||
fmt.Sprintf("--advertise-addr=http://%s", utils.JoinHostPort(AdvertiseHost(m.Host), m.StatusPort)), | ||
fmt.Sprintf("--peer-urls=http://%s", utils.JoinHostPort(m.Host, m.Port)), | ||
fmt.Sprintf("--advertise-peer-urls=http://%s", utils.JoinHostPort(AdvertiseHost(m.Host), m.Port)), | ||
fmt.Sprintf("--log-file=%s", m.LogFile()), | ||
} | ||
|
||
endpoints := make([]string, 0) | ||
for _, master := range m.initEndpoints { | ||
endpoints = append(endpoints, fmt.Sprintf("%s=http://%s", master.Name(), utils.JoinHostPort(master.Host, master.Port))) | ||
} | ||
args = append(args, fmt.Sprintf("--initial-cluster=%s", strings.Join(endpoints, ","))) | ||
|
||
if m.ConfigPath != "" { | ||
args = append(args, fmt.Sprintf("--config=%s", m.ConfigPath)) | ||
} | ||
|
||
m.Process = &process{cmd: PrepareCommand(ctx, m.BinPath, args, nil, m.Dir)} | ||
|
||
logIfErr(m.Process.SetOutputFile(m.LogFile())) | ||
return m.Process.Start() | ||
} | ||
|
||
func (m *DMMaster) SetInitEndpoints(endpoints []*DMMaster) { | ||
m.initEndpoints = endpoints | ||
} | ||
|
||
func (m *DMMaster) Component() string { | ||
return "dm-master" | ||
} | ||
|
||
func (m *DMMaster) LogFile() string { | ||
return filepath.Join(m.Dir, "dm-master.log") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package instance | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
"time" | ||
|
||
"github.com/pingcap/tiup/pkg/utils" | ||
) | ||
|
||
type DMWorker struct { | ||
instance | ||
Process | ||
|
||
masters []*DMMaster | ||
} | ||
|
||
var _ Instance = &DMWorker{} | ||
|
||
// NewDMWorker create a DMWorker instance. | ||
func NewDMWorker(binPath string, dir, host, configPath string, portOffset int, id int, port int, masters []*DMMaster) *DMWorker { | ||
if port <= 0 { | ||
port = 8262 | ||
} | ||
return &DMWorker{ | ||
instance: instance{ | ||
BinPath: binPath, | ||
ID: id, | ||
Dir: dir, | ||
Host: host, | ||
Port: utils.MustGetFreePort(host, port, portOffset), | ||
ConfigPath: configPath, | ||
}, | ||
masters: masters, | ||
} | ||
} | ||
|
||
func (w *DMWorker) MasterAddrs() []string { | ||
var addrs []string | ||
for _, master := range w.masters { | ||
addrs = append(addrs, utils.JoinHostPort(AdvertiseHost(master.Host), master.StatusPort)) | ||
} | ||
return addrs | ||
} | ||
|
||
func (w *DMWorker) Name() string { | ||
return fmt.Sprintf("dm-worker-%d", w.ID) | ||
} | ||
|
||
func (w *DMWorker) Start(ctx context.Context) error { | ||
args := []string{ | ||
fmt.Sprintf("--name=%s", w.Name()), | ||
fmt.Sprintf("--worker-addr=%s", utils.JoinHostPort(w.Host, w.Port)), | ||
fmt.Sprintf("--advertise-addr=%s", utils.JoinHostPort(AdvertiseHost(w.Host), w.Port)), | ||
fmt.Sprintf("--join=%s", strings.Join(w.MasterAddrs(), ",")), | ||
fmt.Sprintf("--log-file=%s", w.LogFile()), | ||
} | ||
|
||
if w.ConfigPath != "" { | ||
args = append(args, fmt.Sprintf("--config=%s", w.ConfigPath)) | ||
} | ||
|
||
w.Process = &process{cmd: PrepareCommand(ctx, w.BinPath, args, nil, w.Dir)} | ||
|
||
logIfErr(w.Process.SetOutputFile(w.LogFile())) | ||
|
||
// try to wait for the master to be ready | ||
// this is a very ugly implementation, but it may mostly works | ||
// TODO: find a better way to do this, | ||
// e.g, let master support a HTTP API to check if it's ready | ||
time.Sleep(time.Second * 3) | ||
return w.Process.Start() | ||
} | ||
|
||
func (w *DMWorker) Component() string { | ||
return "dm-worker" | ||
} | ||
|
||
func (w *DMWorker) LogFile() string { | ||
return filepath.Join(w.Dir, "dm-worker.log") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Benjamin2037 seems that for DM worker, we should support Retry when the worker starts and tries to connect the leader of the Master.
In the case of Playground, when the master starts, and the worker will also immediately start, and the worker will fail because at that time, there is no leader in DM master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussing with the TiUP owner, we decided to use TiUP first to start the DM master and wait for all DM master starting processes to finish, and then TiUP starts the DM worker.