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/04/19 02:42:54 UTC

[GitHub] [servicecomb-service-center] robotLJW commented on a change in pull request #953: SCB-2094 Fast register with mongo

robotLJW commented on a change in pull request #953:
URL: https://github.com/apache/servicecomb-service-center/pull/953#discussion_r615507761



##########
File path: datasource/mongo/fast_register_inst_service.go
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 mongo
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/server/config"
+
+	"github.com/go-chassis/cari/discovery"
+)
+
+var isFastRegisterEnabled bool
+
+var fastRegisterInstanceService *RegisterFastInstanceService
+
+type RegisterFastInstanceService struct {
+	InstEventCh  chan *InstanceRegisterEvent
+	FailedInstCh chan *InstanceRegisterEvent
+}
+
+type InstanceRegisterEvent struct {
+	Ctx        context.Context
+	Request    *discovery.RegisterInstanceRequest
+	isCustomID bool
+	failedTime int
+}
+
+func NewFastRegisterInstanceService() *RegisterFastInstanceService {

Review comment:
       https://github.com/apache/servicecomb-service-center/blob/master/datasource/etcd/config.go
   可以参考下这个写法,其实这个配置按理应该初始化一次就行

##########
File path: datasource/mongo/fast_register_timer.go
##########
@@ -0,0 +1,165 @@
+/*
+ * 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 mongo
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"github.com/apache/servicecomb-service-center/pkg/gopool"
+	"github.com/apache/servicecomb-service-center/pkg/log"
+	"runtime"
+	"time"
+)
+
+const (
+	loopTime              = 100
+	batchLen              = 10000
+	fuseMinCount          = 3
+	fuseTime              = 1000
+	maxRegisterFailedTime = 500
+)
+
+var fastRegisterTimer *FastRegisterTimer
+
+func NewRegisterTimer() *FastRegisterTimer {

Review comment:
       Newxxx  位置放到 type FastRegisterTimer struct {  后面更合适,见uber_go_guide_cn#函数名规范
   
   https://github.com/xxjwxc/uber_go_guide_cn#%E5%87%BD%E6%95%B0%E5%90%8D

##########
File path: datasource/mongo/fast_register_inst_service.go
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 mongo
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/server/config"
+
+	"github.com/go-chassis/cari/discovery"
+)
+
+var isFastRegisterEnabled bool
+
+var fastRegisterInstanceService *RegisterFastInstanceService
+
+type RegisterFastInstanceService struct {

Review comment:
       我上次记得华哥说个一个.go文件最好只包含一个struct,其他的应该放到types里面会比较好,我之前心跳的一个struct也抽到types里面
   https://github.com/robotLJW/servicecomb-service-center/blob/6a75041291c9b75f4c8d09a918c7b1efc158cf33/datasource/mongo/heartbeat/cache/types.go




-- 
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