Skip to content

Commit

Permalink
Custom error type/check.
Browse files Browse the repository at this point in the history
  • Loading branch information
notbdu committed Oct 25, 2019
1 parent f62eccf commit 4360c02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/dbnode/namespace/schema_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ import (
"go.uber.org/zap"
)

func newSchemaHistoryNotFoundError(nsIDStr string) error {
return &schemaHistoryNotFoundError{nsIDStr}
}

type schemaHistoryNotFoundError struct {
nsIDStr string
}

func (s *schemaHistoryNotFoundError) Error() string {
return fmt.Sprintf("schema history is not found for %s", s.nsIDStr)
}

type schemaRegistry struct {
sync.RWMutex

Expand Down Expand Up @@ -125,7 +137,7 @@ func (sr *schemaRegistry) getSchemaHistory(nsIDStr string) (SchemaHistory, error

history, ok := sr.registry[nsIDStr]
if !ok {
return nil, fmt.Errorf("schema history is not found for %v", nsIDStr)
return nil, newSchemaHistoryNotFoundError(nsIDStr)
}
return history.Get().(SchemaHistory), nil
}
Expand Down
11 changes: 6 additions & 5 deletions src/dbnode/namespace/schema_registry_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package namespace

import (
"fmt"
"strings"

xerrors "github.com/m3db/m3/src/x/errors"

Expand All @@ -39,10 +38,12 @@ func UpdateSchemaRegistry(newNamespaces Map, schemaReg SchemaRegistry, log *zap.
curSchemaNone = true
)
curSchema, err := schemaReg.GetLatestSchema(metadata.ID())
// NB(bodu): Schema history not found is a valid error as this occurs on initial bootstrap for the db.
if err != nil && !strings.Contains(err.Error(), "schema history is not found for") {
multiErr = multiErr.Add(fmt.Errorf("cannot get latest namespace schema: %v", err))
continue
if err != nil {
// NB(bodu): Schema history not found is a valid error as this occurs on initial bootstrap for the db.
if _, ok := err.(*schemaHistoryNotFoundError); !ok {
multiErr = multiErr.Add(fmt.Errorf("cannot get latest namespace schema: %v", err))
continue
}
}

if curSchema != nil {
Expand Down

0 comments on commit 4360c02

Please sign in to comment.