Skip to content

using a db transaction when scanning (external) files with sqlite causes database locked errors #11391

Closed

Description

@butonic

I assume the database transaction used to commit updates of the file scanning process in batches causes an sqlite database to lock for extended periods of time, leading to the database locked error when another request comes in. With preview generation, background jobs, hooks, search lucene and maybe sync clients coming along that is very likely to happen. The chance that a lock is in place increases with the latency of file scans, meaning scanning a remote files_external storage, such as amazon s3 is highly likely to produce the db lock.

for reference, a little history:
16 Jan 2013 @icewind1991 adding a transaction to improve scan performance 6871a15

3 Nov 2013 @jancborchardt the original issue #5680
21 Aug 2014 @PVince81 assuming an open db cursor to be the issue #10566

8 Sep 2014 @icewind1991 making the transaction contain even more updates in master 644755d

30 Sep 2014 @butonic being able to reproduce the issue #11280 (comment)
1 Oct 2014 @jancborchardt confirming he was likely using files_external with sqlite #11280 (comment)

With 644755d has added a flag to the scanner that we could use to do without transactions on sqlite. AFAICT atomicity is not the reason for the transaction. Opinions @DeepDiver1975 @karlitschek @schiesbn @icewind1991

Activity

  1. craigpg commented on Oct 2, 2014

    @craigpg

    @butonic, is this sqlite only?

  2. added this to the milestone on Oct 2, 2014
  3. butonic commented on Oct 2, 2014

    @butonic
    ContributorAuthor

    @craigpg yes, sqlite only

  4. icewind1991 commented on Oct 2, 2014

    @icewind1991
    Contributor

    Disabling transitions in the scanner would be a solution but it would cause a massive performance panelty

  5. karlitschek commented on Oct 2, 2014

    @karlitschek
    Contributor

    @icewind1991 Why does the transaction improve the performance? I´m not sure I understand the reason by reading the code.

  6. butonic commented on Oct 6, 2014

    @butonic
    ContributorAuthor

    Without the transaction scanning 10000 files makes 10000 individual updates, auto committing them. Which in turn causes the affected indexes to be updated - which is slow on all DBMS, but especially on sqlite and lower end hardware. (more details on sqlite insert performance in http://stackoverflow.com/questions/1711631/how-do-i-improve-insert-per-second-performance-of-sqlite)

  7. 9 remaining items

  8. modified the milestones: , on Oct 27, 2014
  9. modified the milestones: , on Nov 10, 2014
  10. modified the milestones: , backlog on Jan 31, 2015
  11. dragotin commented on Feb 18, 2015

    @dragotin
    Contributor

    Pull request that adds some closeCursors: #14329

  12. MorrisJobke commented on Nov 25, 2015

    @MorrisJobke
    Contributor

    @PVince81 @icewind1991 Isn't this solved by high level file locking that was enabled in 8.2+?

  13. PVince81 commented on Nov 25, 2015

    @PVince81
    Contributor

    Such issues haven't been reported since a while, so it might be solved by locking, yes.
    Also we did add many closeCursor calls.

  14. MorrisJobke commented on Nov 25, 2015

    @MorrisJobke
    Contributor

    Okay let's close this here and maybe reopen if this appears again.

  15. lock commented on Aug 7, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  16. locked as resolved and limited conversation to collaborators on Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions