Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (s *VisibilityStore) countGroupByWorkflowExecutions(
termsAgg,
)
if err != nil {
return nil, err
return nil, ConvertElasticsearchClientError("CountWorkflowExecutions failed", err)
}
return s.parseCountGroupByResponse(esResponse, groupByFields)
}
Expand Down Expand Up @@ -1154,14 +1154,19 @@ func finishParseJSONValue(val interface{}, t enumspb.IndexedValueType) (interfac

func ConvertElasticsearchClientError(message string, err error) error {
errMessage := fmt.Sprintf("%s: %s", message, detailedErrorMessage(err))
switch e := err.(type) {
case *elastic.Error:
switch e.Status {
var elasticErr *elastic.Error
switch {
case errors.As(err, &elasticErr):
switch elasticErr.Status {
case 400: // BadRequest
// Returning InvalidArgument error will prevent retry on a caller side.
return serviceerror.NewInvalidArgument(errMessage)
}
return serviceerror.NewUnavailable(errMessage)
case errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded):
return fmt.Errorf("%s: %w", message, err)
}

return serviceerror.NewUnavailable(errMessage)
}

Expand Down
27 changes: 14 additions & 13 deletions common/persistence/visibility/store/sql/visibility_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func (s *VisibilityStore) GetName() string {
return s.sqlStore.GetName()
}

func convertSQLError(message string, err error) error {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("%s: %w", message, err)
}
return serviceerror.NewUnavailable(fmt.Sprintf("%s: %v", message, err))
}

func (s *VisibilityStore) GetIndexName() string {
return s.sqlStore.GetDbName()
}
Expand Down Expand Up @@ -160,7 +167,7 @@ func (s *VisibilityStore) DeleteWorkflowExecution(
RunID: request.RunID,
})
if err != nil {
return serviceerror.NewUnavailable(err.Error())
return convertSQLError("DeleteWorkflowExecution operation failed.", err)
}
return nil
}
Expand Down Expand Up @@ -225,8 +232,7 @@ func (s *VisibilityStore) listWorkflowExecutions(

rows, err := s.sqlStore.DB.SelectFromVisibility(ctx, *selectFilter)
if err != nil {
return nil, serviceerror.NewUnavailable(
fmt.Sprintf("ListWorkflowExecutions operation failed. Select failed: %v", err))
return nil, convertSQLError("ListWorkflowExecutions operation failed.", err)
}
if len(rows) == 0 {
return &store.InternalListWorkflowExecutionsResponse{}, nil
Expand Down Expand Up @@ -296,8 +302,7 @@ func (s *VisibilityStore) listWorkflowExecutionsLegacy(

rows, err := s.sqlStore.DB.SelectFromVisibility(ctx, *selectFilter)
if err != nil {
return nil, serviceerror.NewUnavailable(
fmt.Sprintf("ListWorkflowExecutions operation failed. Select failed: %v", err))
return nil, convertSQLError("ListWorkflowExecutions operation failed.", err)
}
if len(rows) == 0 {
return &store.InternalListWorkflowExecutionsResponse{}, nil
Expand Down Expand Up @@ -381,8 +386,7 @@ func (s *VisibilityStore) countWorkflowExecutionsLegacy(

count, err := s.sqlStore.DB.CountFromVisibility(ctx, *selectFilter)
if err != nil {
return nil, serviceerror.NewUnavailable(
fmt.Sprintf("CountWorkflowExecutions operation failed. Query failed: %v", err))
return nil, convertSQLError("CountWorkflowExecutions operation failed.", err)
}

return &manager.CountWorkflowExecutionsResponse{Count: count}, nil
Expand Down Expand Up @@ -443,8 +447,7 @@ func (s *VisibilityStore) countWorkflowExecutions(

count, err := s.sqlStore.DB.CountFromVisibility(ctx, *selectFilter)
if err != nil {
return nil, serviceerror.NewUnavailable(
fmt.Sprintf("CountWorkflowExecutions operation failed. Query failed: %v", err))
return nil, convertSQLError("CountWorkflowExecutions operation failed.", err)
}

return &manager.CountWorkflowExecutionsResponse{Count: count}, nil
Expand All @@ -469,8 +472,7 @@ func (s *VisibilityStore) countGroupByWorkflowExecutions(

rows, err := s.sqlStore.DB.CountGroupByFromVisibility(ctx, *selectFilter)
if err != nil {
return nil, serviceerror.NewUnavailable(
fmt.Sprintf("CountWorkflowExecutions operation failed. Query failed: %v", err))
return nil, convertSQLError("CountWorkflowExecutions operation failed.", err)
}
resp := &manager.CountWorkflowExecutionsResponse{
Count: 0,
Expand Down Expand Up @@ -505,8 +507,7 @@ func (s *VisibilityStore) GetWorkflowExecution(
RunID: request.RunID,
})
if err != nil {
return nil, serviceerror.NewUnavailable(
fmt.Sprintf("GetWorkflowExecution operation failed. Select failed: %v", err))
return nil, convertSQLError("GetWorkflowExecution operation failed.", err)
}
info, err := s.rowToInfo(row, request.Namespace)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/retry.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ It's important to note that a special retry policy is used for `ResourceExhauste

## Service Error

Service errors are specific Go errors that can generate a gRCP `Status` (see [status.proto](https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto)).
Service errors are specific Go errors that can generate a gRPC `Status` (see [status.proto](https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto)).
A gRPC status contains a gRPC `Code` (see [code.proto](https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto)), a message and (optionally) a payload with more details.

```go
Expand Down
Loading