Skip to content

Commit

Permalink
Merge pull request #17985 from ioito/hotfix/qx-tenantcache-metadata
Browse files Browse the repository at this point in the history
fix(region): clean tenantcache metadata
  • Loading branch information
zexi authored Sep 12, 2023
2 parents baf8742 + 44f8f75 commit cbf33bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 8 additions & 0 deletions pkg/cloudcommon/db/tenantcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions pkg/cloudcommon/db/tenantcacheitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudcommon/db/tenantcachesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down Expand Up @@ -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++
Expand Down

0 comments on commit cbf33bb

Please sign in to comment.