Skip to content

Commit

Permalink
Merge branch 'master' into ci
Browse files Browse the repository at this point in the history
  • Loading branch information
shijiesheng authored Jul 18, 2022
2 parents fb56714 + b0d1f06 commit d95db4e
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/metrics/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,7 @@ const (
PersistenceErrExecutionAlreadyStartedCounter
PersistenceErrDomainAlreadyExistsCounter
PersistenceErrBadRequestCounter
PersistenceErrDBUnavailableCounter
PersistenceSampledCounter
PersistenceEmptyResponseCounter

Expand Down Expand Up @@ -2349,6 +2350,7 @@ var MetricDefs = map[ServiceIdx]map[int]metricDefinition{
PersistenceErrExecutionAlreadyStartedCounter: {metricName: "persistence_errors_execution_already_started", metricType: Counter},
PersistenceErrDomainAlreadyExistsCounter: {metricName: "persistence_errors_domain_already_exists", metricType: Counter},
PersistenceErrBadRequestCounter: {metricName: "persistence_errors_bad_request", metricType: Counter},
PersistenceErrDBUnavailableCounter: {metricName: "persistence_errors_db_unavailable", metricType: Counter},
PersistenceSampledCounter: {metricName: "persistence_sampled", metricType: Counter},
PersistenceEmptyResponseCounter: {metricName: "persistence_empty_response", metricType: Counter},
CadenceClientRequests: {metricName: "cadence_client_requests", metricType: Counter},
Expand Down
9 changes: 9 additions & 0 deletions common/persistence/dataManagerInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ type (
Msg string
}

// DBUnavailableError is returned when the database is unavailable, could be for various reasons.
DBUnavailableError struct {
Msg string
}

// TransactionSizeLimitError is returned when the transaction size is too large
TransactionSizeLimitError struct {
Msg string
Expand Down Expand Up @@ -1862,6 +1867,10 @@ func (e *TimeoutError) Error() string {
return e.Msg
}

func (e *DBUnavailableError) Error() string {
return e.Msg
}

func (e *TransactionSizeLimitError) Error() string {
return e.Msg
}
Expand Down
4 changes: 4 additions & 0 deletions common/persistence/nosql/nosqlplugin/cassandra/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ func (db *cdb) IsTimeoutError(err error) bool {
func (db *cdb) IsThrottlingError(err error) bool {
return db.client.IsThrottlingError(err)
}

func (db *cdb) IsDBUnavailableError(err error) bool {
return db.client.IsDBUnavailableError(err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package public

import (
"context"
"strings"

gogocql "github.com/gocql/gocql"

Expand Down Expand Up @@ -70,3 +71,16 @@ func (c client) IsThrottlingError(err error) bool {
}
return false
}

func (c client) IsDBUnavailableError(err error) bool {
if req, ok := err.(gogocql.RequestError); ok {
// 0x1000 == UNAVAILABLE
if req.Code() != 0x1000 {
return false
}
if strings.Contains(req.Message(), "Cannot perform LWT operation") {
return true
}
}
return false
}
4 changes: 4 additions & 0 deletions common/persistence/nosql/nosqlplugin/dynamodb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (db *ddb) IsThrottlingError(err error) bool {
panic("TODO")
}

func (db *ddb) IsDBUnavailableError(err error) bool {
panic("TODO")
}

func (db *ddb) IsConditionFailedError(err error) bool {
return err == errConditionFailed
}
1 change: 1 addition & 0 deletions common/persistence/nosql/nosqlplugin/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type (
IsTimeoutError(error) bool
IsNotFoundError(error) bool
IsThrottlingError(error) bool
IsDBUnavailableError(error) bool
}

/**
Expand Down
4 changes: 4 additions & 0 deletions common/persistence/nosql/nosqlplugin/mongodb/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ func (db *mdb) IsTimeoutError(err error) bool {
func (db *mdb) IsThrottlingError(err error) bool {
return false
}

func (db *mdb) IsDBUnavailableError(err error) bool {
return false
}
6 changes: 6 additions & 0 deletions common/persistence/nosql/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func convertCommonErrors(
}
}

if errChecker.IsDBUnavailableError(err) {
return &p.DBUnavailableError{
Msg: fmt.Sprintf("#{operation} operation failed. Error: #{err}"),
}
}

return &types.InternalServiceError{
Message: fmt.Sprintf("%v operation failed. Error: %v", operation, err),
}
Expand Down
4 changes: 4 additions & 0 deletions common/persistence/persistenceMetricClients.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ func (p *persistenceMetricsClientBase) updateErrorMetric(scope int, err error) {
case *types.ServiceBusyError:
p.metricClient.IncCounter(scope, metrics.PersistenceErrBusyCounter)
p.metricClient.IncCounter(scope, metrics.PersistenceFailures)
case *DBUnavailableError:
p.metricClient.IncCounter(scope, metrics.PersistenceErrDBUnavailableCounter)
p.metricClient.IncCounter(scope, metrics.PersistenceFailures)
p.logger.Error("DBUnavailable Error:", tag.Error(err), tag.MetricScope(scope))
default:
p.logger.Error("Operation failed with internal error.", tag.Error(err), tag.MetricScope(scope))
p.metricClient.IncCounter(scope, metrics.PersistenceFailures)
Expand Down

0 comments on commit d95db4e

Please sign in to comment.