kuzu icon indicating copy to clipboard operation
kuzu copied to clipboard

Lock file does not prevent opening two databases from the same process

Open mewim opened this issue 10 months ago • 0 comments

For example:

db_path = tmp_path / "test_database_close.kuzu"
db1 = kuzu.Database(database_path = db_path, read_only = False)
assert not db1.is_closed
assert db1._database is not None

db2 = kuzu.Database(database_path = db_path, read_only = False)
assert not db2.is_closed
assert db2._database is not None

this does not throw any error and created two instances of read-write databases in the same Python process. This is likely due to that only one F_WRLCK lock is held per process:

A single process can hold only one type of lock on a file region; if a new lock is applied to an already-locked region, then the existing lock is converted to the new lock type. (Such conversions may involve splitting, shrinking, or coalescing with an existing lock if the byte range specified by the new lock does not precisely coincide with the range of the existing lock.)

Such behavior may not be desirable. We should decide whether we need to do additional work to prevent this and make this behavior clear to the user in our docs.

mewim avatar Apr 16 '24 14:04 mewim