Skip to content

Commit

Permalink
follow acelyc111 advice
Browse files Browse the repository at this point in the history
  • Loading branch information
lupengfan1 committed Dec 6, 2024
1 parent caf9a15 commit 764cafb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
2 changes: 1 addition & 1 deletion admin-cli/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ var pegasusClient *executor.Client
func Init(metaList []string) {
globalMetaList = metaList

pegasusClient = executor.NewClient(os.Stdout, globalMetaList)
pegasusClient, _ = executor.NewClient(os.Stdout, globalMetaList, true)
}
35 changes: 7 additions & 28 deletions admin-cli/executor/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,18 @@ type Client struct {
}

// NewClient creates a client for accessing Pegasus cluster for use of admin-cli.
// This function will call os.Exit.
func NewClient(writer io.Writer, metaAddrs []string) *Client {
// When listing nodes fails, willExit == true means call os.Exit().
func NewClient(writer io.Writer, metaAddrs []string, willExit bool) (*Client, error) {
meta := client.NewRPCBasedMeta(metaAddrs)

// TODO(wutao): initialize replica-nodes lazily
nodes, err := meta.ListNodes()
if err != nil {
fmt.Fprintf(writer, "fatal: failed to list nodes [%s]\n", err)
os.Exit(1)
}

var replicaAddrs []string
for _, node := range nodes {
replicaAddrs = append(replicaAddrs, node.Address.GetAddress())
}

return &Client{
Writer: writer,
Meta: meta,
Nodes: util.NewPegasusNodeManager(metaAddrs, replicaAddrs),
Perf: aggregate.NewPerfClient(metaAddrs),
}
}

// NewClientWithoutExit creates a client for accessing Pegasus cluster for use of admin-cli.
// This function will not call os.Exit.
func NewClientWithoutExit(writer io.Writer, metaAddrs []string) (*Client, error) {
meta := client.NewRPCBasedMeta(metaAddrs)

nodes, err := meta.ListNodes()
if err != nil {
fmt.Fprintf(writer, "fatal: failed to list nodes [%s]\n", err)
return nil, fmt.Errorf("fatal: failed to list nodes [%s]", err)
fmt.Printf("Error: failed to list nodes [%s]\n", err)
if willExit {
os.Exit(1)
}
return nil, fmt.Errorf("failed to list nodes [%s]", err)
}

var replicaAddrs []string
Expand Down
3 changes: 2 additions & 1 deletion admin-cli/executor/toolkits/tablemigrator/switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func SwitchMetaAddrs(client *executor.Client, zkAddr string, zkRoot string, tabl

originMeta := client.Meta
targetAddrList := strings.Split(targetAddrs, ",")
targetMeta := executor.NewClient(os.Stdout, targetAddrList).Meta
pegasusClient, _ := executor.NewClient(os.Stdout, targetAddrList, true)
targetMeta := pegasusClient.Meta
env := map[string]string{
"replica.deny_client_request": "reconfig*all",
}
Expand Down

0 comments on commit 764cafb

Please sign in to comment.