Merge pull request #14372 from ioito/hotfix/qx-tag-lock

fix(region): 避免加锁导致设置标签超时
This commit is contained in:
Zexi Li
2022-06-02 10:20:40 +08:00
committed by GitHub
2 changed files with 4 additions and 7 deletions
-7
View File
@@ -22,8 +22,6 @@ import (
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
)
const (
@@ -40,11 +38,6 @@ func (t TagsUpdateInfo) IsChanged() bool {
}
func SetTags(ctx context.Context, res ICloudResource, managerId string, tags map[string]string, replace bool) error {
// 避免同时设置多个资源标签出现以下错误
// Code=ResourceInUse.TagDuplicate, Message=tagKey-tagValue have exists., RequestId=e87714c0-e50b-4241-b79d-32897437174d
lockman.LockRawObject(ctx, SET_TAGS, managerId)
defer lockman.ReleaseRawObject(ctx, SET_TAGS, managerId)
err := res.SetTags(tags, replace)
if err != nil {
return errors.Wrapf(err, "SetTags")
+4
View File
@@ -19,6 +19,7 @@ import (
"strconv"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
sdkerrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
@@ -183,6 +184,9 @@ func (region *SRegion) createTag(key, value string) error {
apiName := "CreateTag"
_, err := region.client.tagRequest(apiName, params)
if err != nil {
if e, ok := errors.Cause(err).(*sdkerrors.TencentCloudSDKError); ok && e.Code == "ResourceInUse.TagDuplicate" {
return nil
}
return errors.Wrap(err, apiName)
}
return nil