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 1 commit
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
2 changes: 1 addition & 1 deletion chain/index/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func withTx(ctx context.Context, db *sql.DB, fn func(*sql.Tx) error) error {
}

func isRetryableError(err error) bool {
return err != nil && strings.Contains(err.Error(), "database is locked")
return err != nil && (strings.Contains(err.Error(), "database is locked") || strings.Contains(err.Error(), "statement is closed"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this is the right approach, why is the statement getting closed? it's not a network connection so shouldn't suffer from network problems. This seems like it's masking a real problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvagg I see what you mean. Have reverted this change.

}

func isIndexedFlag(b uint8) bool {
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