Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #232 from erizocosmico/feature/logs-index-creation
Browse files Browse the repository at this point in the history
sql/(index,plan): add logs for index creation
  • Loading branch information
ajnavarro committed Jun 20, 2018
2 parents 5c8cbac + 4526bb6 commit acce4ea
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion sql/plan/create_index.go
Expand Up @@ -116,8 +116,13 @@ func (c *CreateIndex) RowIter(ctx *sql.Context) (sql.RowIter, error) {
return nil, err
}

log := logrus.WithFields(logrus.Fields{
"id": index.ID(),
"driver": index.Driver(),
})

go func() {
err := driver.Save(ctx, index, iter)
err := driver.Save(ctx, index, &loggingKeyValueIter{log: log, iter: iter})
close(done)
if err != nil {
logrus.WithField("err", err).Error("unable to save the index")
Expand All @@ -127,9 +132,13 @@ func (c *CreateIndex) RowIter(ctx *sql.Context) (sql.RowIter, error) {
} else {
<-deleted
}
} else {
log.Info("index successfully created")
}
}()

log.Info("starting to save the index")

return sql.RowsToRowIter(), nil
}

Expand Down Expand Up @@ -253,3 +262,20 @@ func getColumnsAndPrepareExpressions(

return columns, expressions, nil
}

type loggingKeyValueIter struct {
log *logrus.Entry
iter sql.IndexKeyValueIter
rows uint64
}

func (i *loggingKeyValueIter) Next() ([]interface{}, []byte, error) {
i.rows++
if i.rows%100 == 0 {
i.log.Debugf("still creating index: %d rows saved so far", i.rows)
}

return i.iter.Next()
}

func (i *loggingKeyValueIter) Close() error { return i.iter.Close() }

0 comments on commit acce4ea

Please sign in to comment.