Fix database locked errors (#3153)

* Make read-only operations use WithReadTxn
* Allow one database write thread
* Add unit test for concurrent transactions
* Perform some actions after commit to release txn
* Suppress some errors from cancelled context
This commit is contained in:
WithoutPants
2022-11-21 06:49:10 +11:00
committed by GitHub
parent 420c6fa9d7
commit f39fa416a9
54 changed files with 626 additions and 311 deletions

View File

@@ -109,7 +109,7 @@ func (j *cleanJob) execute(ctx context.Context) error {
folderCount int
)
if err := txn.WithTxn(ctx, j.Repository, func(ctx context.Context) error {
if err := txn.WithReadTxn(ctx, j.Repository, func(ctx context.Context) error {
var err error
fileCount, err = j.Repository.CountAllInPaths(ctx, j.options.Paths)
if err != nil {
@@ -169,7 +169,7 @@ func (j *cleanJob) assessFiles(ctx context.Context, toDelete *deleteSet) error {
progress := j.progress
more := true
if err := txn.WithTxn(ctx, j.Repository, func(ctx context.Context) error {
if err := txn.WithReadTxn(ctx, j.Repository, func(ctx context.Context) error {
for more {
if job.IsCancelled(ctx) {
return nil
@@ -253,7 +253,7 @@ func (j *cleanJob) assessFolders(ctx context.Context, toDelete *deleteSet) error
progress := j.progress
more := true
if err := txn.WithTxn(ctx, j.Repository, func(ctx context.Context) error {
if err := txn.WithReadTxn(ctx, j.Repository, func(ctx context.Context) error {
for more {
if job.IsCancelled(ctx) {
return nil