Skip to content

Commit

Permalink
fix:清理服务信息操作合并到存储层事务中 (#957)
Browse files Browse the repository at this point in the history
* fix:存储层出现问题可能导致cache数据更新阻塞

* fix:存储层出现问题可能导致cache数据更新阻塞

* fix:存储层出现问题可能导致cache数据更新阻塞

* fix:存储层出现问题可能导致cache数据更新阻塞

* store:清理服务信息纳入事务管理
  • Loading branch information
chuntaojun authored Feb 27, 2023
1 parent ef59f23 commit f105b2e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions store/sqldb/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ func (ss *serviceStore) AddService(s *model.Service) error {
"add service missing some params, id is %s, name is %s, namespace is %s", s.ID, s.Name, s.Namespace))
}

// 先清理无效数据
if err := ss.cleanService(s.Name, s.Namespace); err != nil {
return err
}

err := RetryTransaction("addService", func() error {
return ss.addService(s)
})
Expand All @@ -64,6 +59,11 @@ func (ss *serviceStore) addService(s *model.Service) error {
}
}()

// 先清理无效数据
if err := ss.cleanService(tx, s.Name, s.Namespace); err != nil {
return err
}

// 锁namespace
namespace, err := rlockNamespace(tx.QueryRow, s.Namespace)
if err != nil {
Expand Down Expand Up @@ -728,10 +728,10 @@ func (ss *serviceStore) getServiceByID(serviceID string) (*model.Service, error)

// cleanService 清理无效数据,flag=1的数据
// 只需要删除service即可
func (ss *serviceStore) cleanService(name string, namespace string) error {
func (ss *serviceStore) cleanService(tx *BaseTx, name string, namespace string) error {
log.Infof("[Store][database] clean service(%s, %s)", name, namespace)
str := "delete from service where name = ? and namespace = ? and flag = 1"
_, err := ss.master.Exec(str, name, namespace)
_, err := tx.Exec(str, name, namespace)
if err != nil {
log.Errorf("[Store][database] clean service(%s, %s) err: %s", name, namespace, err.Error())
return err
Expand Down

0 comments on commit f105b2e

Please sign in to comment.