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 8 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].GetInstance() {
Copy link
Collaborator

@Wine93 Wine93 Aug 27, 2023

Choose a reason for hiding this comment

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

Sorry, i didn't express clearly, actually we should use word instances for multi-instances, so GetInstances not GetInstance.

return errno.ERR_REQUIRE_WHOLE_HOST_SERVICES_FOR_MIGRATING
}

Expand Down
7 changes: 4 additions & 3 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
showInstance bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto.

}

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.showInstance, "show-instance", "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.showInstance)
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
instance: 3
- host: ${machine2}
replicas: 3
instance: 3
- host: ${machine3}
replicas: 3
instance: 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.GetInstance() > 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
instance 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, instance 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,
instance: instance,
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) GetInstance() int { return dc.instance }
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
20 changes: 13 additions & 7 deletions internal/configure/topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ type (
Deploy struct {
Host string `mapstructure:"host"`
Name string `mapstructure:"name"`
Replica int `mapstructure:"replica"` // old version
Replicas int `mapstructure:"replicas"`
Replica int `mapstructure:"replica"` // old version
Replicas int `mapstructure:"replicas"` // old version
Instance int `mapstructure:"instance"`
Config map[string]interface{} `mapstructure:"config"`
}

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

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

for replicasSequence := 0; replicasSequence < replicas; replicasSequence++ {
for replicasSequence := 0; replicasSequence < instance; replicasSequence++ {
dc, err := NewDeployConfig(ctx, kind,
role, deploy.Host, deploy.Name, replicas,
role, deploy.Host, deploy.Name, instance,
hostSequence, replicasSequence, utils.DeepCopy(deployConfig))
if err != nil {
return nil, err // already is error code
Expand Down
12 changes: 7 additions & 5 deletions internal/errno/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,13 @@ 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")
//todo: remove ERR_REPLICAS_REQUIRES_POSITIVE_INTEGER and change to ERR_NO_SERVICES_NUM_TOPOLOGY
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should update the error code which show below.

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_SERVICE_NUM_REQUIRES_POSITIVE_INTEGER = EC(331005, "service_num requires a positive integer")
// 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.GetInstance() > 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
Instance 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()),
Instance: fmt.Sprintf("1/%d", dc.GetInstance()),
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()),
Instance: fmt.Sprintf("1/%d", dc.GetInstance()),
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]),
Instance: fmt.Sprintf("%d/%s", j-i, strings.Split(status.Instance, "/")[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",
"Instance",
"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.Instance,
status.ContainerId,
tui.DecorateMessage{Message: status.Status, Decorate: statusDecorate},
utils.Choose(len(status.Ports) == 0, "-", status.Ports),
Expand Down