From 71dcc3801e2049cb18048edc55b2de5276ca77ed Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Tue, 29 Oct 2024 12:15:04 +0700 Subject: [PATCH 1/3] retry database lost connection --- chain/index/helpers.go | 2 +- chain/index/indexer.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/chain/index/helpers.go b/chain/index/helpers.go index a4db495c99e..4123f5f48c7 100644 --- a/chain/index/helpers.go +++ b/chain/index/helpers.go @@ -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")) } func isIndexedFlag(b uint8) bool { diff --git a/chain/index/indexer.go b/chain/index/indexer.go index 10ea4fc9c8b..7cee575a6df 100644 --- a/chain/index/indexer.go +++ b/chain/index/indexer.go @@ -278,7 +278,6 @@ 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 { @@ -286,6 +285,7 @@ func (si *SqliteIndexer) indexTipset(ctx context.Context, tx *sql.Tx, ts *types. } 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) @@ -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) From 5c7fa9611aaebf6add39c041714a198ae72078c0 Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Tue, 29 Oct 2024 16:02:50 +0700 Subject: [PATCH 2/3] log context cancellation --- chain/index/api.go | 3 +++ chain/index/helpers.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/chain/index/api.go b/chain/index/api.go index 5262a200326..1bb19de7a67 100644 --- a/chain/index/api.go +++ b/chain/index/api.go @@ -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) } diff --git a/chain/index/helpers.go b/chain/index/helpers.go index 4123f5f48c7..4b5b5eaf079 100644 --- a/chain/index/helpers.go +++ b/chain/index/helpers.go @@ -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") || strings.Contains(err.Error(), "statement is closed")) + return err != nil && (strings.Contains(err.Error(), "database is locked")) } func isIndexedFlag(b uint8) bool { From 9046d08c96e19f94965846f2e0b0c6b6d867c41f Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Tue, 29 Oct 2024 16:06:27 +0700 Subject: [PATCH 3/3] address review --- chain/index/helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/index/helpers.go b/chain/index/helpers.go index 4b5b5eaf079..a4db495c99e 100644 --- a/chain/index/helpers.go +++ b/chain/index/helpers.go @@ -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") } func isIndexedFlag(b uint8) bool {