You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/03/31 10:49:56 UTC

[GitHub] [servicecomb-service-center] DFSOrange opened a new pull request #911: 【WIP】restructure cache

DFSOrange opened a new pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911


   暂不合入,检视用,已知问题
   1. 缺乏putifabsent的原子方法,实现待商榷
   2. ut补充
   3. instance及其他cache补齐


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608315330



##########
File path: datasource/mongo/client/dao/dep.go
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dao
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/datasource"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+	mutil "github.com/apache/servicecomb-service-center/datasource/mongo/util"
+	"github.com/apache/servicecomb-service-center/pkg/util"
+	"github.com/go-chassis/cari/discovery"
+)
+
+const (
+	p = "p"
+	c = "c"
+)
+
+func GetProviderServiceOfDeps(ctx context.Context, provider *discovery.MicroService) (*discovery.MicroServiceDependency, error) {
+	res := sd.Store().Dep().Cache().GetValue(genDepserivceKey(p, provider))
+	cacheServiceKeys, ok := processCacheDep(res)
+	if !ok || len(cacheServiceKeys) == 0 {
+		return GetServiceofDepsFromDB(ctx, p, provider)
+	}
+	return cacheServiceKeys[0], nil
+}
+
+func processCacheDep(cache []interface{}) ([]*discovery.MicroServiceDependency, bool) {
+	res := make([]*discovery.MicroServiceDependency, 0, len(cache))
+	for _, v := range cache {
+		t, ok := v.(model.DependencyRule)
+		if !ok {
+			return nil, false
+		}
+		res = append(res, t.Dep)
+	}
+	return res, true
+}
+
+func GetServiceofDepsFromDB(ctx context.Context, ruleType string, provider *discovery.MicroService) (*discovery.MicroServiceDependency, error) {
+	filter := mutil.NewFilter(
+		mutil.ServiceType(ruleType),
+		mutil.ServiceKeyTenant(util.ParseDomainProject(ctx)),
+		mutil.ServiceKeyAppID(provider.AppId),
+		mutil.ServiceKeyServiceName(provider.ServiceName),
+		mutil.ServiceKeyServiceVersion(provider.Version),
+	)
+	depRule, err := getDeps(ctx, filter)
+	if err != nil {
+		return nil, err
+	}
+	return depRule.Dep, nil
+}
+
+func genDepserivceKey(ruleType string, service *discovery.MicroService) string {
+	return util.StringJoin([]string{ruleType, service.AppId, service.ServiceName, service.Version}, "/")

Review comment:
       这个util包奶德方法没有意义,go明明自带这个func,难道有什么特别的优势,没有就干掉吧




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608389983



##########
File path: datasource/mongo/client/dao/rule.go
##########
@@ -29,6 +32,32 @@ import (
 	"github.com/apache/servicecomb-service-center/pkg/log"
 )
 
+func GetRulesByServiceID(ctx context.Context, serviceID string) ([]*model.Rule, error) {
+	cacheRes := sd.Store().Rule().Cache().GetValue(serviceID)
+	cacheRules, ok := processCacheRules(cacheRes)
+	if !ok || len(cacheRules) == 0 {
+		return GetRules(ctx, mutil.NewDomainProjectFilter(util.ParseDomain(ctx), util.ParseDomain(ctx), mutil.ServiceID(serviceID)))
+	}
+	return cacheRules, nil
+}
+
+func processCacheRules(cacheRules []interface{}) ([]*model.Rule, bool) {
+	res := make([]*model.Rule, 0, len(cacheRules))
+	for _, v := range cacheRules {
+		t, ok := v.(model.Rule)

Review comment:
       这里判断其实很频繁,封一个统一的cache API吧 参考下go chassis




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608383752



##########
File path: datasource/mongo/client/dao/dep.go
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dao
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/datasource"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+	mutil "github.com/apache/servicecomb-service-center/datasource/mongo/util"
+	"github.com/apache/servicecomb-service-center/pkg/util"
+	"github.com/go-chassis/cari/discovery"
+)
+
+const (
+	p = "p"

Review comment:
       这两个常量名没有可读性




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608384265



##########
File path: datasource/mongo/client/dao/dep.go
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dao
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/datasource"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+	mutil "github.com/apache/servicecomb-service-center/datasource/mongo/util"
+	"github.com/apache/servicecomb-service-center/pkg/util"
+	"github.com/go-chassis/cari/discovery"
+)
+
+const (
+	p = "p"
+	c = "c"
+)
+
+func GetProviderServiceOfDeps(ctx context.Context, provider *discovery.MicroService) (*discovery.MicroServiceDependency, error) {
+	res := sd.Store().Dep().Cache().GetValue(genDepserivceKey(p, provider))
+	cacheServiceKeys, ok := processCacheDep(res)
+	if !ok || len(cacheServiceKeys) == 0 {
+		return GetServiceofDepsFromDB(ctx, p, provider)
+	}
+	return cacheServiceKeys[0], nil
+}
+
+func processCacheDep(cache []interface{}) ([]*discovery.MicroServiceDependency, bool) {

Review comment:
       这类方法都放到工具pkg,processCacheDep这个方法名也不太明确到底在干嘛,有没有更好的命名方式




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] DFSOrange closed pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
DFSOrange closed pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608389983



##########
File path: datasource/mongo/client/dao/rule.go
##########
@@ -29,6 +32,32 @@ import (
 	"github.com/apache/servicecomb-service-center/pkg/log"
 )
 
+func GetRulesByServiceID(ctx context.Context, serviceID string) ([]*model.Rule, error) {
+	cacheRes := sd.Store().Rule().Cache().GetValue(serviceID)
+	cacheRules, ok := processCacheRules(cacheRes)
+	if !ok || len(cacheRules) == 0 {
+		return GetRules(ctx, mutil.NewDomainProjectFilter(util.ParseDomain(ctx), util.ParseDomain(ctx), mutil.ServiceID(serviceID)))
+	}
+	return cacheRules, nil
+}
+
+func processCacheRules(cacheRules []interface{}) ([]*model.Rule, bool) {
+	res := make([]*model.Rule, 0, len(cacheRules))
+	for _, v := range cacheRules {
+		t, ok := v.(model.Rule)

Review comment:
       这里判断其实很频繁,封一个统一的cache API吧 参考下go chassis https://github.com/go-chassis/go-chassis/commit/6f8d8843fabdec93d8fd633ffe4e2b64314d1329
   
   core/registry/cache.go 理想情况就是etcd,mongo用的同一套cache API,先通过mongbo实现把API定义好




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r612088248



##########
File path: datasource/mongo/sd/servicec_test.go
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package sd
+
+import (
+	"testing"
+
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
+	"github.com/go-chassis/cari/discovery"
+	"github.com/stretchr/testify/assert"
+)
+
+var serviceCache *MongoCacher
+
+var svc1 = model.Service{
+	Domain:  "default",
+	Project: "default",
+	Tags:    nil,
+	Service: &discovery.MicroService{
+		ServiceId:   "123456789",
+		AppId:       "appid1",
+		ServiceName: "svc1",
+		Version:     "1.0",
+	},
+}
+
+var svc2 = model.Service{
+	Domain:  "default",
+	Project: "default",
+	Tags:    nil,
+	Service: &discovery.MicroService{
+		ServiceId:   "987654321",
+		AppId:       "appid1",
+		ServiceName: "svc1",
+		Version:     "1.0",
+	},
+}
+
+func TestServiceCacheBasicFunc(t *testing.T) {
+	serviceCache := newServiceStore()
+	assert.NotNil(t, serviceCache)
+	assert.Equal(t, service, serviceCache.cache.Name())
+	event1 := MongoEvent{
+		DocumentID: "id1",
+		Value:      svc1,
+	}
+	event2 := MongoEvent{
+		DocumentID: "id2",
+		Value:      svc2,
+	}
+	serviceCache.cache.ProcessUpdate(event1)
+	assert.Equal(t, serviceCache.cache.Size(), 1)
+	assert.Nil(t, serviceCache.cache.Get("id_not_exist"))

Review comment:
       整理下UT,不要平铺直叙,不易读




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608386019



##########
File path: datasource/mongo/client/dao/instance.go
##########
@@ -19,6 +19,9 @@ package dao
 
 import (
 	"context"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"

Review comment:
       dao层不能依赖cache层




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608387609



##########
File path: datasource/mongo/event/instance_event_handler_test.go
##########
@@ -118,7 +117,6 @@ func mongoEventWronServiceId() sd.MongoEvent {
 	mongoEvent.DocumentID = "5fdc483b4a885f69317e3505"
 	mongoEvent.Value = mongoInstance
 	mongoEvent.Type = discovery.EVT_CREATE
-	mongoEvent.ResourceID = "f73dceb440f711eba63ffa163e7cdcb8"

Review comment:
       为何删了

##########
File path: datasource/mongo/ms.go
##########
@@ -2591,49 +2590,6 @@ func allowAcrossDimension(ctx context.Context, providerService *model.Service, c
 	return nil
 }
 
-func GetServiceByID(ctx context.Context, serviceID string) (*model.Service, error) {
-	cacheService, ok := sd.Store().Service().Cache().Get(serviceID).(model.Service)

Review comment:
       这一层才该依赖cache层




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] DFSOrange closed pull request #911: 【WIP】restructure cache

Posted by GitBox <gi...@apache.org>.
DFSOrange closed pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang merged pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang merged pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608386613



##########
File path: datasource/mongo/client/dao/microservice.go
##########
@@ -19,22 +19,45 @@ package dao
 
 import (
 	"context"
+	"errors"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"

Review comment:
       dao层不该依赖cache




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608389983



##########
File path: datasource/mongo/client/dao/rule.go
##########
@@ -29,6 +32,32 @@ import (
 	"github.com/apache/servicecomb-service-center/pkg/log"
 )
 
+func GetRulesByServiceID(ctx context.Context, serviceID string) ([]*model.Rule, error) {
+	cacheRes := sd.Store().Rule().Cache().GetValue(serviceID)
+	cacheRules, ok := processCacheRules(cacheRes)
+	if !ok || len(cacheRules) == 0 {
+		return GetRules(ctx, mutil.NewDomainProjectFilter(util.ParseDomain(ctx), util.ParseDomain(ctx), mutil.ServiceID(serviceID)))
+	}
+	return cacheRules, nil
+}
+
+func processCacheRules(cacheRules []interface{}) ([]*model.Rule, bool) {
+	res := make([]*model.Rule, 0, len(cacheRules))
+	for _, v := range cacheRules {
+		t, ok := v.(model.Rule)

Review comment:
       这里判断其实很频繁,封一个统一的cache API吧 参考下go chassis https://github.com/go-chassis/go-chassis/commit/6f8d8843fabdec93d8fd633ffe4e2b64314d1329




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608384265



##########
File path: datasource/mongo/client/dao/dep.go
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dao
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/datasource"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+	mutil "github.com/apache/servicecomb-service-center/datasource/mongo/util"
+	"github.com/apache/servicecomb-service-center/pkg/util"
+	"github.com/go-chassis/cari/discovery"
+)
+
+const (
+	p = "p"
+	c = "c"
+)
+
+func GetProviderServiceOfDeps(ctx context.Context, provider *discovery.MicroService) (*discovery.MicroServiceDependency, error) {
+	res := sd.Store().Dep().Cache().GetValue(genDepserivceKey(p, provider))
+	cacheServiceKeys, ok := processCacheDep(res)
+	if !ok || len(cacheServiceKeys) == 0 {
+		return GetServiceofDepsFromDB(ctx, p, provider)
+	}
+	return cacheServiceKeys[0], nil
+}
+
+func processCacheDep(cache []interface{}) ([]*discovery.MicroServiceDependency, bool) {

Review comment:
       这类方法都放到工具pkg




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608315330



##########
File path: datasource/mongo/client/dao/dep.go
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dao
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/datasource"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+	mutil "github.com/apache/servicecomb-service-center/datasource/mongo/util"
+	"github.com/apache/servicecomb-service-center/pkg/util"
+	"github.com/go-chassis/cari/discovery"
+)
+
+const (
+	p = "p"
+	c = "c"
+)
+
+func GetProviderServiceOfDeps(ctx context.Context, provider *discovery.MicroService) (*discovery.MicroServiceDependency, error) {
+	res := sd.Store().Dep().Cache().GetValue(genDepserivceKey(p, provider))
+	cacheServiceKeys, ok := processCacheDep(res)
+	if !ok || len(cacheServiceKeys) == 0 {
+		return GetServiceofDepsFromDB(ctx, p, provider)
+	}
+	return cacheServiceKeys[0], nil
+}
+
+func processCacheDep(cache []interface{}) ([]*discovery.MicroServiceDependency, bool) {
+	res := make([]*discovery.MicroServiceDependency, 0, len(cache))
+	for _, v := range cache {
+		t, ok := v.(model.DependencyRule)
+		if !ok {
+			return nil, false
+		}
+		res = append(res, t.Dep)
+	}
+	return res, true
+}
+
+func GetServiceofDepsFromDB(ctx context.Context, ruleType string, provider *discovery.MicroService) (*discovery.MicroServiceDependency, error) {
+	filter := mutil.NewFilter(
+		mutil.ServiceType(ruleType),
+		mutil.ServiceKeyTenant(util.ParseDomainProject(ctx)),
+		mutil.ServiceKeyAppID(provider.AppId),
+		mutil.ServiceKeyServiceName(provider.ServiceName),
+		mutil.ServiceKeyServiceVersion(provider.Version),
+	)
+	depRule, err := getDeps(ctx, filter)
+	if err != nil {
+		return nil, err
+	}
+	return depRule.Dep, nil
+}
+
+func genDepserivceKey(ruleType string, service *discovery.MicroService) string {
+	return util.StringJoin([]string{ruleType, service.AppId, service.ServiceName, service.Version}, "/")

Review comment:
       这个util包里的方法没有意义,go明明自带这个func,难道有什么特别的优势,没有就干掉吧




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r612087944



##########
File path: datasource/mongo/cache/ms_cache.go
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except request compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to request writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cache
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"

Review comment:
       如果sd下的cache是通用的,那么都要move到一个中立的文件夹内,表示是通用的而不是放在mongo包,
   另外此文件同理




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] DFSOrange closed pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
DFSOrange closed pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608315330



##########
File path: datasource/mongo/client/dao/dep.go
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dao
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/datasource"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+	mutil "github.com/apache/servicecomb-service-center/datasource/mongo/util"
+	"github.com/apache/servicecomb-service-center/pkg/util"
+	"github.com/go-chassis/cari/discovery"
+)
+
+const (
+	p = "p"
+	c = "c"
+)
+
+func GetProviderServiceOfDeps(ctx context.Context, provider *discovery.MicroService) (*discovery.MicroServiceDependency, error) {
+	res := sd.Store().Dep().Cache().GetValue(genDepserivceKey(p, provider))
+	cacheServiceKeys, ok := processCacheDep(res)
+	if !ok || len(cacheServiceKeys) == 0 {
+		return GetServiceofDepsFromDB(ctx, p, provider)
+	}
+	return cacheServiceKeys[0], nil
+}
+
+func processCacheDep(cache []interface{}) ([]*discovery.MicroServiceDependency, bool) {
+	res := make([]*discovery.MicroServiceDependency, 0, len(cache))
+	for _, v := range cache {
+		t, ok := v.(model.DependencyRule)
+		if !ok {
+			return nil, false
+		}
+		res = append(res, t.Dep)
+	}
+	return res, true
+}
+
+func GetServiceofDepsFromDB(ctx context.Context, ruleType string, provider *discovery.MicroService) (*discovery.MicroServiceDependency, error) {
+	filter := mutil.NewFilter(
+		mutil.ServiceType(ruleType),
+		mutil.ServiceKeyTenant(util.ParseDomainProject(ctx)),
+		mutil.ServiceKeyAppID(provider.AppId),
+		mutil.ServiceKeyServiceName(provider.ServiceName),
+		mutil.ServiceKeyServiceVersion(provider.Version),
+	)
+	depRule, err := getDeps(ctx, filter)
+	if err != nil {
+		return nil, err
+	}
+	return depRule.Dep, nil
+}
+
+func genDepserivceKey(ruleType string, service *discovery.MicroService) string {
+	return util.StringJoin([]string{ruleType, service.AppId, service.ServiceName, service.Version}, "/")

Review comment:
       这个util包里的方法没有意义,go自带这个func,没有什么特别的优势就干掉吧




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608316136



##########
File path: datasource/mongo/client/dao/microservice.go
##########
@@ -44,6 +67,60 @@ func GetService(ctx context.Context, filter interface{}, opts ...*options.FindOn
 	return svc, nil
 }
 
+func getServiceIDFromDB(ctx context.Context, key *discovery.MicroServiceKey) (string, error) {

Review comment:
       没必要加FromDB吧,难道有FromCache?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#issuecomment-811671577


   描述详细的设计思路和更改点


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on pull request #911: restructure cache

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#issuecomment-806291417


   标题写WIP


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] DFSOrange commented on a change in pull request #911: [SCB-2094]restructure cache

Posted by GitBox <gi...@apache.org>.
DFSOrange commented on a change in pull request #911:
URL: https://github.com/apache/servicecomb-service-center/pull/911#discussion_r612236854



##########
File path: datasource/mongo/cache/ms_cache.go
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except request compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to request writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cache
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
+	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"

Review comment:
       > 如果sd下的cache是通用的,那么都要move到一个中立的文件夹内,表示是通用的而不是放在mongo包,
   > 另外此文件同理
   
   已修改文件位置




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org