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 2022/01/11 11:30:23 UTC

[GitHub] [servicecomb-service-center] xiaoluoluo opened a new pull request #1214: [feat] add syncer delete expire tombstone data

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


   【issue】#1212
   【修改内容】:增加定时器,定时删除 墓碑数据
   【修改原因】:过期的墓碑数据需要删除
   【影响范围】:无
   【额外说明】:无
   【测试用例】:无


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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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



[GitHub] [servicecomb-service-center] little-cui merged pull request #1214: [feat] add syncer delete expire tombstone data

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


   


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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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



[GitHub] [servicecomb-service-center] robotLJW commented on a change in pull request #1214: [feat] add syncer delete expire tombstone data

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



##########
File path: syncer/service/tombstone/tombstone_test.go
##########
@@ -0,0 +1,92 @@
+/*
+ * 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 tombstone

Review comment:
       测试用例的包名还是改成xxx_test




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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1214: [feat] add syncer delete expire tombstone data

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



##########
File path: syncer/service/tombstone/tombstone.go
##########
@@ -0,0 +1,72 @@
+/*
+ * 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 tombstone
+
+import (
+	"context"
+	"fmt"
+	"time"
+
+	"github.com/apache/servicecomb-service-center/eventbase/model"
+	"github.com/apache/servicecomb-service-center/eventbase/service/tombstone"
+	"github.com/apache/servicecomb-service-center/pkg/log"
+	"github.com/apache/servicecomb-service-center/server/config"
+)
+
+const (
+	defaultExpireTime = time.Hour * 24
+)
+
+func DeleteExpireTombStone() error {
+	expireTime := getExpireTime()
+	request := &model.ListTombstoneRequest{
+		BeforeTimestamp: time.Now().Add(-expireTime).UnixNano(),
+	}
+	tombstones, err := tombstone.List(context.Background(), request)
+	if err != nil {
+		log.Error("get tombstone list fail", err)
+		return err
+	}
+
+	if len(tombstones) <= 0 {
+		log.Info("expire tombstone data is empty")
+		return nil
+	}
+
+	err = tombstone.Delete(context.Background(), tombstones...)
+	if err != nil {
+		log.Error("delete tombstone data list fail", err)
+		return err
+	}
+	return nil
+}
+
+func getExpireTime() time.Duration {
+	reserve := config.GetString("sync.tombstone.retire.reserve", "")
+	if len(reserve) <= 0 {
+		log.Warn("tombstone expireTime is empty")

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.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1214: [feat] add syncer delete expire tombstone data

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



##########
File path: syncer/config/config.go
##########
@@ -44,6 +45,11 @@ type Peer struct {
 	Mode      []string `yaml:"mode"`
 }
 
+type Tombstone struct {
+	Cron       string `yaml:"cron"`
+	ExpireTime string `yaml:"expireTime"`
+}

Review comment:
       不需要定义对象,直接config.GetXXX获取




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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1214: [feat] add syncer delete expire tombstone data

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



##########
File path: syncer/service/tombstone/tombstone_test.go
##########
@@ -0,0 +1,92 @@
+/*
+ * 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 tombstone
+
+import (
+	"context"
+	"testing"
+	"time"
+
+	"github.com/apache/servicecomb-service-center/eventbase/datasource"
+	"github.com/apache/servicecomb-service-center/eventbase/model"
+	"github.com/apache/servicecomb-service-center/eventbase/service/tombstone"
+	"github.com/apache/servicecomb-service-center/eventbase/test"
+	"github.com/go-chassis/cari/sync"
+	"github.com/stretchr/testify/assert"
+)
+
+func init() {
+	err := datasource.Init(test.DbCfg)
+	if err != nil {
+		panic(err)
+	}
+}
+
+const (
+	testDomain  = "expireTombstone"
+	testProject = "expireProject"
+)
+
+func TestDeleteExpireTombStone(t *testing.T) {
+	tombstoneOne := sync.NewTombstone(testDomain, testProject, "config", "1")
+	tombstoneOne.Timestamp = time.Now().Add(-time.Hour * 24).UnixNano()
+
+	tombstoneTwo := sync.NewTombstone(testDomain, testProject, "config", "2")
+	tombstoneTwo.Timestamp = time.Now().Add(-time.Hour * 23).UnixNano()
+
+	tombstoneThree := sync.NewTombstone(testDomain, testProject, "config", "3")
+	tombstoneThree.Timestamp = time.Now().Add(-time.Hour * 25).UnixNano()
+
+	t.Run("to create three tasks for next get delete and list operations, should pass", func(t *testing.T) {
+		_, err := datasource.GetDataSource().TombstoneDao().Create(context.Background(), tombstoneOne)
+		assert.Nil(t, err)
+		_, err = datasource.GetDataSource().TombstoneDao().Create(context.Background(), tombstoneTwo)
+		assert.Nil(t, err)
+		_, err = datasource.GetDataSource().TombstoneDao().Create(context.Background(), tombstoneThree)
+		assert.Nil(t, err)

Review comment:
       这里忘记清理测试用例数据

##########
File path: etc/conf/syncer.yaml
##########
@@ -1,5 +1,9 @@
 sync:
   enableOnStart: true
+  tombstone:

Review comment:
       ```yaml
   tombstone:
     retire:
       cron: ''
       reserve: 24h
   ```

##########
File path: syncer/service/tombstone/tombstone.go
##########
@@ -0,0 +1,78 @@
+/*
+ * 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 tombstone
+
+import (
+	"context"
+	"fmt"
+	"time"
+
+	"github.com/apache/servicecomb-service-center/eventbase/model"
+	"github.com/apache/servicecomb-service-center/eventbase/service/tombstone"
+	"github.com/apache/servicecomb-service-center/pkg/log"
+	"github.com/apache/servicecomb-service-center/syncer/config"
+)
+
+const (
+	defaultExpireTime = time.Hour * 24
+)
+
+func DeleteExpireTombStone() error {
+	expireTime := getExpireTime()
+	request := &model.ListTombstoneRequest{
+		BeforeTimestamp: time.Now().Add(-expireTime).UnixNano(),
+	}
+	tombstones, err := tombstone.List(context.Background(), request)
+	if err != nil {
+		log.Error("get tombstone list fail", err)
+		return err
+	}
+
+	if len(tombstones) <= 0 {
+		log.Info("expire tombstone data is empty")
+		return nil
+	}
+
+	err = tombstone.Delete(context.Background(), tombstones...)
+	if err != nil {
+		log.Error("delete tombstone data list fail", err)
+		return err
+	}
+	return nil
+}
+
+func getExpireTime() time.Duration {
+	config := config.GetConfig()

Review comment:
       变量名跟包名冲突,建议用cfg




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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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