Skip to content

hub: a push batch takes the write lock once per item to read prior answers #210

Closed

Description

@frostyard-machines

logService.Push (internal/hub/log.go:172-176) calls s.answered for each item of a push batch, before it applies anything. answered (log.go:243-255) wraps 1 read, tx.PushAnswer, in s.h.cfg.DB.Tx. DB.Tx takes the database's single write mutex (internal/store/store.go:303-305) and opens a write transaction.

So a batch of 100 items takes and releases the write mutex 100 times only to read prior answers, and each time it can block a vault writer on the hub (a local edit, a scan, another device's push in a different vault). A read of hub_pushes (internal/store/hublog.go:92) needs neither the mutex nor a write transaction: the per-vault logLock (log.go:163-165) already keeps two pushes of the same vault apart.

What's wanted: read the prior answers of the whole batch with 1 query outside DB.Tx (a DB method beside the read methods in internal/store/hub.go and hublog.go), or at least in 1 transaction for the batch. The answers the device gets must stay the same.

Found in a code review of main at b9c6c90.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions