From 58329923236b8640465ac68a1069ac4c5abbca07 Mon Sep 17 00:00:00 2001 From: Jinsub Moon Date: Wed, 20 Jul 2022 16:49:53 +0000 Subject: [PATCH 1/3] Fix 'database is locked' error --- db/db.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db/db.go b/db/db.go index 5a382769e..97b609866 100644 --- a/db/db.go +++ b/db/db.go @@ -19,7 +19,12 @@ 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 { + db.SetMaxOpenConns(1) + } + + return db, err } //go:embed create_main_db.sql From 753c5c399a9a7215e68e5b12cc4df91375ca5ec2 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Wed, 3 Aug 2022 12:44:53 +0300 Subject: [PATCH 2/3] add cache=shared --- node/modules/storageminer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 0747c805c..de7256cf6 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -285,7 +285,7 @@ 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") + dbPath := path.Join(r.Path(), "boost.db?cache=shared") return db.SqlDB(dbPath) } @@ -294,7 +294,7 @@ type LogSqlDB struct { } func NewLogsSqlDB(r repo.LockedRepo) (*LogSqlDB, error) { - dbPath := path.Join(r.Path(), "boost.logs.db") + dbPath := path.Join(r.Path(), "boost.logs.db?cache=shared") d, err := db.SqlDB(dbPath) if err != nil { return nil, err From fd59abc6d88c7f72c8f05a6ce2ab5cba526fef78 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 11 Aug 2022 13:34:35 +0200 Subject: [PATCH 3/3] add comments on issue --- db/db.go | 3 +++ node/modules/storageminer.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/db/db.go b/db/db.go index 97b609866..e7a6c4b1e 100644 --- a/db/db.go +++ b/db/db.go @@ -21,6 +21,9 @@ type Scannable interface { func SqlDB(dbPath string) (*sql.DB, error) { 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) } diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index de7256cf6..b77cf8bb2 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -285,6 +285,8 @@ func StorageNetworkName(ctx helpers.MetricsCtx, a v1api.FullNode) (dtypes.Networ } func NewBoostDB(r lotus_repo.LockedRepo) (*sql.DB, error) { + // 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) } @@ -294,6 +296,8 @@ type LogSqlDB struct { } func NewLogsSqlDB(r repo.LockedRepo) (*LogSqlDB, error) { + // 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 {