From f105b2ed04b081bbcdd8f29a488eeb85981efa69 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Mon, 27 Feb 2023 18:09:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=B8=85=E7=90=86=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=93=8D=E4=BD=9C=E5=90=88=E5=B9=B6=E5=88=B0?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E5=B1=82=E4=BA=8B=E5=8A=A1=E4=B8=AD=20(#957)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix:存储层出现问题可能导致cache数据更新阻塞 * fix:存储层出现问题可能导致cache数据更新阻塞 * fix:存储层出现问题可能导致cache数据更新阻塞 * fix:存储层出现问题可能导致cache数据更新阻塞 * store:清理服务信息纳入事务管理 --- store/sqldb/service.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/store/sqldb/service.go b/store/sqldb/service.go index e5756b9f5..9bcf1fb2c 100644 --- a/store/sqldb/service.go +++ b/store/sqldb/service.go @@ -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) }) @@ -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 { @@ -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