Skip to content

Commit

Permalink
[fix] center fix the transfer of etcdadpt (#1465)
Browse files Browse the repository at this point in the history
Co-authored-by: songshiyuan 00649746 <[email protected]>
  • Loading branch information
tornado-ssy and songshiyuan 00649746 authored Mar 29, 2024
1 parent 01abe81 commit 0534041
Show file tree
Hide file tree
Showing 60 changed files with 187 additions and 147 deletions.
7 changes: 4 additions & 3 deletions client/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
"io"
"net/http"

"github.com/go-chassis/cari/discovery"
"github.com/go-chassis/cari/pkg/errsvc"
"github.com/go-chassis/etcdadpt"

"github.com/apache/servicecomb-service-center/pkg/dump"
"github.com/apache/servicecomb-service-center/pkg/util"
"github.com/apache/servicecomb-service-center/version"
"github.com/go-chassis/cari/discovery"
"github.com/go-chassis/cari/pkg/errsvc"
"github.com/little-cui/etcdadpt"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion datasource/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package datasource
import (
"context"

"github.com/little-cui/etcdadpt"
"github.com/go-chassis/etcdadpt"
)

// SCManager contains the APIs of registration of SC itself
Expand Down
8 changes: 4 additions & 4 deletions datasource/etcd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"time"

crbac "github.com/go-chassis/cari/rbac"
"github.com/go-chassis/etcdadpt"
"github.com/go-chassis/foundation/stringutil"
"github.com/little-cui/etcdadpt"

"github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/datasource/etcd/path"
Expand Down Expand Up @@ -142,7 +142,7 @@ func (ds *RbacDAO) ListAccount(ctx context.Context) ([]*crbac.Account, int64, er
err = json.Unmarshal(v.Value, a)
if err != nil {
log.Error("account info format invalid:", err)
continue //do not fail if some account is invalid
continue // do not fail if some account is invalid
}
a.Password = ""
ds.compatibleOldVersionAccount(a)
Expand All @@ -159,7 +159,7 @@ func (ds *RbacDAO) DeleteAccount(ctx context.Context, names []string) (bool, err
a, err := ds.GetAccount(ctx, name)
if err != nil {
log.Error("", err)
continue //do not fail if some account is invalid
continue // do not fail if some account is invalid
}
if a == nil {
log.Warn("can not find account")
Expand All @@ -168,7 +168,7 @@ func (ds *RbacDAO) DeleteAccount(ctx context.Context, names []string) (bool, err
opts, err := GenAccountOpts(a, etcdadpt.ActionDelete)
if err != nil {
log.Error("", err)
continue //do not fail if some account is invalid
continue // do not fail if some account is invalid

}
allOpts = append(allOpts, opts...)
Expand Down
5 changes: 3 additions & 2 deletions datasource/etcd/account_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (
"encoding/json"
"fmt"

"github.com/go-chassis/etcdadpt"

"github.com/apache/servicecomb-service-center/datasource/etcd/path"
"github.com/apache/servicecomb-service-center/datasource/rbac"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/little-cui/etcdadpt"
)

func (al *RbacDAO) UpsertLock(ctx context.Context, lock *rbac.Lock) error {
Expand Down Expand Up @@ -73,7 +74,7 @@ func (al *RbacDAO) ListLock(ctx context.Context) ([]*rbac.Lock, int64, error) {
err = json.Unmarshal(v.Value, lock)
if err != nil {
log.Error("account lock info format invalid:", err)
continue //do not fail if some account is invalid
continue // do not fail if some account is invalid
}
locks = append(locks, lock)
}
Expand Down
10 changes: 5 additions & 5 deletions datasource/etcd/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
package bootstrap

import (
//registry
_ "github.com/little-cui/etcdadpt/buildin"
_ "github.com/little-cui/etcdadpt/embedded"
_ "github.com/little-cui/etcdadpt/remote"
// registry
_ "github.com/go-chassis/etcdadpt/buildin"
_ "github.com/go-chassis/etcdadpt/embedded"
_ "github.com/go-chassis/etcdadpt/remote"

//discovery
// discovery
_ "github.com/apache/servicecomb-service-center/datasource/etcd/sd/aggregate"
_ "github.com/apache/servicecomb-service-center/datasource/etcd/sd/k8s"
_ "github.com/apache/servicecomb-service-center/datasource/etcd/sd/servicecenter"
Expand Down
5 changes: 3 additions & 2 deletions datasource/etcd/cache/filter_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
"context"
"fmt"

pb "github.com/go-chassis/cari/discovery"
"github.com/go-chassis/etcdadpt"

"github.com/apache/servicecomb-service-center/datasource/etcd/path"
"github.com/apache/servicecomb-service-center/datasource/etcd/sd"
"github.com/apache/servicecomb-service-center/datasource/etcd/util"
"github.com/apache/servicecomb-service-center/pkg/cache"
"github.com/apache/servicecomb-service-center/pkg/log"
pb "github.com/go-chassis/cari/discovery"
"github.com/little-cui/etcdadpt"
)

type InstancesFilter struct {
Expand Down
3 changes: 2 additions & 1 deletion datasource/etcd/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"context"
"fmt"

"github.com/go-chassis/etcdadpt"

"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/pkg/task"
"github.com/little-cui/etcdadpt"
)

// KeepAlive will always return ok when cache is unavailable
Expand Down
3 changes: 2 additions & 1 deletion datasource/etcd/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
"errors"
"testing"

"github.com/go-chassis/etcdadpt"

"github.com/apache/servicecomb-service-center/pkg/task"
"github.com/little-cui/etcdadpt"
)

var closedCh = make(chan struct{})
Expand Down
3 changes: 2 additions & 1 deletion datasource/etcd/client/lease_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import (
"fmt"
"time"

"github.com/go-chassis/etcdadpt"

"github.com/apache/servicecomb-service-center/pkg/log"
simple "github.com/apache/servicecomb-service-center/pkg/time"
"github.com/apache/servicecomb-service-center/pkg/util"
"github.com/apache/servicecomb-service-center/server/metrics"
"github.com/little-cui/etcdadpt"
)

const leaseProfTimeFmt = "15:04:05.000"
Expand Down
7 changes: 4 additions & 3 deletions datasource/etcd/client/lease_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
"errors"
"testing"

"github.com/apache/servicecomb-service-center/datasource/etcd/client"
"github.com/little-cui/etcdadpt"
"github.com/little-cui/etcdadpt/buildin"
"github.com/go-chassis/etcdadpt"
"github.com/go-chassis/etcdadpt/buildin"
"github.com/stretchr/testify/assert"

"github.com/apache/servicecomb-service-center/datasource/etcd/client"
)

type mockRegistry struct {
Expand Down
3 changes: 2 additions & 1 deletion datasource/etcd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ package etcd
import (
"time"

"github.com/go-chassis/etcdadpt"

"github.com/apache/servicecomb-service-center/server/config"
"github.com/little-cui/etcdadpt"
)

func Configuration() etcdadpt.Config {
Expand Down
2 changes: 1 addition & 1 deletion datasource/etcd/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"fmt"

pb "github.com/go-chassis/cari/discovery"
"github.com/little-cui/etcdadpt"
"github.com/go-chassis/etcdadpt"

"github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/datasource/etcd/event"
Expand Down
5 changes: 3 additions & 2 deletions datasource/etcd/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import (
"encoding/json"
"os"

"github.com/go-chassis/cari/dlock"
"github.com/go-chassis/etcdadpt"

"github.com/apache/servicecomb-service-center/datasource/etcd/path"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/server/config"
"github.com/apache/servicecomb-service-center/version"
"github.com/go-chassis/cari/dlock"
"github.com/little-cui/etcdadpt"
)

const versionLockKey = "/version-upgrade"
Expand Down
11 changes: 6 additions & 5 deletions datasource/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ import (
"strings"
"time"

"github.com/go-chassis/cari/dlock"
"github.com/go-chassis/etcdadpt"
"github.com/go-chassis/etcdadpt/middleware/tracing"
"github.com/go-chassis/foundation/gopool"

"github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/datasource/etcd/event"
"github.com/apache/servicecomb-service-center/datasource/etcd/sd"
"github.com/apache/servicecomb-service-center/datasource/etcd/state"
tracer "github.com/apache/servicecomb-service-center/datasource/etcd/tracing"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/server/config"
"github.com/go-chassis/cari/dlock"
"github.com/go-chassis/foundation/gopool"
"github.com/little-cui/etcdadpt"
"github.com/little-cui/etcdadpt/middleware/tracing"
)

const compactLockKey = "/etcd-compact"
Expand All @@ -43,7 +44,7 @@ var clustersIndex = make(map[string]int)

func init() {
datasource.Install("etcd", NewDataSource)
datasource.Install("embeded_etcd", NewDataSource) //TODO remove misspell in future
datasource.Install("embeded_etcd", NewDataSource) // TODO remove misspell in future
datasource.Install("embedded_etcd", NewDataSource)

sd.RegisterInnerTypes()
Expand Down
15 changes: 8 additions & 7 deletions datasource/etcd/event/dependency_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ import (
"sync"
"time"

pb "github.com/go-chassis/cari/discovery"
"github.com/go-chassis/cari/dlock"
"github.com/go-chassis/etcdadpt"
"github.com/go-chassis/foundation/backoff"
"github.com/go-chassis/foundation/gopool"
"github.com/go-chassis/foundation/stringutil"
"github.com/go-chassis/foundation/timeutil"

"github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/datasource/etcd/path"
"github.com/apache/servicecomb-service-center/datasource/etcd/sd"
Expand All @@ -32,13 +40,6 @@ import (
"github.com/apache/servicecomb-service-center/pkg/queue"
"github.com/apache/servicecomb-service-center/pkg/util"
"github.com/apache/servicecomb-service-center/server/config"
pb "github.com/go-chassis/cari/discovery"
"github.com/go-chassis/cari/dlock"
"github.com/go-chassis/foundation/backoff"
"github.com/go-chassis/foundation/gopool"
"github.com/go-chassis/foundation/stringutil"
"github.com/go-chassis/foundation/timeutil"
"github.com/little-cui/etcdadpt"
)

const depQueueLockKey = "/dep-queue"
Expand Down
5 changes: 3 additions & 2 deletions datasource/etcd/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import (
"context"
"fmt"

"github.com/go-chassis/cari/discovery"
"github.com/go-chassis/etcdadpt"

"github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/datasource/etcd/path"
"github.com/apache/servicecomb-service-center/datasource/etcd/sd"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/go-chassis/cari/discovery"
"github.com/little-cui/etcdadpt"
)

type MetricsManager struct {
Expand Down
27 changes: 14 additions & 13 deletions datasource/etcd/ms.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import (
"strconv"
"time"

pb "github.com/go-chassis/cari/discovery"
"github.com/go-chassis/cari/pkg/errsvc"
"github.com/go-chassis/cari/sync"
"github.com/go-chassis/etcdadpt"
"github.com/go-chassis/foundation/gopool"

"github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/datasource/etcd/cache"
"github.com/apache/servicecomb-service-center/datasource/etcd/path"
Expand All @@ -43,11 +49,6 @@ import (
"github.com/apache/servicecomb-service-center/server/plugin/uuid"
quotasvc "github.com/apache/servicecomb-service-center/server/service/quota"
"github.com/apache/servicecomb-service-center/syncer/service/event"
pb "github.com/go-chassis/cari/discovery"
"github.com/go-chassis/cari/pkg/errsvc"
"github.com/go-chassis/cari/sync"
"github.com/go-chassis/foundation/gopool"
"github.com/little-cui/etcdadpt"
)

type MetadataManager struct {
Expand Down Expand Up @@ -391,7 +392,7 @@ func (ds *MetadataManager) registerInstance(ctx context.Context, request *pb.Reg
remoteIP := util.GetIPFromContext(ctx)
instance := request.Instance

//允许自定义id
// 允许自定义id
if len(instance.InstanceId) > 0 {
needRegister, err := ds.sendHeartbeatInstead(ctx, instance)
if err != nil {
Expand All @@ -408,7 +409,7 @@ func (ds *MetadataManager) registerInstance(ctx context.Context, request *pb.Reg
instanceFlag := fmt.Sprintf("ttl %ds, endpoints %v, host '%s', serviceID %s",
ttl, instance.Endpoints, instance.HostName, instance.ServiceId)

//先以domain/project的方式组装
// 先以domain/project的方式组装
domainProject := util.ParseDomainProject(ctx)

instanceID := instance.InstanceId
Expand Down Expand Up @@ -1251,7 +1252,7 @@ func (ds *MetadataManager) PutTag(ctx context.Context, request *pb.UpdateService
return pb.NewError(pb.ErrInternal, err.Error())
}

//check if the tag exists
// check if the tag exists
if _, ok := tags[request.Key]; !ok {
log.Error(fmt.Sprintf("update service[%s]'s tag[%s] failed, tag does not exist, operator: %s",
request.ServiceId, tagFlag, remoteIP), nil)
Expand Down Expand Up @@ -1580,7 +1581,7 @@ func (ds *MetadataManager) UnregisterService(ctx context.Context, request *pb.De
}
opts = append(opts, syncOpts...)

//删除依赖规则
// 删除依赖规则
optDeleteDep, err := eutil.DeleteDependencyForDeleteService(domainProject, serviceID, serviceKey)
if err != nil {
log.Error(fmt.Sprintf("%s micro-service[%s] failed, delete dependency failed, operator: %s",
Expand All @@ -1600,19 +1601,19 @@ func (ds *MetadataManager) UnregisterService(ctx context.Context, request *pb.De
etcdadpt.WithStrKey(path.GenerateServiceSchemaRefKey(domainProject, serviceID, "")),
etcdadpt.WithPrefix()))

//删除tags
// 删除tags
opts = append(opts, etcdadpt.OpDel(
etcdadpt.WithStrKey(path.GenerateServiceTagKey(domainProject, serviceID))))

//删除instances
// 删除instances
opts = append(opts, etcdadpt.OpDel(
etcdadpt.WithStrKey(path.GenerateInstanceKey(domainProject, serviceID, "")),
etcdadpt.WithPrefix()))
opts = append(opts, etcdadpt.OpDel(
etcdadpt.WithStrKey(path.GenerateInstanceLeaseKey(domainProject, serviceID, "")),
etcdadpt.WithPrefix()))

//删除实例
// 删除实例
err = eutil.DeleteServiceAllInstances(ctx, serviceID)
if err != nil {
log.Error(fmt.Sprintf("%s micro-service[%s] failed, revoke all instances failed, operator: %s",
Expand Down Expand Up @@ -1668,7 +1669,7 @@ func (ds *MetadataManager) UpdateManyInstanceStatus(ctx context.Context, match *
}
if t {
key := path.GenerateInstanceKey(domainProject, instance.ServiceId, instance.InstanceId)
//更新状态
// 更新状态
instance.Status = status
data, _ := json.Marshal(instance)
leaseID, err := serviceUtil.GetLeaseID(ctx, domainProject, instance.ServiceId, instance.InstanceId)
Expand Down
7 changes: 4 additions & 3 deletions datasource/etcd/retire.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"fmt"
"sync/atomic"

pb "github.com/go-chassis/cari/discovery"
"github.com/go-chassis/etcdadpt"
"github.com/go-chassis/foundation/gopool"

"github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/datasource/etcd/path"
"github.com/apache/servicecomb-service-center/datasource/etcd/sd"
Expand All @@ -30,9 +34,6 @@ import (
"github.com/apache/servicecomb-service-center/pkg/goutil"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/pkg/util"
pb "github.com/go-chassis/cari/discovery"
"github.com/go-chassis/foundation/gopool"
"github.com/little-cui/etcdadpt"
)

const poolSizeOfRotation = 5
Expand Down
Loading

0 comments on commit 0534041

Please sign in to comment.