mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-18 03:17:56 +01:00
Fix SQLite concurrency problems by using BEGIN IMMEDIATE (#10368)
* Test locking immediate for SQLite3 * fix url field separator Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
7ffc2427da
commit
4a2d23981d
3 changed files with 3 additions and 3 deletions
|
@ -126,7 +126,7 @@ func restoreOldDB(t *testing.T, version string) bool {
|
||||||
err := os.MkdirAll(path.Dir(setting.Database.Path), os.ModePerm)
|
err := os.MkdirAll(path.Dir(setting.Database.Path), os.ModePerm)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
db, err := sql.Open("sqlite3", fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d", setting.Database.Path, setting.Database.Timeout))
|
db, err := sql.Open("sqlite3", fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate", setting.Database.Path, setting.Database.Timeout))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ func MainTest(m *testing.M, pathToGiteaRoot string) {
|
||||||
// CreateTestEngine creates a memory database and loads the fixture data from fixturesDir
|
// CreateTestEngine creates a memory database and loads the fixture data from fixturesDir
|
||||||
func CreateTestEngine(fixturesDir string) error {
|
func CreateTestEngine(fixturesDir string) error {
|
||||||
var err error
|
var err error
|
||||||
x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
|
x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared&_txlock=immediate")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ func DBConnStr() (string, error) {
|
||||||
if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil {
|
if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil {
|
||||||
return "", fmt.Errorf("Failed to create directories: %v", err)
|
return "", fmt.Errorf("Failed to create directories: %v", err)
|
||||||
}
|
}
|
||||||
connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d", Database.Path, Database.Timeout)
|
connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate", Database.Path, Database.Timeout)
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("Unknown database type: %s", Database.Type)
|
return "", fmt.Errorf("Unknown database type: %s", Database.Type)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue