Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
fix CassandraIdx.Init error handling
Browse files Browse the repository at this point in the history
* fix two cases where Init failed but err=nil was reported and
  processing continued erroreously.
* return annotated errors instead of bare
* returned errors will be printed by caller, don't need to be printed
  twice. especially not as a warning when it's an error
* typo fix
  • Loading branch information
Dieterbe committed Dec 1, 2017
1 parent 6fc35e8 commit 31990fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions idx/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,40 +165,37 @@ func (c *CasIdx) InitBare() error {
var err error
tmpSession, err := c.cluster.CreateSession()
if err != nil {
log.Error(3, "cassandra-idx failed to create cassandra session. %s", err)
return err
return fmt.Errorf("failed to create cassandra session: %s", err)
}

// create the keyspace or ensure it exists
if createKeyspace {
err = tmpSession.Query(fmt.Sprintf(KeyspaceSchema, keyspace)).Exec()
if err != nil {
log.Error(3, "cassandra-idx failed to initialize cassandra keyspace. %s", err)
return err
return fmt.Errorf("failed to initialize cassandra keyspace: %s", err)
}
err = tmpSession.Query(fmt.Sprintf(TableSchema, keyspace)).Exec()
if err != nil {
log.Error(3, "cassandra-idx failed to initialize cassandra table. %s", err)
return err
return fmt.Errorf("failed to initialize cassandra table: %s", err)
}
} else {
var keyspaceMetadata *gocql.KeyspaceMetadata
for attempt := 1; attempt > 0; attempt++ {
keyspaceMetadata, err = tmpSession.KeyspaceMetadata(keyspace)
if err != nil {
log.Warn("cassandra-idx cassandra keyspace not found. retry attempt: %v", attempt)
if attempt >= 5 {
return err
return fmt.Errorf("cassandra keyspace not found. %d attempts", attempt)
}
log.Warn("cassandra-idx cassandra keyspace not found. retrying in 5s. attempt: %d", attempt)
time.Sleep(5 * time.Second)
} else {
if _, ok := keyspaceMetadata.Tables["metric_idx"]; ok {
break
} else {
log.Warn("cassandra-idx cassandra table not found. retry attempt: %v", attempt)
if attempt >= 5 {
return err
return fmt.Errorf("cassandra table not found. %d attempts", attempt)
}
log.Warn("cassandra-idx cassandra table not found. retrying in 5s. attempt: %d", attempt)
time.Sleep(5 * time.Second)
}
}
Expand All @@ -210,8 +207,7 @@ func (c *CasIdx) InitBare() error {
c.cluster.Keyspace = keyspace
session, err := c.cluster.CreateSession()
if err != nil {
log.Error(3, "cassandra-idx failed to create cassandra session. %s", err)
return err
return fmt.Errorf("failed to create cassandra session: %s", err)
}

c.session = session
Expand Down
2 changes: 1 addition & 1 deletion metrictank.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func main() {
log.Info("metricIndex initialized in %s. starting data consumption", time.Now().Sub(pre))

/***********************************
Initialize MetricPerrist notifiers
Initialize MetricPersist notifiers
***********************************/
handlers := make([]mdata.NotifierHandler, 0)
if notifierKafka.Enabled {
Expand Down

0 comments on commit 31990fb

Please sign in to comment.