Skip to content

Commit e05a7e3

Browse files
tiansuo114Wine93
authored andcommitted
Improve(config): using more meaningful name for service instances.
Signed-off-by: tec-rubbish maker <[email protected]>
1 parent 59bbb91 commit e05a7e3

File tree

16 files changed

+106
-94
lines changed

16 files changed

+106
-94
lines changed

cli/command/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func checkMigrateTopology(curveadm *cli.CurveAdm, data string) error {
152152
dcs2add[0].GetRole() != dcs2del[0].GetRole() {
153153
return errno.ERR_REQUIRE_SAME_ROLE_SERVICES_FOR_MIGRATING
154154
}
155-
if len(dcs2del) != dcs2del[0].GetReplicas() {
155+
if len(dcs2del) != dcs2del[0].GetInstances() {
156156
return errno.ERR_REQUIRE_WHOLE_HOST_SERVICES_FOR_MIGRATING
157157
}
158158

cli/command/status.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ var (
4848
)
4949

5050
type statusOptions struct {
51-
id string
52-
role string
53-
host string
54-
verbose bool
55-
showReplicas bool
51+
id string
52+
role string
53+
host string
54+
verbose bool
55+
showInstances bool
5656
}
5757

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

7878
return cmd
7979
}
@@ -113,7 +113,7 @@ func displayStatus(curveadm *cli.CurveAdm, dcs []*topology.DeployConfig, options
113113
}
114114
}
115115

116-
output := tui.FormatStatus(statuses, options.verbose, options.showReplicas)
116+
output := tui.FormatStatus(statuses, options.verbose, options.showInstances)
117117
curveadm.WriteOutln("")
118118
curveadm.WriteOutln("cluster name : %s", curveadm.ClusterName())
119119
curveadm.WriteOutln("cluster kind : %s", dcs[0].GetKind())

configs/bs/cluster/scale-out.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
chunkserver_services:
22
deploy:
33
- host: ${machine1}
4-
replica: 20 # 请注意这里的replica不代表存储池的副本数,而是节点上同类进程的数量,比如这里指的是chunkserver进程的数量,也就是配置的磁盘数,相关问题可以参考:https://github.com/opencurve/curveadm/issues/146
4+
instances: 20 # 请注意这里的replica不代表存储池的副本数,而是节点上同类进程的数量,比如这里指的是chunkserver进程的数量,也就是配置的磁盘数,相关问题可以参考:https://github.com/opencurve/curveadm/issues/146
55
config:
66
- host: ${machine2}
7-
replica: 20
7+
instances: 20
88
- host: ${machine3}
9-
replica: 20
9+
instances: 20
1010

configs/bs/cluster/topology.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ mds_services:
3636
chunkserver_services:
3737
config:
3838
listen.ip: ${service_host}
39-
listen.port: 82${format_replicas_sequence} # 8200,8201,8202
40-
data_dir: /data/chunkserver${service_replicas_sequence} # /data/chunkserver0, /data/chunksever1
39+
listen.port: 82${format_instances_sequence} # 8200,8201,8202
40+
data_dir: /data/chunkserver${service_instances_sequence} # /data/chunkserver0, /data/chunksever1
4141
copysets: 100
4242
deploy:
4343
- host: ${machine1}
44-
replicas: 3 # 请注意这里的replica不代表存储池的副本数,而是节点上同类进程的数量,比如这里指的是chunkserver进程的数量,也就是配置的磁盘数,相关问题可以参考:https://github.com/opencurve/curveadm/issues/146
44+
instances: 3
4545
- host: ${machine2}
46-
replicas: 3
46+
instances: 3
4747
- host: ${machine3}
48-
replicas: 3
48+
instances: 3
4949

5050
snapshotclone_services:
5151
config:

internal/configure/pool.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ type (
9898
* logicalpools:
9999
* - name: pool1
100100
* physicalpool: pool1
101-
* replicasnum: 3
101+
* replicassum: 3
102102
* copysetnum: 100
103103
* zonenum: 3
104104
* type: 0
@@ -121,7 +121,7 @@ type (
121121
* ...
122122
* pools:
123123
* - name: pool1
124-
* replicasnum: 3
124+
* replicasum: 3
125125
* copysetnum: 100
126126
* zonenum: 3
127127
*/
@@ -139,7 +139,7 @@ func SortDeployConfigs(dcs []*topology.DeployConfig) {
139139
dc1, dc2 := dcs[i], dcs[j]
140140
if dc1.GetRole() == dc2.GetRole() {
141141
if dc1.GetHostSequence() == dc2.GetHostSequence() {
142-
return dc1.GetReplicasSequence() < dc2.GetReplicasSequence()
142+
return dc1.GetInstancesSequence() < dc2.GetInstancesSequence()
143143
}
144144
return dc1.GetHostSequence() < dc2.GetHostSequence()
145145
}
@@ -148,7 +148,7 @@ func SortDeployConfigs(dcs []*topology.DeployConfig) {
148148
}
149149

150150
func formatName(dc *topology.DeployConfig) string {
151-
return fmt.Sprintf("%s_%s_%d", dc.GetHost(), dc.GetName(), dc.GetReplicasSequence())
151+
return fmt.Sprintf("%s_%s_%d", dc.GetHost(), dc.GetName(), dc.GetInstancesSequence())
152152
}
153153

154154
func createLogicalPool(dcs []*topology.DeployConfig, logicalPool, poolset string) (LogicalPool, []Server) {
@@ -168,14 +168,14 @@ func createLogicalPool(dcs []*topology.DeployConfig, logicalPool, poolset string
168168
zone = nextZone()
169169
}
170170

171-
// NOTE: if we deploy chunkservers with replica feature
172-
// and the value of replica greater than 1, we should
171+
// NOTE: if we deploy chunkservers with instance feature
172+
// and the value of instance greater than 1, we should
173173
// set internal port and external port to 0 for let MDS
174174
// attribute them as services on the same machine.
175175
// see issue: https://github.com/opencurve/curve/issues/1441
176176
internalPort := dc.GetListenPort()
177177
externalPort := dc.GetListenExternalPort()
178-
if dc.GetReplicas() > 1 {
178+
if dc.GetInstances() > 1 {
179179
internalPort = 0
180180
externalPort = 0
181181
}

internal/configure/topology/dc.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ const (
4848

4949
type (
5050
DeployConfig struct {
51-
kind string // KIND_CURVEFS / KIND_CUVREBS
52-
id string // role_host_[name/hostSequence]_replicasSequence
53-
parentId string // role_host_[name/hostSequence]_0
54-
role string // etcd/mds/metaserevr/chunkserver
55-
host string
56-
hostname string
57-
name string
58-
replicas int
59-
hostSequence int // start with 0
60-
replicasSequence int // start with 0
51+
kind string // KIND_CURVEFS / KIND_CUVREBS
52+
id string // role_host_[name/hostSequence]_instancesSequence
53+
parentId string // role_host_[name/hostSequence]_0
54+
role string // etcd/mds/metaserevr/chunkserver
55+
host string
56+
hostname string
57+
name string
58+
instances int
59+
hostSequence int // start with 0
60+
instancesSequence int // start with 0
6161

6262
config map[string]interface{}
6363
serviceConfig map[string]string
@@ -73,8 +73,8 @@ type (
7373
)
7474

7575
// etcd_hostname_0_0
76-
func formatId(role, host, name string, replicasSequence int) string {
77-
return fmt.Sprintf("%s_%s_%s_%d", role, host, name, replicasSequence)
76+
func formatId(role, host, name string, instancesSequence int) string {
77+
return fmt.Sprintf("%s_%s_%s_%d", role, host, name, instancesSequence)
7878
}
7979

8080
func formatName(name string, hostSequence int) string {
@@ -104,8 +104,8 @@ func newVariables(m map[string]interface{}) (*variable.Variables, error) {
104104
return vars, nil
105105
}
106106

107-
func NewDeployConfig(ctx *Context, kind, role, host, name string, replicas int,
108-
hostSequence, replicasSequence int, config map[string]interface{}) (*DeployConfig, error) {
107+
func NewDeployConfig(ctx *Context, kind, role, host, name string, instances int,
108+
hostSequence, instancesSequence int, config map[string]interface{}) (*DeployConfig, error) {
109109
// variable section
110110
v := config[CONFIG_VARIABLE.key]
111111
if !utils.IsStringAnyMap(v) && v != nil {
@@ -137,19 +137,19 @@ func NewDeployConfig(ctx *Context, kind, role, host, name string, replicas int,
137137

138138
name = formatName(name, hostSequence)
139139
return &DeployConfig{
140-
kind: kind,
141-
id: formatId(role, host, name, replicasSequence),
142-
parentId: formatId(role, host, name, 0),
143-
role: role,
144-
host: host,
145-
name: name,
146-
replicas: replicas,
147-
hostSequence: hostSequence,
148-
replicasSequence: replicasSequence,
149-
config: config,
150-
serviceConfig: map[string]string{},
151-
variables: vars,
152-
ctx: ctx,
140+
kind: kind,
141+
id: formatId(role, host, name, instancesSequence),
142+
parentId: formatId(role, host, name, 0),
143+
role: role,
144+
host: host,
145+
name: name,
146+
instances: instances,
147+
hostSequence: hostSequence,
148+
instancesSequence: instancesSequence,
149+
config: config,
150+
serviceConfig: map[string]string{},
151+
variables: vars,
152+
ctx: ctx,
153153
}, nil
154154
}
155155

internal/configure/topology/dc_get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ func (dc *DeployConfig) GetRole() string { return dc.role }
117117
func (dc *DeployConfig) GetHost() string { return dc.host }
118118
func (dc *DeployConfig) GetHostname() string { return dc.hostname }
119119
func (dc *DeployConfig) GetName() string { return dc.name }
120-
func (dc *DeployConfig) GetReplicas() int { return dc.replicas }
120+
func (dc *DeployConfig) GetInstances() int { return dc.instances }
121121
func (dc *DeployConfig) GetHostSequence() int { return dc.hostSequence }
122-
func (dc *DeployConfig) GetReplicasSequence() int { return dc.replicasSequence }
122+
func (dc *DeployConfig) GetInstancesSequence() int { return dc.instancesSequence }
123123
func (dc *DeployConfig) GetServiceConfig() map[string]string { return dc.serviceConfig }
124124
func (dc *DeployConfig) GetVariables() *variable.Variables { return dc.variables }
125125

internal/configure/topology/topology.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ var (
3939

4040
type (
4141
Deploy struct {
42-
Host string `mapstructure:"host"`
43-
Name string `mapstructure:"name"`
44-
Replica int `mapstructure:"replica"` // old version
45-
Replicas int `mapstructure:"replicas"`
46-
Config map[string]interface{} `mapstructure:"config"`
42+
Host string `mapstructure:"host"`
43+
Name string `mapstructure:"name"`
44+
Replica int `mapstructure:"replica"` // old version
45+
Replicas int `mapstructure:"replicas"` // old version
46+
Instances int `mapstructure:"instances"`
47+
Config map[string]interface{} `mapstructure:"config"`
4748
}
4849

4950
Service struct {
@@ -140,23 +141,28 @@ func ParseTopology(data string, ctx *Context) ([]*DeployConfig, error) {
140141
merge(servicesConfig, deployConfig, 1)
141142

142143
// create deploy config
143-
replicas := 1
144+
instances := 1
144145
if deploy.Replicas < 0 {
145-
return nil, errno.ERR_REPLICAS_REQUIRES_POSITIVE_INTEGER.
146+
return nil, errno.ERR_INSTANCES_REQUIRES_POSITIVE_INTEGER.
146147
F("replicas: %d", deploy.Replicas)
147148
} else if deploy.Replica < 0 {
148-
return nil, errno.ERR_REPLICAS_REQUIRES_POSITIVE_INTEGER.
149+
return nil, errno.ERR_INSTANCES_REQUIRES_POSITIVE_INTEGER.
149150
F("replica: %d", deploy.Replica)
151+
} else if deploy.Instances < 0 {
152+
return nil, errno.ERR_INSTANCES_REQUIRES_POSITIVE_INTEGER.
153+
F("Instance: %d", deploy.Instances)
154+
} else if deploy.Instances > 0 {
155+
instances = deploy.Instances
150156
} else if deploy.Replicas > 0 {
151-
replicas = deploy.Replicas
157+
instances = deploy.Replicas
152158
} else if deploy.Replica > 0 {
153-
replicas = deploy.Replica
159+
instances = deploy.Replica
154160
}
155161

156-
for replicasSequence := 0; replicasSequence < replicas; replicasSequence++ {
162+
for instancesSequence := 0; instancesSequence < instances; instancesSequence++ {
157163
dc, err := NewDeployConfig(ctx, kind,
158-
role, deploy.Host, deploy.Name, replicas,
159-
hostSequence, replicasSequence, utils.DeepCopy(deployConfig))
164+
role, deploy.Host, deploy.Name, instances,
165+
hostSequence, instancesSequence, utils.DeepCopy(deployConfig))
160166
if err != nil {
161167
return nil, err // already is error code
162168
}

internal/configure/topology/variables.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ type Var struct {
5959
* ${service_role} "mds"
6060
* ${service_host} "10.0.0.1"
6161
* ${service_host_sequence} "1"
62-
* ${service_replicas_sequence} "1"
63-
* ${format_replicas_sequence} "01"
62+
* ${service_instances_sequence} "1"
63+
* ${format_instances_sequence} "01"
6464
* ${service_addr} "10.0.0.1"
6565
* ${service_port} "6666"
6666
* ${service_client_port} "2379" (etcd)
@@ -94,8 +94,10 @@ var (
9494
{name: "service_host_sequence"},
9595
{name: "service_replica_sequence"},
9696
{name: "service_replicas_sequence"},
97+
{name: "service_instances_sequence"},
9798
{name: "format_replica_sequence"},
9899
{name: "format_replicas_sequence"},
100+
{name: "format_instances_sequence"},
99101
{name: "service_addr", lookup: true},
100102
{name: "service_port"},
101103
{name: "service_client_port", role: []string{ROLE_ETCD}},
@@ -174,10 +176,10 @@ func joinEtcdPeer(dcs []*DeployConfig) string {
174176
}
175177

176178
hostSequence := dc.GetHostSequence()
177-
replicaSquence := dc.GetReplicasSequence()
179+
instanceSquence := dc.GetInstancesSequence()
178180
peerHost := dc.GetListenIp()
179181
peerPort := dc.GetListenPort()
180-
peer := fmt.Sprintf("etcd%d%d=http://%s:%d", hostSequence, replicaSquence, peerHost, peerPort)
182+
peer := fmt.Sprintf("etcd%d%d=http://%s:%d", hostSequence, instanceSquence, peerHost, peerPort)
181183
peers = append(peers, peer)
182184
}
183185
return strings.Join(peers, ",")
@@ -245,13 +247,17 @@ func getValue(name string, dcs []*DeployConfig, idx int) string {
245247
case "service_host_sequence":
246248
return strconv.Itoa(dc.GetHostSequence())
247249
case "service_replica_sequence":
248-
return strconv.Itoa(dc.GetReplicasSequence())
250+
return strconv.Itoa(dc.GetInstancesSequence())
249251
case "service_replicas_sequence":
250-
return strconv.Itoa(dc.GetReplicasSequence())
252+
return strconv.Itoa(dc.GetInstancesSequence())
253+
case "service_instances_sequence":
254+
return strconv.Itoa(dc.GetInstancesSequence())
251255
case "format_replica_sequence":
252-
return fmt.Sprintf("%02d", dc.GetReplicasSequence())
256+
return fmt.Sprintf("%02d", dc.GetInstancesSequence())
253257
case "format_replicas_sequence":
254-
return fmt.Sprintf("%02d", dc.GetReplicasSequence())
258+
return fmt.Sprintf("%02d", dc.GetInstancesSequence())
259+
case "format_instances_sequence":
260+
return fmt.Sprintf("%02d", dc.GetInstancesSequence())
255261
case "service_addr":
256262
return utils.Atoa(dc.get(CONFIG_LISTEN_IP))
257263
case "service_port":

internal/errno/errno.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ var (
311311
ERR_RENDERING_VARIABLE_FAILED = EC(330007, "rendering variable failed")
312312
ERR_CREATE_HASH_FOR_TOPOLOGY_FAILED = EC(330008, "create hash for topology failed")
313313
// 331: configure (topology.yaml: invalid configure value)
314-
ERR_UNSUPPORT_CLUSTER_KIND = EC(331000, "unsupport cluster kind")
315-
ERR_NO_SERVICES_IN_TOPOLOGY = EC(331001, "no services in topology")
316-
ERR_REPLICAS_REQUIRES_POSITIVE_INTEGER = EC(331002, "replicas requires a positive integer")
317-
ERR_INVALID_VARIABLE_SECTION = EC(331003, "invalid variable section")
318-
ERR_DUPLICATE_SERVICE_ID = EC(331004, "service id is duplicate")
314+
ERR_UNSUPPORT_CLUSTER_KIND = EC(331000, "unsupport cluster kind")
315+
ERR_NO_SERVICES_IN_TOPOLOGY = EC(331001, "no services in topology")
316+
ERR_INSTANCES_REQUIRES_POSITIVE_INTEGER = EC(331002, "instances requires a positive integer")
317+
ERR_INVALID_VARIABLE_SECTION = EC(331003, "invalid variable section")
318+
ERR_DUPLICATE_SERVICE_ID = EC(331004, "service id is duplicate")
319319
// 332: configure (topology.yaml: update topology)
320320
ERR_DELETE_SERVICE_WHILE_COMMIT_TOPOLOGY_IS_DENIED = EC(332000, "delete service while commit topology is denied")
321321
ERR_ADD_SERVICE_WHILE_COMMIT_TOPOLOGY_IS_DENIED = EC(332001, "add service while commit topology is denied")

0 commit comments

Comments
 (0)