Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chainindex): retry transaction if database connection is lost #12657

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions chain/index/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ func (si *SqliteIndexer) backfillMissingTipset(ctx context.Context, ts *types.Ti
if ipld.IsNotFound(err) {
return nil, xerrors.Errorf("failed to backfill tipset at epoch %d: chain store does not contain data: %w", ts.Height(), err)
}
if ctx.Err() != nil {
log.Errorf("failed to backfill tipset at epoch %d due to context cancellation: %s", ts.Height(), err)
}
return nil, xerrors.Errorf("failed to backfill tipset at epoch %d; err: %w", ts.Height(), err)
}

Expand Down
3 changes: 2 additions & 1 deletion chain/index/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ func (si *SqliteIndexer) indexTipset(ctx context.Context, tx *sql.Tx, ts *types.
}

height := ts.Height()
insertTipsetMsgStmt := tx.Stmt(si.stmts.insertTipsetMessageStmt)

msgs, err := si.cs.MessagesForTipset(ctx, ts)
if err != nil {
return xerrors.Errorf("failed to get messages for tipset: %w", err)
}

if len(msgs) == 0 {
insertTipsetMsgStmt := tx.Stmt(si.stmts.insertTipsetMessageStmt)
// If there are no messages, just insert the tipset and return
if _, err := insertTipsetMsgStmt.ExecContext(ctx, tsKeyCidBytes, height, 0, nil, -1); err != nil {
return xerrors.Errorf("failed to insert empty tipset: %w", err)
Expand All @@ -294,6 +294,7 @@ func (si *SqliteIndexer) indexTipset(ctx context.Context, tx *sql.Tx, ts *types.
}

for i, msg := range msgs {
insertTipsetMsgStmt := tx.Stmt(si.stmts.insertTipsetMessageStmt)
msg := msg
if _, err := insertTipsetMsgStmt.ExecContext(ctx, tsKeyCidBytes, height, 0, msg.Cid().Bytes(), i); err != nil {
return xerrors.Errorf("failed to insert tipset message: %w", err)
Expand Down
Loading