Skip to content

Commit

Permalink
fix the bug that registering without instanceid will add reregistrati…
Browse files Browse the repository at this point in the history
…on property (#1502)
  • Loading branch information
Wanghb1 authored Mar 6, 2025
1 parent 9083ad2 commit 04b8429
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/service/disco/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
"sync"
"time"

"github.com/apache/servicecomb-service-center/pkg/protect"
pb "github.com/go-chassis/cari/discovery"
"github.com/go-chassis/cari/pkg/errsvc"

"github.com/apache/servicecomb-service-center/pkg/protect"

"github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/pkg/util"
Expand Down Expand Up @@ -74,14 +75,18 @@ func RegisterInstance(ctx context.Context, in *pb.RegisterInstanceRequest) (*pb.
if popErr := populateInstanceDefaultValue(ctx, in.Instance); popErr != nil {
return nil, popErr
}
var reRegistration bool
if len(in.Instance.InstanceId) != 0 {
reRegistration = true
}
resp, err := datasource.GetMetadataManager().RegisterInstance(ctx, in)
if err != nil {
log.Error(fmt.Sprintf("register instance failed, endpoints %v, host '%s', serviceID %s, operator %s",
in.Instance.Endpoints, in.Instance.HostName, in.Instance.ServiceId, remoteIP), err)
return nil, err
}
// re-register instance with id, should sync properties to peer
if len(in.Instance.InstanceId) != 0 {
if reRegistration {
in.Instance.Properties[reRegisterTimestamp] = time.Now().String()
err = PutInstanceProperties(ctx, &pb.UpdateInstancePropsRequest{
InstanceId: in.Instance.InstanceId,
Expand Down

0 comments on commit 04b8429

Please sign in to comment.