Skip to content

Fix 'database is locked' error #679

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

Merged
merged 3 commits into from
Aug 11, 2022
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
10 changes: 9 additions & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ type Scannable interface {
}

func SqlDB(dbPath string) (*sql.DB, error) {
return sql.Open("sqlite3", "file:"+dbPath)
db, err := sql.Open("sqlite3", "file:"+dbPath)
if err == nil {
// fixes error "database is locked", caused by concurrent access from deal goroutines to a single sqlite3 db connection
// see: https://github.com/mattn/go-sqlite3#:~:text=Error%3A%20database%20is%20locked
// see: https://github.com/filecoin-project/boost/pull/657
db.SetMaxOpenConns(1)
}

return db, err
}

//go:embed create_main_db.sql
Expand Down
8 changes: 6 additions & 2 deletions node/modules/storageminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ func StorageNetworkName(ctx helpers.MetricsCtx, a v1api.FullNode) (dtypes.Networ
}

func NewBoostDB(r lotus_repo.LockedRepo) (*sql.DB, error) {
dbPath := path.Join(r.Path(), "boost.db")
// fixes error "database is locked", caused by concurrent access from deal goroutines to a single sqlite3 db connection
// see: https://github.com/mattn/go-sqlite3#:~:text=Error%3A%20database%20is%20locked
dbPath := path.Join(r.Path(), "boost.db?cache=shared")
return db.SqlDB(dbPath)
}

Expand All @@ -294,7 +296,9 @@ type LogSqlDB struct {
}

func NewLogsSqlDB(r repo.LockedRepo) (*LogSqlDB, error) {
dbPath := path.Join(r.Path(), "boost.logs.db")
// fixes error "database is locked", caused by concurrent access from deal goroutines to a single sqlite3 db connection
// see: https://github.com/mattn/go-sqlite3#:~:text=Error%3A%20database%20is%20locked
dbPath := path.Join(r.Path(), "boost.logs.db?cache=shared")
d, err := db.SqlDB(dbPath)
if err != nil {
return nil, err
Expand Down