Skip to content

Commit

Permalink
Merge pull request #463 from Iceber/add-retry-for-bad-conn-0.5
Browse files Browse the repository at this point in the history
[release/0.5] internalstorage: add recoverable err
  • Loading branch information
Iceber authored Nov 24, 2022
2 parents fb84406 + 9278db8 commit f62507d
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions pkg/storage/internalstorage/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package internalstorage

import (
"database/sql/driver"
"errors"
"fmt"
"io"
Expand All @@ -17,6 +18,14 @@ import (
"github.com/clusterpedia-io/clusterpedia/pkg/storage"
)

var recoverableErrors = []error{
io.ErrClosedPipe,
io.ErrUnexpectedEOF,
os.ErrDeadlineExceeded,
syscall.ECONNREFUSED,
driver.ErrBadConn,
}

func InterpretResourceDBError(cluster, name string, err error) error {
if err == nil {
return nil
Expand All @@ -34,15 +43,20 @@ func InterpretDBError(key string, err error) error {
return genericstorage.NewKeyNotFoundError(key, 0)
}

if _, isNetError := err.(net.Error); isNetError ||
errors.Is(err, io.ErrClosedPipe) ||
errors.Is(err, io.ErrUnexpectedEOF) ||
os.IsTimeout(err) ||
errors.Is(err, os.ErrDeadlineExceeded) ||
errors.Is(err, syscall.ECONNREFUSED) {
if _, isNetError := err.(net.Error); isNetError {
return storage.NewRecoverableException(err)
}

if os.IsTimeout(err) {
return storage.NewRecoverableException(err)
}

for _, re := range recoverableErrors {
if errors.Is(err, re) {
return storage.NewRecoverableException(err)
}
}

// TODO(iceber): add dialector judgment
mysqlErr := InterpretMysqlError(key, err)
if mysqlErr != err {
Expand Down

0 comments on commit f62507d

Please sign in to comment.