-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Do not block the database(sqlite) during archive creation #27563
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
Conversation
This commit can be dropped as soon as go-gitea#27563 is accepted.
This commit can be dropped as soon as go-gitea#27563 is accepted.
This commit can be dropped as soon as go-gitea#27563 is accepted.
How about moving the archive generation before database updates? |
That would work if the gitea/services/repository/archiver/archiver.go Lines 189 to 194 in 170177c
|
Yes, that's a simpler lock mechanism based on database. And I think this is only affecting sqlite but for other database, it works. |
Yes, I think the underlying issue is sqlite's limitations in regard to concurrent reads/writes. Holding the transaction open for the entire duration of archive creation seems to even block read access to the database. Other databases do not have these limitations, although keeping the transaction open for a long time might have some effect there as well, like increased resource usage and such to accommodate this situation. Some sqlite options, like WAL mode, might also have an effect on how this issue manifests itself, but I haven't tested out anything in that regard. |
It's better to use the current |
Can you help to confirm that #32186 can resolve the problem? |
Replaced by #32186 |
Since there is a status column in the database, the transaction is unnecessary when downloading an archive. The transaction is blocking database operations, especially with SQLite. Replace #27563
Since there is a status column in the database, the transaction is unnecessary when downloading an archive. The transaction is blocking database operations, especially with SQLite. Replace go-gitea#27563
Backport #32186 by @lunny Since there is a status column in the database, the transaction is unnecessary when downloading an archive. The transaction is blocking database operations, especially with SQLite. Replace #27563 Co-authored-by: Lunny Xiao <[email protected]>
The database transaction in
doArchive
is currently held open for the entirety of the archive generation process. For larger repositories this could be a long time. If the database is sqlite3 (others not tested) then this can block other processes from using the database, which e.g. leads to long load times for the web UI route of all repositories on the gitea server, among other things. This patch finishes the transaction right before generating the archive and starts a new one to update the database afterwards.You can reproduce the issue with the following steps:
I am new to Go and therefore not sure if this is the most idiomatic way to fix this. I essentially just copied the way the transaction is created in the beginning to after the archive is created and
.Commit
and.Close
d before that. Specifically I am not sure if I would have to propagate the err from.Close
as well, since that is deferred in the beginning which would silence the error as well, right? Is this "double.Close
" from the defer and the explicit call OK to do?