From 4360c024b655b275497ea2dd33bc26b7ac745878 Mon Sep 17 00:00:00 2001 From: Bo Du Date: Fri, 25 Oct 2019 16:32:50 -0400 Subject: [PATCH] Custom error type/check. --- src/dbnode/namespace/schema_registry.go | 14 +++++++++++++- src/dbnode/namespace/schema_registry_updater.go | 11 ++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/dbnode/namespace/schema_registry.go b/src/dbnode/namespace/schema_registry.go index bfc11ea03f..014f19d4d2 100644 --- a/src/dbnode/namespace/schema_registry.go +++ b/src/dbnode/namespace/schema_registry.go @@ -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 @@ -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 } diff --git a/src/dbnode/namespace/schema_registry_updater.go b/src/dbnode/namespace/schema_registry_updater.go index 472da93c96..245103ca1a 100644 --- a/src/dbnode/namespace/schema_registry_updater.go +++ b/src/dbnode/namespace/schema_registry_updater.go @@ -22,7 +22,6 @@ package namespace import ( "fmt" - "strings" xerrors "github.com/m3db/m3/src/x/errors" @@ -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 {