Skip to content

Commit

Permalink
1,extend the time to reset cache (#1440) 2,fix lint problems (#1466)
Browse files Browse the repository at this point in the history
* extend the time to reset cache (#1440)

Co-authored-by: songshiyuan 00649746 <[email protected]>

* fix lint problems (#1451)

Co-authored-by: l00618052 <[email protected]>
(cherry picked from commit a0e09e1)

---------

Co-authored-by: songshiyuan 00649746 <[email protected]>
Co-authored-by: Dantlian <[email protected]>
  • Loading branch information
3 people committed Apr 1, 2024
1 parent 93c4d37 commit 8be30c5
Show file tree
Hide file tree
Showing 56 changed files with 111 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.51.2
version: v1.55.2
args: --timeout=5m --skip-dirs='api,test,.*/controller/(v3|v4)$,.*/bootstrap$,examples,integration' --enable gofmt,revive,gocyclo,goimports --skip-files=.*_test.go$
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Client struct {
Cfg Config
}

func (c *Client) CommonHeaders(ctx context.Context) http.Header {
func (c *Client) CommonHeaders(_ context.Context) http.Header {
var headers = make(http.Header)
// TODO overwrote by context values
if len(c.Cfg.Token) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion client/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/apache/servicecomb-service-center/pkg/util"
)

func (c *LBClient) WebsocketDial(ctx context.Context, api string, headers http.Header) (conn *websocket.Conn, err error) {
func (c *LBClient) WebsocketDial(_ context.Context, api string, headers http.Header) (conn *websocket.Conn, err error) {
dialer := &websocket.Dialer{TLSClientConfig: c.TLS}
var errs []string
for i := 0; i < c.Retries; i++ {
Expand Down
4 changes: 2 additions & 2 deletions datasource/dependency_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func toString(in *discovery.MicroServiceKey) string {
return path.GenerateProviderDependencyRuleKey(in.Tenant, in)
}

func ParseAddOrUpdateRules(ctx context.Context, dep *Dependency, oldProviderRules *discovery.MicroServiceDependency) {
func ParseAddOrUpdateRules(_ context.Context, dep *Dependency, oldProviderRules *discovery.MicroServiceDependency) {
deleteDependencyRuleList := make([]*discovery.MicroServiceKey, 0, len(oldProviderRules.Dependency))
createDependencyRuleList := make([]*discovery.MicroServiceKey, 0, len(dep.ProvidersRule))
existDependencyRuleList := make([]*discovery.MicroServiceKey, 0, len(oldProviderRules.Dependency))
Expand All @@ -83,7 +83,7 @@ func ParseAddOrUpdateRules(ctx context.Context, dep *Dependency, oldProviderRule
setDep(dep, createDependencyRuleList, existDependencyRuleList, deleteDependencyRuleList)
}

func ParseOverrideRules(ctx context.Context, dep *Dependency, oldProviderRules *discovery.MicroServiceDependency) {
func ParseOverrideRules(_ context.Context, dep *Dependency, oldProviderRules *discovery.MicroServiceDependency) {
deleteDependencyRuleList := make([]*discovery.MicroServiceKey, 0, len(oldProviderRules.Dependency))
createDependencyRuleList := make([]*discovery.MicroServiceKey, 0, len(dep.ProvidersRule))
existDependencyRuleList := make([]*discovery.MicroServiceKey, 0, len(oldProviderRules.Dependency))
Expand Down
4 changes: 2 additions & 2 deletions datasource/etcd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func init() {
rbac.Install("embedded_etcd", NewRbacDAO)
}

func NewRbacDAO(opts rbac.Options) (rbac.DAO, error) {
func NewRbacDAO(_ rbac.Options) (rbac.DAO, error) {
return &RbacDAO{}, nil
}

Expand Down Expand Up @@ -187,7 +187,7 @@ func (ds *RbacDAO) DeleteAccount(ctx context.Context, names []string) (bool, err
return true, nil
}

func (ds *RbacDAO) UpdateAccount(ctx context.Context, name string, account *crbac.Account) error {
func (ds *RbacDAO) UpdateAccount(ctx context.Context, _ string, account *crbac.Account) error {
var (
opts []etcdadpt.OpOptions
err error
Expand Down
2 changes: 1 addition & 1 deletion datasource/etcd/cache/filter_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (f *ConsumerFilter) Name(ctx context.Context, _ *cache.Node) string {
return ctx.Value(CtxConsumerID).(string)
}

func (f *ConsumerFilter) Init(ctx context.Context, parent *cache.Node) (node *cache.Node, err error) {
func (f *ConsumerFilter) Init(_ context.Context, _ *cache.Node) (node *cache.Node, err error) {
node = cache.NewNode()
node.Cache.Set(DepResult, &DependencyRuleItem{})
return
Expand Down
2 changes: 1 addition & 1 deletion datasource/etcd/cache/filter_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (f *ServiceFilter) Name(ctx context.Context, _ *cache.Node) string {
provider.ServiceName}, "/")
}

func (f *ServiceFilter) Init(ctx context.Context, parent *cache.Node) (node *cache.Node, err error) {
func (f *ServiceFilter) Init(_ context.Context, _ *cache.Node) (node *cache.Node, err error) {
node = cache.NewNode()
return
}
2 changes: 1 addition & 1 deletion datasource/etcd/cache/filter_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (f *VersionFilter) Name(ctx context.Context, _ *cache.Node) string {
return ""
}

func (f *VersionFilter) Init(ctx context.Context, parent *cache.Node) (node *cache.Node, err error) {
func (f *VersionFilter) Init(ctx context.Context, _ *cache.Node) (node *cache.Node, err error) {
instance, ok := ctx.Value(CtxProviderInstanceKey).(*pb.HeartbeatSetElement)
if ok {
node = cache.NewNode()
Expand Down
6 changes: 3 additions & 3 deletions datasource/etcd/cache/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (f *FindInstancesCache) GetWithProviderID(ctx context.Context, consumer *pb
func (f *FindInstancesCache) Remove(provider *pb.MicroServiceKey) {
f.Tree.Remove(context.WithValue(context.Background(), CtxProviderKey, provider))
if len(provider.Alias) > 0 {
copy := *provider
copy.ServiceName = copy.Alias
f.Tree.Remove(context.WithValue(context.Background(), CtxProviderKey, &copy))
copyProvider := *provider
copyProvider.ServiceName = copyProvider.Alias
f.Tree.Remove(context.WithValue(context.Background(), CtxProviderKey, &copyProvider))
}
}
11 changes: 5 additions & 6 deletions datasource/etcd/ms.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (ds *MetadataManager) RegisterService(ctx context.Context, request *pb.Crea
}, nil
}

func (ds *MetadataManager) ListService(ctx context.Context, request *pb.GetServicesRequest) (
func (ds *MetadataManager) ListService(ctx context.Context, _ *pb.GetServicesRequest) (
*pb.GetServicesResponse, error) {
services, err := eutil.GetAllServiceUtil(ctx)
if err != nil {
Expand Down Expand Up @@ -186,7 +186,7 @@ func (ds *MetadataManager) GetService(ctx context.Context, request *pb.GetServic
return singleService, nil
}

func (ds *MetadataManager) GetOverview(ctx context.Context, request *pb.GetServicesRequest) (
func (ds *MetadataManager) GetOverview(ctx context.Context, _ *pb.GetServicesRequest) (
*pb.Statistics, error) {
ctx = util.WithCacheOnly(ctx)
st, err := statistics(ctx, false)
Expand Down Expand Up @@ -848,10 +848,9 @@ func (ds *MetadataManager) SendManyHeartbeat(ctx context.Context, request *pb.He
log.Warn(fmt.Sprintf("instance[%s/%s] is duplicate request heartbeat set",
heartbeatElement.ServiceId, heartbeatElement.InstanceId))
continue
} else {
existFlag[heartbeatElement.ServiceId+heartbeatElement.InstanceId] = true
noMultiCounter++
}
existFlag[heartbeatElement.ServiceId+heartbeatElement.InstanceId] = true
noMultiCounter++
gopool.Go(getHeartbeatFunc(ctx, domainProject, instancesHbRst, heartbeatElement))
}
count := 0
Expand Down Expand Up @@ -913,7 +912,7 @@ func (ds *MetadataManager) SendHeartbeat(ctx context.Context, request *pb.Heartb
return nil
}

func (ds *MetadataManager) ListManyInstances(ctx context.Context, request *pb.GetAllInstancesRequest) (*pb.GetAllInstancesResponse, error) {
func (ds *MetadataManager) ListManyInstances(ctx context.Context, _ *pb.GetAllInstancesRequest) (*pb.GetAllInstancesResponse, error) {
domainProject := util.ParseDomainProject(ctx)
key := path.GetInstanceRootKey(domainProject) + path.SPLIT
opts := append(eutil.FromContext(ctx), etcdadpt.WithStrKey(key), etcdadpt.WithPrefix())
Expand Down
2 changes: 1 addition & 1 deletion datasource/etcd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {
schema.Install("embedded_etcd", NewSchemaDAO)
}

func NewSchemaDAO(opts schema.Options) (schema.DAO, error) {
func NewSchemaDAO(_ schema.Options) (schema.DAO, error) {
return &SchemaDAO{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion datasource/etcd/sd/aggregate/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ func (r *Repository) New(t kvstore.Type, cfg *kvstore.Options) state.State {
return NewAggregator(t, cfg)
}

func NewRepository(opts state.Config) state.Repository {
func NewRepository(_ state.Config) state.Repository {
return &Repository{}
}
2 changes: 1 addition & 1 deletion datasource/etcd/sd/k8s/adaptor/listwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type k8sListWatcher struct {
cb OnEventFunc
}

func (w *k8sListWatcher) Handle(ctx context.Context, obj interface{}) {
func (w *k8sListWatcher) Handle(_ context.Context, obj interface{}) {
if w.cb == nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion datasource/etcd/sd/k8s/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ func (r *Repository) New(t kvstore.Type, cfg *kvstore.Options) state.State {
return adaptor.NewK8sAdaptor(t, cfg)
}

func NewRepository(opts state.Config) state.Repository {
func NewRepository(_ state.Config) state.Repository {
return &Repository{}
}
2 changes: 1 addition & 1 deletion datasource/etcd/sd/servicecenter/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ func (r *Repository) New(t kvstore.Type, cfg *kvstore.Options) state.State {
return NewServiceCenterAdaptor(t, cfg)
}

func NewRepository(opts state.Config) state.Repository {
func NewRepository(_ state.Config) state.Repository {
return &Repository{}
}
2 changes: 1 addition & 1 deletion datasource/etcd/sd/servicecenter/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (c *Syncer) checkWithConflictHandleFunc(local *Cacher, remote dump.Getter,
}
}

func (c *Syncer) skipHandleFunc(origin *dump.KV, conflict dump.Getter, index int) {
func (c *Syncer) skipHandleFunc(_ *dump.KV, _ dump.Getter, _ int) {
}

func (c *Syncer) logConflictFunc(origin *dump.KV, conflict dump.Getter, index int) {
Expand Down
2 changes: 1 addition & 1 deletion datasource/etcd/state/etcd/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ func (r *Repository) New(t kvstore.Type, cfg *kvstore.Options) state.State {
return NewEtcdState(t.String(), cfg)
}

func NewRepository(opts state.Config) state.Repository {
func NewRepository(_ state.Config) state.Repository {
return &Repository{}
}
22 changes: 11 additions & 11 deletions datasource/etcd/state/kvstore/cache_null.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ var (
type nullCache struct {
}

func (n *nullCache) Name() string { return "NULL" }
func (n *nullCache) Size() int { return 0 }
func (n *nullCache) Get(k string) *KeyValue { return nil }
func (n *nullCache) GetAll(arr *[]*KeyValue) int { return 0 }
func (n *nullCache) GetPrefix(prefix string, arr *[]*KeyValue) int { return 0 }
func (n *nullCache) ForEach(iter func(k string, v *KeyValue) (next bool)) {}
func (n *nullCache) Put(k string, v *KeyValue) {}
func (n *nullCache) Remove(k string) {}
func (n *nullCache) MarkDirty() {}
func (n *nullCache) Dirty() bool { return false }
func (n *nullCache) Clear() {}
func (n *nullCache) Name() string { return "NULL" }
func (n *nullCache) Size() int { return 0 }
func (n *nullCache) Get(_ string) *KeyValue { return nil }
func (n *nullCache) GetAll(_ *[]*KeyValue) int { return 0 }
func (n *nullCache) GetPrefix(_ string, _ *[]*KeyValue) int { return 0 }
func (n *nullCache) ForEach(_ func(k string, v *KeyValue) (next bool)) {}
func (n *nullCache) Put(_ string, _ *KeyValue) {}
func (n *nullCache) Remove(_ string) {}
func (n *nullCache) MarkDirty() {}
func (n *nullCache) Dirty() bool { return false }
func (n *nullCache) Clear() {}

type nullCacher struct {
}
Expand Down
2 changes: 1 addition & 1 deletion datasource/etcd/state/kvstore/indexer_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type CacheIndexer struct {
Cache CacheReader
}

func (i *CacheIndexer) Search(ctx context.Context, opts ...etcdadpt.OpOption) (resp *Response, _ error) {
func (i *CacheIndexer) Search(_ context.Context, opts ...etcdadpt.OpOption) (resp *Response, _ error) {
op := etcdadpt.OpGet(opts...)
if op.Prefix {
resp = i.searchByPrefix(op)
Expand Down
9 changes: 4 additions & 5 deletions datasource/etcd/util/dependency_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ func (dr *DependencyRelation) GetDependencyConsumers(opts ...DependencyRelationF
log.Warn(fmt.Sprintf("consumer[%s/%s/%s/%s] does not exist",
consumer.Environment, consumer.AppId, consumer.ServiceName, consumer.Version))
continue
} else {
return nil, err
}
return nil, err
}

if op.NonSelf && service.ServiceId == dr.provider.ServiceId {
Expand Down Expand Up @@ -234,9 +233,9 @@ func (dr *DependencyRelation) GetDependencyConsumersOfProvider() ([]*pb.MicroSer
}

func (dr *DependencyRelation) GetConsumerOfSameServiceNameAndAppID(provider *pb.MicroServiceKey) ([]*pb.MicroServiceKey, error) {
copy := *provider
copy.Version = ""
prefix := path.GenerateProviderDependencyRuleKey(dr.domainProject, &copy)
copyProvider := *provider
copyProvider.Version = ""
prefix := path.GenerateProviderDependencyRuleKey(dr.domainProject, &copyProvider)

opts := append(FromContext(dr.ctx),
etcdadpt.WithStrKey(prefix),
Expand Down
8 changes: 4 additions & 4 deletions datasource/etcd/util/microservice_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ func searchServiceIDFromAlias(ctx context.Context, key *pb.MicroServiceKey) (str
}

func GetServiceAllVersions(ctx context.Context, key *pb.MicroServiceKey, alias bool) (*kvstore.Response, error) {
copy := *key
copy.Version = ""
copyKey := *key
copyKey.Version = ""
var (
prefix string
indexer kvstore.Indexer
)
if alias {
prefix = path.GenerateServiceAliasKey(&copy)
prefix = path.GenerateServiceAliasKey(&copyKey)
indexer = sd.ServiceAlias()
} else {
prefix = path.GenerateServiceIndexKey(&copy)
prefix = path.GenerateServiceIndexKey(&copyKey)
indexer = sd.ServiceIndex()
}
opts := append(FromContext(ctx),
Expand Down
4 changes: 2 additions & 2 deletions datasource/etcd/util/versionrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func LessEqual(start, end string) bool {
}

// Latest return latest version kv
func Latest(sorted []string, kvs []*kvstore.KeyValue, start, end string) []string {
func Latest(sorted []string, kvs []*kvstore.KeyValue, _, _ string) []string {
if len(sorted) == 0 {
return []string{}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func Range(sorted []string, kvs []*kvstore.KeyValue, start, end string) []string
}

// AtLess return version >= start
func AtLess(sorted []string, kvs []*kvstore.KeyValue, start, end string) []string {
func AtLess(sorted []string, kvs []*kvstore.KeyValue, start, _ string) []string {
total := len(sorted)
if total == 0 {
return []string{}
Expand Down
2 changes: 1 addition & 1 deletion datasource/mongo/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func init() {
rbac.Install("mongo", NewRbacDAO)
}

func NewRbacDAO(opts rbac.Options) (rbac.DAO, error) {
func NewRbacDAO(_ rbac.Options) (rbac.DAO, error) {
return &RbacDAO{}, nil
}

Expand Down
5 changes: 2 additions & 3 deletions datasource/mongo/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func updateDepTxn(ctx context.Context, dependencyInfos []*discovery.ConsumerDepe
})
}

func (ds *DepManager) DependencyHandle(ctx context.Context) (err error) {
func (ds *DepManager) DependencyHandle(_ context.Context) (err error) {
return nil
}

Expand Down Expand Up @@ -326,10 +326,9 @@ func removeProviderDeps(ctx context.Context, depRule *model.DependencyRule, cach
if !ok {
_, exist, err = FindServiceIds(ctx, depRule.ServiceKey, false)
if err != nil {
cache[id] = exist
return err
}

cache[id] = exist
}

filter := bson.M{
Expand Down
2 changes: 1 addition & 1 deletion datasource/mongo/dependency_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func findServiceKeysByAlias(ctx context.Context, key *discovery.MicroServiceKey,

type ServiceVersionFilter func(ctx context.Context, filter bson.D) ([]string, error)

func findServiceKeys(ctx context.Context, version string, filter bson.D) (newFilter bson.D) {
func findServiceKeys(_ context.Context, version string, filter bson.D) (newFilter bson.D) {
filter = append(filter, bson.E{Key: util.ConnectWithDot([]string{model.ColumnService, model.ColumnVersion}), Value: version})
return filter
}
Expand Down
4 changes: 2 additions & 2 deletions datasource/mongo/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
type SCManager struct {
}

func (ds *SCManager) UpgradeVersion(ctx context.Context) error {
func (ds *SCManager) UpgradeVersion(_ context.Context) error {
return nil
}

func (ds *SCManager) GetClusters(ctx context.Context) (etcdadpt.Clusters, error) {
func (ds *SCManager) GetClusters(_ context.Context) (etcdadpt.Clusters, error) {
return nil, nil
}
2 changes: 1 addition & 1 deletion datasource/mongo/heartbeat/cache/heartbeatcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (h *HeartBeatCache) Heartbeat(ctx context.Context, request *pb.HeartbeatReq
}

// CheckInstance func is to add instance related information to the cache
func (h *HeartBeatCache) CheckInstance(ctx context.Context, instance *pb.MicroServiceInstance) error {
func (h *HeartBeatCache) CheckInstance(_ context.Context, instance *pb.MicroServiceInstance) error {
return h.Cfg.AddHeartbeatTask(instance.ServiceId, instance.InstanceId, instance.HealthCheck.Interval*(instance.HealthCheck.Times+1))
}

Expand Down
2 changes: 1 addition & 1 deletion datasource/mongo/heartbeat/checker/heartbeatchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (h *HeartBeatChecker) Heartbeat(ctx context.Context, request *pb.HeartbeatR
}, nil
}

func (h *HeartBeatChecker) CheckInstance(ctx context.Context, instance *pb.MicroServiceInstance) error {
func (h *HeartBeatChecker) CheckInstance(_ context.Context, _ *pb.MicroServiceInstance) error {
// do nothing
return nil
}
Loading

0 comments on commit 8be30c5

Please sign in to comment.