Open ZmeiGorynych opened 2 weeks ago
Just noticed that this doesn't happen if I make the relation name unique, eg f"rel{i+1}" instead of "rel1". Do the relation names have to be unique even when they connect different nodes?
Hi @ZmeiGorynych, relationship tables reference the underlying node table's primary keys in the FROM
and TO
columns (you can only have one relationship between any given pair of nodes based on their primary keys).
Just clarifying the intent behind this snippet, which doesn't seem right (or safe) to me:
sleep_time = 0
for i in range(10):
print(i + 1)
create_entity(f"entity{i+1}")
sleep(sleep_time)
create_relation("entity1", f"entity{i+1}", "rel1")
sleep(sleep_time)
When you just create entity1
within the for loop and then immediately reference it to create the relationship, the transaction may not have been committed yet (nor the primary key index created/updated safely for the relationship table to reference). From an I/O perspective, you're much better off creating the nodes beforehand, so that the node table's hash index can get up to date and all the transactions are committed safely. Then you would be able to safely reference these primary keys in a subsequent loop to update the relationships. Maybe @ray6080 might be able to offer more advice if I've missed anything here.
Thanks a lot for the quick answer!
However, I would challenge it on several counts:
firstly, as I said the exception vanishes when I replace the line
create_relation("entity1", f"entity{i+1}", f"rel")
with
create_relation("entity1", f"entity{i+1}", f"rel{i+1}")
,
and it doesn't seem like that would happen if your explanation was correct.
Secondly, the above is a very natural calling pattern, think of it as having a function add_child
that is called several times in a row, and each time it first creates a child node and then a relationship between it and entity1
.
Finally, I find it very alarming that you appear to say that a collision between subsequent execute
methods if they are not called in a certain magic order is reasonable behavior for kuzu. Is there no way to make sure each call of the execute method returns only after all the commits have been made, all the indices updated, etc? I don't mind waiting a bit longer on each call, but having random errors like this pop up on a logically sound sequence of calls might be a deal breaker for us using kuzu if there is no fix or workaround :(
Thanks for reporting the bug. Just to weigh in: I don't see anything wrong with the query. Each of your calls to connection.execute
should auto-commit before returning, so you should not even need to sleep in between these. This looks like a bug with our management of the nodes.statistics_and_deleted.ids.wal
file. Let's have @ray6080 look into this bug and fix it.
Thanks @semihsalihoglu-uw! Relieved to have you agree that this is indeed a bug :) Probably not caught yet because your tests are likely on a Linux, and Windows can be a lot more anal about locking files. Hopefully the fact that the bug disappears if the relation names are all distinct will make it easier to locate.
Just got a very similar error in a different context:
(<class 'RuntimeError'>, RuntimeError('remove: The process cannot access the file because it is being used by another process.: "C:\\Users\\Egor\\Dropbox\\Code\\motleycrew\\examples\\research_agent\\research_db\\catalog.kz.wal"'), <traceback object at 0x00000A8CDAEA8D80>)
while executing a very basic query
'CREATE REL TABLE is_subquestion (FROM Question TO Question)'
Is intermittent, sometimes it arises when I call the above query and sometimes not in exactly the same code.
Is there any ETA on resolving the above and hopefully also this one? :)
Thanks a lot!
Hey @ZmeiGorynych , we will take a look into it today and get back to u on the ETA. prioritizing this now.
I haven't been able to reproduce this, but it could just be from another program accessing the wal file when it is being removed after committing. Is it possible that it's caused by Dropbox accessing the files? Have you tried disabling anti-virus scanning for the database directory?
Ah, nice catch! After moving the disk location to a non-Dropbox directory, the error disappeared (or at least hasn't appeared after a dozen or so runs). Still, this sounds like something others might encounter - would it be worth waiting for (a second?) and retrying if this error occurs, instead of failing right away?
That might work, though I think a more reliable alternative would be to avoid removing the WAL files at all and to just empty them instead.
When I try to insert nodes and relations in a loop, like below, sooner or later I get the following exception:
(<class 'RuntimeError'>, RuntimeError('remove: The process cannot access the file because it is being used by another process.: "C:\\Users\\Egor\\Dropbox\\Code\\motleycrew\\examples\\bug_db\\nodes.statistics_and_deleted.ids.wal"'), <traceback object at 0x000001E21B6AB280>)
This only happens on Windows (at least not on a Mac), but on Windows it always does :(. Sleeping between inserts makes the problem less likely, but it still appears sometimes.Running kuzu==0.3.2 installed with pip, on Python 3.11 on Window.s