@@ -73,14 +73,14 @@ func NewArgs(clusterName string, endpoints []string) *Args {
73
73
}
74
74
}
75
75
76
- // RegInstance 注册实例,如果name为空,则自动使用ip作为名称 ,完整实例名称为 clusterName_name
77
- func (cluster * Cluster ) RegInstance (ctx context.Context , name string ) (base.Instance , error ) {
76
+ // RegInstance 注册实例,如果id为空,则自动使用ip作为id ,完整实例名称为 clusterName_id
77
+ func (cluster * Cluster ) RegInstance (ctx context.Context , id string ) (base.Instance , error ) {
78
78
if cluster .localInstance != nil {
79
79
// 已注册,直接返回
80
80
return cluster .localInstance , nil
81
81
}
82
82
// 创建实例
83
- ins , err := newInstance (cluster .args .ClusterName , name )
83
+ ins , err := newInstance (cluster .args .ClusterName , id )
84
84
if err != nil {
85
85
return nil , err
86
86
}
@@ -131,7 +131,7 @@ func (cluster *Cluster) GetAllInstances(ctx context.Context) ([]base.Instance, e
131
131
}
132
132
var instances []base.Instance
133
133
for _ , item := range rsp .Kvs {
134
- ins , err := newInstanceWithName (string (item .Key ))
134
+ ins , err := newInstanceWithID (string (item .Key ))
135
135
if err != nil {
136
136
continue
137
137
}
@@ -208,7 +208,7 @@ func (cluster *Cluster) startHeartBeat(ins *Instance) error {
208
208
if r := recover (); r != nil {
209
209
buf := make ([]byte , 4096 )
210
210
buf = buf [:runtime .Stack (buf , false )]
211
- fmt .Printf ("[HeartBeatPanic]ins:%v, err:%v, stack:\n %s\n " , ins .GetName (), r , buf )
211
+ fmt .Printf ("[HeartBeatPanic]ins:%v, err:%v, stack:\n %s\n " , ins .GetID (), r , buf )
212
212
// 如果故障,则退出进程(通常不可能进入到这里)
213
213
os .Exit (- 1 )
214
214
}
@@ -272,7 +272,7 @@ func delNode(ctx context.Context, cli *clientv3.Client, ins *Instance) error {
272
272
if ! ins .IsValid () {
273
273
return errors .New ("invalid instance" )
274
274
}
275
- _ , err := cli .Delete (ctx , ins .GetName ())
275
+ _ , err := cli .Delete (ctx , ins .GetID ())
276
276
_ , _ = cli .Revoke (ctx , ins .leaseID )
277
277
ins .clear ()
278
278
return err
@@ -289,7 +289,7 @@ func putNode(ctx context.Context, cli *clientv3.Client, ins *Instance, ttl int64
289
289
return err
290
290
}
291
291
// 写入etcd节点,节点内容暂无实际意义,暂且写入1
292
- _ , err = cli .Put (ctx , ins .GetName (), "1" , clientv3 .WithLease (rsp .ID ))
292
+ _ , err = cli .Put (ctx , ins .GetID (), "1" , clientv3 .WithLease (rsp .ID ))
293
293
if err != nil {
294
294
return err
295
295
}
0 commit comments