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

@@ -42,7 +42,7 @@ func (t *GenerateMarkersTask) Start(ctx context.Context) {
if t.Marker != nil {
var scene *models.Scene
if err := t.TxnManager.WithTxn(ctx, func(ctx context.Context) error {
if err := t.TxnManager.WithReadTxn(ctx, func(ctx context.Context) error {
var err error
scene, err = t.TxnManager.Scene.Find(ctx, int(t.Marker.SceneID.Int64))
if err == nil && scene != nil {
@@ -73,7 +73,7 @@ func (t *GenerateMarkersTask) Start(ctx context.Context) {
func (t *GenerateMarkersTask) generateSceneMarkers(ctx context.Context) {
var sceneMarkers []*models.SceneMarker
if err := t.TxnManager.WithTxn(ctx, func(ctx context.Context) error {
if err := t.TxnManager.WithReadTxn(ctx, func(ctx context.Context) error {
var err error
sceneMarkers, err = t.TxnManager.SceneMarker.FindBySceneID(ctx, t.Scene.ID)
return err