From 44f8f75203d46af3e21e473f1c882772f931d1c9 Mon Sep 17 00:00:00 2001 From: ioito Date: Mon, 11 Sep 2023 15:19:16 +0800 Subject: [PATCH] fix(region): clean tenantcache metadata --- pkg/cloudcommon/db/tenantcache.go | 8 ++++++++ pkg/cloudcommon/db/tenantcacheitem.go | 11 ++++++----- pkg/cloudcommon/db/tenantcachesync.go | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/cloudcommon/db/tenantcache.go b/pkg/cloudcommon/db/tenantcache.go index b38c4de441e..bba92d994f1 100644 --- a/pkg/cloudcommon/db/tenantcache.go +++ b/pkg/cloudcommon/db/tenantcache.go @@ -336,6 +336,14 @@ func (manager *STenantCacheManager) Save(ctx context.Context, item SCachedTenant log.Errorf("FetchTenantbyId fail %s", err) return nil, errors.Wrapf(err, "TenantCache FetchById %s", item.Id) } + // clean cache metadata + if item.PendingDeleted && saveMeta { + for k := range item.Metadata { + if strings.HasPrefix(k, USER_TAG_PREFIX) { + item.Metadata[k] = "none" + } + } + } now := time.Now().UTC() if err == nil { obj := objo.(*STenant) diff --git a/pkg/cloudcommon/db/tenantcacheitem.go b/pkg/cloudcommon/db/tenantcacheitem.go index 7975bc97a32..1e2e95cb63e 100644 --- a/pkg/cloudcommon/db/tenantcacheitem.go +++ b/pkg/cloudcommon/db/tenantcacheitem.go @@ -17,11 +17,12 @@ package db import identityapi "yunion.io/x/onecloud/pkg/apis/identity" type SCachedTenant struct { - Id string `json:"id"` - Name string `json:"name"` - DomainId string `json:"domain_id"` - ProjectDomain string `json:"project_domain"` - Metadata map[string]string `json:"metadata"` + Id string `json:"id"` + Name string `json:"name"` + DomainId string `json:"domain_id"` + ProjectDomain string `json:"project_domain"` + Metadata map[string]string `json:"metadata"` + PendingDeleted bool `json:"pending_deleted"` } func (s SCachedTenant) objType() string { diff --git a/pkg/cloudcommon/db/tenantcachesync.go b/pkg/cloudcommon/db/tenantcachesync.go index 726869de4fa..c7bb3b8d050 100644 --- a/pkg/cloudcommon/db/tenantcachesync.go +++ b/pkg/cloudcommon/db/tenantcachesync.go @@ -123,7 +123,7 @@ func syncProjects(ctx context.Context) error { // update project cache item := SCachedTenant{} err := results.Data[i].Unmarshal(&item) - if err != nil { + if err == nil { TenantCacheManager.Save(ctx, item, true) } offset++ @@ -152,7 +152,7 @@ func syncUsers(ctx context.Context) error { // update user cache item := SCachedUser{} err := results.Data[i].Unmarshal(&item) - if err != nil { + if err == nil { UserCacheManager.Save(ctx, item.Id, item.Name, item.DomainId, item.ProjectDomain, item.Lang) } offset++