Skip to content

Commit

Permalink
Switch back to cgo-based SQLite driver
Browse files Browse the repository at this point in the history
In our experience, the pure Go SQLite driver introduced in upstream cmgr
v0.13.0 had issues handling a large number of concurrent requests (such
as during major competitions). Operations would often fail due to
SQLITE_BUSY errors. See also package issues [0][1][2][3][4][5].

Due to this issue, we had previously forced to roll back to upstream
cmgr v0.12.0. By reverting back to the cgo-based driver, we can take
advantage of the other fixes made since that release.

[0]: https://gitlab.com/cznic/sqlite/-/issues/74
[1]: https://gitlab.com/cznic/sqlite/-/issues/115
[2]: https://gitlab.com/cznic/sqlite/-/issues/126
[3]: https://gitlab.com/cznic/sqlite/-/issues/142
[4]: https://gitlab.com/cznic/sqlite/-/issues/146
[5]: https://gitlab.com/cznic/sqlite/-/issues/161
  • Loading branch information
dmartin committed Jan 19, 2024
1 parent 749f372 commit 0f6bee8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 235 deletions.
48 changes: 22 additions & 26 deletions NOTICE.release
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,30 @@ OTHER DEALINGS IN THE SOFTWARE.

------------------------------------------------------------------------------

This work uses the 'modernc.org/sqlite' module for Go:
This work uses the 'github.com/mattn/go-sqlite3' module for Go:

Copyright (c) 2017 The Sqlite Authors. All rights reserved.
go-sqlite3
The MIT License (MIT)

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Copyright (c) 2014 Yasuhiro Matsumoto

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions cmgr/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"

"github.com/jmoiron/sqlx"
_ "modernc.org/sqlite"
_ "github.com/mattn/go-sqlite3"
)

const schemaQuery string = `
Expand Down Expand Up @@ -179,7 +179,7 @@ func (m *Manager) initDatabase() error {
dbPath = "cmgr.db"
}

db, err := sqlx.Open("sqlite", dbPath+"?_pragma=foreign_keys(1)")
db, err := sqlx.Open("sqlite3", dbPath+"?_fk=true")
if err != nil {
m.log.errorf("could not open database: %s", err)
return err
Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ require (
github.com/docker/docker v20.10.13+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.4.0
github.com/gogo/googleapis v1.4.1 // indirect
github.com/jmoiron/sqlx v1.3.4
github.com/klauspost/compress v1.15.0 // indirect
github.com/moby/sys/mountinfo v0.6.0 // indirect
github.com/moby/sys/signal v0.7.0 // indirect
github.com/mattn/go-sqlite3 v1.14.9
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/yuin/goldmark v1.4.2
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
google.golang.org/genproto v0.0.0-20220310185008-1973136f34c6 // indirect
google.golang.org/grpc v1.45.0 // indirect
gopkg.in/yaml.v2 v2.4.0
modernc.org/sqlite v1.14.6
)
Loading

0 comments on commit 0f6bee8

Please sign in to comment.