Skip to content

Commit

Permalink
Merge pull request #5818 from influxdata/er-upgrade-error
Browse files Browse the repository at this point in the history
Highlight upgrade info for old shards
  • Loading branch information
e-dard committed Mar 9, 2016
2 parents bc26167 + aa845ce commit 7dbc0f4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
5 changes: 5 additions & 0 deletions cmd/influxd/run/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ func (s *Server) Open() error {

// Open TSDB store.
if err := s.TSDBStore.Open(); err != nil {
// Provide helpful error if user needs to upgrade shards to
// tsm1.
if serr, ok := err.(tsdb.ShardError); ok && serr.Err == tsdb.ErrUnknownEngineFormat {
return influxdb.ErrUpgradeEngine
}
return fmt.Errorf("open tsdb store: %s", err)
}

Expand Down
15 changes: 15 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ var (

// ErrFieldTypeConflict is returned when a new field already exists with a different type.
ErrFieldTypeConflict = errors.New("field type conflict")

// ErrUpgradeEngine will be returned when it's determined that
// the server has encountered shards that are not in the `tsm1`
// format.
ErrUpgradeEngine = errors.New("\n\n" + upgradeMessage + "\n\n")
)

// ErrDatabaseNotFound indicates that a database operation failed on the
Expand Down Expand Up @@ -43,3 +48,13 @@ func IsClientError(err error) bool {

return false
}

const upgradeMessage = `*******************************************************************
UNSUPPORTED SHARD FORMAT DETECTED
As of version 0.11, only tsm shards are supported. Please use the
influx_tsm tool to convert non-tsm shards.
More information can be found at the documentation site:
https://docs.influxdata.com/influxdb/v0.10/administration/upgrading
*******************************************************************`
7 changes: 6 additions & 1 deletion tsdb/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (
var (
// ErrFormatNotFound is returned when no format can be determined from a path.
ErrFormatNotFound = errors.New("format not found")

// ErrUnknownEngineFormat is returned when the engine format is
// unknown. ErrUnknownEngineFormat is currently returned if a format
// other than tsm1 is encountered.
ErrUnknownEngineFormat = errors.New("unknown engine format")
)

// Engine represents a swappable storage engine for the shard.
Expand Down Expand Up @@ -89,7 +94,7 @@ func NewEngine(path string, walPath string, options EngineOptions) (Engine, erro
if fi, err := os.Stat(path); err != nil {
return nil, err
} else if !fi.Mode().IsDir() {
return nil, errors.New("unknown engine type")
return nil, ErrUnknownEngineFormat
} else {
format = "tsm1"
}
Expand Down
27 changes: 23 additions & 4 deletions tsdb/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ var (
ErrFieldUnmappedID = errors.New("field ID not mapped")
)

// A ShardError implements the error interface, and contains extra
// context about the shard that generated the error.
type ShardError struct {
id uint64
Err error
}

// NewShardError returns a new ShardError.
func NewShardError(id uint64, err error) error {
if err == nil {
return nil
}
return ShardError{id: id, Err: err}
}

func (e ShardError) Error() string {
return fmt.Sprintf("[shard %d] %s", e.id, e.Err)
}

// Shard represents a self-contained time series database. An inverted index of
// the measurement and tag data is kept along with the raw time series data.
// Data can be split across many shards. The query engine in TSDB is responsible
Expand Down Expand Up @@ -126,7 +145,7 @@ func (s *Shard) Open() error {
// Initialize underlying engine.
e, err := NewEngine(s.path, s.walPath, s.options)
if err != nil {
return fmt.Errorf("new engine: %s", err)
return err
}
s.engine = e

Expand All @@ -135,18 +154,18 @@ func (s *Shard) Open() error {

// Open engine.
if err := s.engine.Open(); err != nil {
return fmt.Errorf("open engine: %s", err)
return err
}

// Load metadata index.
if err := s.engine.LoadMetadataIndex(s, s.index, s.measurementFields); err != nil {
return fmt.Errorf("load metadata index: %s", err)
return err
}

return nil
}(); err != nil {
s.close()
return err
return NewShardError(s.id, err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion tsdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (s *Store) loadShards() error {
shard := NewShard(shardID, s.databaseIndexes[db], path, walPath, s.EngineOptions)
err = shard.Open()
if err != nil {
return fmt.Errorf("failed to open shard %d: %s", shardID, err)
return err
}

s.shards[shardID] = shard
Expand Down

0 comments on commit 7dbc0f4

Please sign in to comment.