Repository navigation
open_or_create_database: a process that is overtaken on a new path no longer fails with "Cannot create directory" - #493
Merged
Conversation
…ried again The failure on main: open_or_create_database on a new path raised the engine's "Cannot create directory" while another process created the database. These tests script that sequence with a factory object, so they do not depend on the timing of two processes. They fail on the current helper, which calls create() once and raises its error when no database appears within the wait.
Cause: LocalDatabase.create() in the engine makes the database directory with exists() followed by mkdirs(). A process that another one overtakes between the two gets "Cannot create directory" for a directory that now exists. The helper then waited 0.25 s for schema.json, which the other process writes only at the end of its create, and re-raised the directory error when that took longer. The second create does not depend on timing: the directory is there, so the engine's database lock decides (create, "locked by another process", or "already exists"). Other failures fail the same way twice. Both packages use the helper. Docstrings and the docs page now say that the lock error can also come while the other process is still creating.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes
open_or_create_databaseandDatabaseFactory.open_or_createwhen two processes start on the same new path, inarcadedbandarcadedb-jvm(both usesrc/arcadedb/_open_or_create.py).Cause
Two things together made one process fail in the run on
main:LocalDatabase.create()makes the directory withif (!databaseDirectory.exists() && !databaseDirectory.mkdirs())and throws "Cannot create directory" inside it.File.mkdirs()returnsfalsefor a directory that already exists, so a process that another one overtakes between the two calls gets that error about a directory that is there.exists()and then raised the create error again.exists()looks for the schema file, which the other process writes near the end of its create. In that run this took longer than the wait.This is not correct behaviour: the documented contract allows only the "locked by another process" error here.
The fix
The helper calls
create()a second time. After the first failure the directory exists, so the engine skipsmkdirs()and its database lock decides: this process creates the database, or gets "locked by another process", or gets "already exists" and opens it. A longer wait would only have moved the limit. A failure with another cause (a path that is a file, no permission) is still raised, after one more attempt. The outcomes that the two-process test accepts are unchanged.The docstrings and the "Databases and queries" page now also say that the lock error can come while the other process is still creating the database.
The check followed by
mkdirs()stays in the engine. This fix does not depend on a change there.Related issues
Closes #492
Tests
Four new tests in
tests/test_open_or_create.pyscript the sequence with a factory object, so they do not depend on the timing of two processes. The first commit holds only the tests.On the test commit (
097b289), the Python 3.14 leg of the JVM tests ended with 4 failed and 4258 passed: the failures are the four new tests, on the old helper. The checks of the head commit run them with the fix.The failure showed on the Windows leg, which only the full tier runs. I did not start a full run: the race is intermittent (the two later runs on
mainate031d35passed without a fix), so one green Windows run would show little, while the new tests run the failing sequence on every platform. I ran only static checks on my machine (compile, pyflakes, pre-commit, Bandit).Release note draft
open_or_create_database: when two processes start on the same new path, the second one no longer fails with "Cannot create directory". It opens the database or raises the "locked by another process" error, inarcadedbandarcadedb-jvm.Checklist
uvx pre-commit run --files <changed files>passes