From ec62ca1b7078b501cd090a0fcebaa2476c87aa65 Mon Sep 17 00:00:00 2001 From: xiaozhu36 Date: Sun, 4 Dec 2022 11:51:29 +0800 Subject: [PATCH] backend/oss: Ignore the getting oss endpoint error and using string concat instead; Improves the error message level --- internal/backend/remote-state/oss/backend.go | 16 +++++++++------- internal/backend/remote-state/oss/client.go | 13 +++++-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/internal/backend/remote-state/oss/backend.go b/internal/backend/remote-state/oss/backend.go index 2d488ce14c..468a883298 100644 --- a/internal/backend/remote-state/oss/backend.go +++ b/internal/backend/remote-state/oss/backend.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints" "io/ioutil" "log" "net/http" @@ -16,6 +15,8 @@ import ( "strings" "time" + "github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints" + "github.com/aliyun/alibaba-cloud-sdk-go/sdk" "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" @@ -379,12 +380,13 @@ func (b *Backend) configure(ctx context.Context) error { if endpoint == "" { endpointsResponse, err := b.getOSSEndpointByRegion(accessKey, secretKey, securityToken, region) if err != nil { - return err - } - for _, endpointItem := range endpointsResponse.Endpoints.Endpoint { - if endpointItem.Type == "openAPI" { - endpoint = endpointItem.Endpoint - break + log.Printf("[WARN] getting oss endpoint failed and using oss-%s.aliyuncs.com instead. Error: %#v.", region, err) + } else { + for _, endpointItem := range endpointsResponse.Endpoints.Endpoint { + if endpointItem.Type == "openAPI" { + endpoint = endpointItem.Endpoint + break + } } } if endpoint == "" { diff --git a/internal/backend/remote-state/oss/client.go b/internal/backend/remote-state/oss/client.go index 78d835ae13..0c2938d0e6 100644 --- a/internal/backend/remote-state/oss/client.go +++ b/internal/backend/remote-state/oss/client.go @@ -180,23 +180,22 @@ func (c *RemoteClient) Lock(info *statemgr.LockInfo) (string, error) { }, } - log.Printf("[DEBUG] Recording state lock in tablestore: %#v", putParams) + log.Printf("[DEBUG] Recording state lock in tablestore: %#v; LOCKID:%s", putParams, c.lockPath()) _, err := c.otsClient.PutRow(&tablestore.PutRowRequest{ PutRowChange: putParams, }) if err != nil { - log.Printf("[WARN] Error storing state lock in tablestore: %#v", err) + err = fmt.Errorf("invoking PutRow got an error: %#v", err) lockInfo, infoErr := c.getLockInfo() if infoErr != nil { - log.Printf("[WARN] Error getting lock info: %#v", err) - err = multierror.Append(err, infoErr) + err = multierror.Append(err, fmt.Errorf("\ngetting lock info got an error: %#v", infoErr)) } lockErr := &statemgr.LockError{ Err: err, Info: lockInfo, } - log.Printf("[WARN] state lock error: %#v", lockErr) + log.Printf("[ERROR] state lock error: %s", lockErr.Error()) return "", lockErr } @@ -386,13 +385,11 @@ func (c *RemoteClient) Unlock(id string) error { }, }, Condition: &tablestore.RowCondition{ - RowExistenceExpectation: tablestore.RowExistenceExpectation_EXPECT_EXIST, + RowExistenceExpectation: tablestore.RowExistenceExpectation_IGNORE, }, }, } - log.Printf("[DEBUG] Deleting state lock from tablestore: %#v", params) - _, err = c.otsClient.DeleteRow(params) if err != nil {