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

change the replicas keyword to service_num #294

Closed
wants to merge 11 commits into from
Closed
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
2 changes: 1 addition & 1 deletion cli/command/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func checkMigrateTopology(curveadm *cli.CurveAdm, data string) error {
dcs2add[0].GetRole() != dcs2del[0].GetRole() {
return errno.ERR_REQUIRE_SAME_ROLE_SERVICES_FOR_MIGRATING
}
if len(dcs2del) != dcs2del[0].GetReplicas() {
if len(dcs2del) != dcs2del[0].GetInstances() {
return errno.ERR_REQUIRE_WHOLE_HOST_SERVICES_FOR_MIGRATING
}

Expand Down
15 changes: 8 additions & 7 deletions cli/command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ var (
}
)

// todo change status print from replicas to service num
type statusOptions struct {
id string
role string
host string
verbose bool
showReplicas bool
id string
role string
host string
verbose bool
showInstances bool
}

func NewStatusCommand(curveadm *cli.CurveAdm) *cobra.Command {
Expand All @@ -73,7 +74,7 @@ func NewStatusCommand(curveadm *cli.CurveAdm) *cobra.Command {
flags.StringVar(&options.role, "role", "*", "Specify service role")
flags.StringVar(&options.host, "host", "*", "Specify service host")
flags.BoolVarP(&options.verbose, "verbose", "v", false, "Verbose output for status")
flags.BoolVarP(&options.showReplicas, "show-replicas", "s", false, "Display service replicas")
flags.BoolVarP(&options.showInstances, "show-instances", "s", false, "Display service num")

return cmd
}
Expand Down Expand Up @@ -113,7 +114,7 @@ func displayStatus(curveadm *cli.CurveAdm, dcs []*topology.DeployConfig, options
}
}

output := tui.FormatStatus(statuses, options.verbose, options.showReplicas)
output := tui.FormatStatus(statuses, options.verbose, options.showInstances)
curveadm.WriteOutln("")
curveadm.WriteOutln("cluster name : %s", curveadm.ClusterName())
curveadm.WriteOutln("cluster kind : %s", dcs[0].GetKind())
Expand Down
6 changes: 3 additions & 3 deletions configs/bs/cluster/topology.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ chunkserver_services:
copysets: 100
deploy:
- host: ${machine1}
replicas: 3 # 请注意这里的replica不代表存储池的副本数,而是节点上同类进程的数量,比如这里指的是chunkserver进程的数量,也就是配置的磁盘数,相关问题可以参考:https://github.com/opencurve/curveadm/issues/146
instances: 3
- host: ${machine2}
replicas: 3
instances: 3
- host: ${machine3}
replicas: 3
instances: 3

snapshotclone_services:
config:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/melbahja/goph v1.3.0 => github.com/Wine93/goph v0.0.0-20220907033045-3b286d827fb3
replace github.com/melbahja/goph v1.3.0 => github.com/Wine93/goph v0.0.0-20220907033045-3b286d827fb3
981 changes: 981 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/configure/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func createLogicalPool(dcs []*topology.DeployConfig, logicalPool string, poolset
// see issue: https://github.com/opencurve/curve/issues/1441
internalPort := dc.GetListenPort()
externalPort := dc.GetListenExternalPort()
if dc.GetReplicas() > 1 {
if dc.GetInstances() > 1 {
internalPort = 0
externalPort = 0
}
Expand Down
6 changes: 3 additions & 3 deletions internal/configure/topology/dc.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type (
host string
hostname string
name string
replicas int
instances int
hostSequence int // start with 0
replicasSequence int // start with 0

Expand Down Expand Up @@ -104,7 +104,7 @@ func newVariables(m map[string]interface{}) (*variable.Variables, error) {
return vars, nil
}

func NewDeployConfig(ctx *Context, kind, role, host, name string, replicas int,
func NewDeployConfig(ctx *Context, kind, role, host, name string, instances int,
hostSequence, replicasSequence int, config map[string]interface{}) (*DeployConfig, error) {
// variable section
v := config[CONFIG_VARIABLE.key]
Expand Down Expand Up @@ -143,7 +143,7 @@ func NewDeployConfig(ctx *Context, kind, role, host, name string, replicas int,
role: role,
host: host,
name: name,
replicas: replicas,
instances: instances,
hostSequence: hostSequence,
replicasSequence: replicasSequence,
config: config,
Expand Down
2 changes: 1 addition & 1 deletion internal/configure/topology/dc_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (dc *DeployConfig) GetRole() string { return dc.role }
func (dc *DeployConfig) GetHost() string { return dc.host }
func (dc *DeployConfig) GetHostname() string { return dc.hostname }
func (dc *DeployConfig) GetName() string { return dc.name }
func (dc *DeployConfig) GetReplicas() int { return dc.replicas }
func (dc *DeployConfig) GetInstances() int { return dc.instances }
func (dc *DeployConfig) GetHostSequence() int { return dc.hostSequence }
func (dc *DeployConfig) GetReplicasSequence() int { return dc.replicasSequence }
func (dc *DeployConfig) GetServiceConfig() map[string]string { return dc.serviceConfig }
Expand Down
32 changes: 19 additions & 13 deletions internal/configure/topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ import (

type (
Deploy struct {
Host string `mapstructure:"host"`
Name string `mapstructure:"name"`
Replica int `mapstructure:"replica"` // old version
Replicas int `mapstructure:"replicas"`
Config map[string]interface{} `mapstructure:"config"`
Host string `mapstructure:"host"`
Name string `mapstructure:"name"`
Replica int `mapstructure:"replica"` // old version
Replicas int `mapstructure:"replicas"` // old version
Instances int `mapstructure:"instances"`
Config map[string]interface{} `mapstructure:"config"`
}

Service struct {
Expand Down Expand Up @@ -149,23 +150,28 @@ func ParseTopology(data string, ctx *Context) ([]*DeployConfig, error) {
merge(servicesConfig, deployConfig, 1)

// create deploy config
replicas := 1
instances := 1
if deploy.Replicas < 0 {
return nil, errno.ERR_REPLICAS_REQUIRES_POSITIVE_INTEGER.
return nil, errno.ERR_INSTANCES_REQUIRES_POSITIVE_INTEGER.
F("replicas: %d", deploy.Replicas)
} else if deploy.Replica < 0 {
return nil, errno.ERR_REPLICAS_REQUIRES_POSITIVE_INTEGER.
return nil, errno.ERR_INSTANCES_REQUIRES_POSITIVE_INTEGER.
F("replica: %d", deploy.Replica)
} else if deploy.Instances < 0 {
return nil, errno.ERR_INSTANCES_REQUIRES_POSITIVE_INTEGER.
F("Instance: %d", deploy.Instances)
} else if deploy.Instances > 0 {
instances = deploy.Instances
} else if deploy.Replicas > 0 {
replicas = deploy.Replicas
instances = deploy.Replicas
} else if deploy.Replica > 0 {
replicas = deploy.Replica
instances = deploy.Replica
}

for replicasSequence := 0; replicasSequence < replicas; replicasSequence++ {
for instancesSequence := 0; instancesSequence < instances; instancesSequence++ {
dc, err := NewDeployConfig(ctx, kind,
role, deploy.Host, deploy.Name, replicas,
hostSequence, replicasSequence, utils.DeepCopy(deployConfig))
role, deploy.Host, deploy.Name, instances,
hostSequence, instancesSequence, utils.DeepCopy(deployConfig))
if err != nil {
return nil, err // already is error code
}
Expand Down
10 changes: 5 additions & 5 deletions internal/errno/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ var (
ERR_RENDERING_VARIABLE_FAILED = EC(330007, "rendering variable failed")
ERR_CREATE_HASH_FOR_TOPOLOGY_FAILED = EC(330008, "create hash for topology failed")
// 331: configure (topology.yaml: invalid configure value)
ERR_UNSUPPORT_CLUSTER_KIND = EC(331000, "unsupport cluster kind")
ERR_NO_SERVICES_IN_TOPOLOGY = EC(331001, "no services in topology")
ERR_REPLICAS_REQUIRES_POSITIVE_INTEGER = EC(331002, "replicas requires a positive integer")
ERR_INVALID_VARIABLE_SECTION = EC(331003, "invalid variable section")
ERR_DUPLICATE_SERVICE_ID = EC(331004, "service id is duplicate")
ERR_UNSUPPORT_CLUSTER_KIND = EC(331000, "unsupport cluster kind")
ERR_NO_SERVICES_IN_TOPOLOGY = EC(331001, "no services in topology")
ERR_INSTANCES_REQUIRES_POSITIVE_INTEGER = EC(331002, "instances requires a positive integer")
ERR_INVALID_VARIABLE_SECTION = EC(331003, "invalid variable section")
ERR_DUPLICATE_SERVICE_ID = EC(331004, "service id is duplicate")
// 332: configure (topology.yaml: update topology)
ERR_DELETE_SERVICE_WHILE_COMMIT_TOPOLOGY_IS_DENIED = EC(332000, "delete service while commit topology is denied")
ERR_ADD_SERVICE_WHILE_COMMIT_TOPOLOGY_IS_DENIED = EC(332001, "add service while commit topology is denied")
Expand Down
2 changes: 1 addition & 1 deletion internal/task/task/checker/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func joinPorts(dc *topology.DeployConfig, addresses []Address) string {
for _, address := range addresses {
ports = append(ports, strconv.Itoa(address.Port))
}
if dc.GetReplicas() > 1 { // replicas service
if dc.GetInstances() > 1 { // replicas service
ports = append(ports, "...")
}
return strings.Join(ports, ",")
Expand Down
6 changes: 3 additions & 3 deletions internal/task/task/common/service_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type (
ParentId string
Role string
Host string
Replica string
Instances string
ContainerId string
Ports string
IsLeader bool
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *step2InitStatus) Execute(ctx *context.Context) error {
ParentId: dc.GetParentId(),
Role: dc.GetRole(),
Host: dc.GetHost(),
Replica: fmt.Sprintf("1/%d", dc.GetReplicas()),
Instances: fmt.Sprintf("1/%d", dc.GetInstances()),
ContainerId: tui.TrimContainerId(s.containerId),
Status: comm.SERVICE_STATUS_UNKNOWN,
LogDir: dc.GetLogDir(),
Expand Down Expand Up @@ -206,7 +206,7 @@ func (s *step2FormatServiceStatus) Execute(ctx *context.Context) error {
ParentId: dc.GetParentId(),
Role: dc.GetRole(),
Host: dc.GetHost(),
Replica: fmt.Sprintf("1/%d", dc.GetReplicas()),
Instances: fmt.Sprintf("1/%d", dc.GetInstances()),
ContainerId: tui.TrimContainerId(s.containerId),
Ports: *s.ports,
IsLeader: *s.isLeader,
Expand Down
6 changes: 3 additions & 3 deletions internal/tui/service/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func mergeStatues(statuses []task.ServiceStatus) []task.ServiceStatus {
Id: merge(statuses[i:j], ITEM_ID),
Role: status.Role,
Host: status.Host,
Replica: fmt.Sprintf("%d/%s", j-i, strings.Split(status.Replica, "/")[1]),
Instances: fmt.Sprintf("%d/%s", j-i, strings.Split(status.Instances, "/")[1]),
ContainerId: merge(statuses[i:j], ITEM_CONTAINER_ID),
Status: merge(statuses[i:j], ITEM_STATUS),
Ports: merge(statuses[i:j], ITEM_PORTS),
Expand All @@ -214,7 +214,7 @@ func FormatStatus(statuses []task.ServiceStatus, verbose, expand bool) string {
"Id",
"Role",
"Host",
"Replicas",
"Instances",
"Container Id",
"Status",
"Ports",
Expand All @@ -235,7 +235,7 @@ func FormatStatus(statuses []task.ServiceStatus, verbose, expand bool) string {
status.Id,
status.Role,
status.Host,
status.Replica,
status.Instances,
status.ContainerId,
tui.DecorateMessage{Message: status.Status, Decorate: statusDecorate},
utils.Choose(len(status.Ports) == 0, "-", status.Ports),
Expand Down