Skip to content

Commit

Permalink
backend/oss: Ignore the getting oss endpoint error and using string c…
Browse files Browse the repository at this point in the history
…oncat instead; Improves the error message level
  • Loading branch information
xiaozhu36 committed Nov 28, 2022
1 parent ec6451a commit d44474e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 7 additions & 6 deletions internal/backend/remote-state/oss/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,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 == "" {
Expand Down
13 changes: 5 additions & 8 deletions internal/backend/remote-state/oss/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d44474e

Please sign in to comment.