New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Batch inserts in mysql/mariadb cluster (autoincrement by >1) #3828
Comments
Uf, please simplify before reporting anything, this is crazy. |
You haven't provided anything reproducible, just error message, please try to put together a reproduction as in https://github.com/mikro-orm/mikro-orm/tree/master/tests/issues Closing before you provide one.
Why don't you show the code of what you are doing? :] |
@B4nan my apologies. Its pretty difficult for me to reproduce it because it happens on this specific environment I have. It is working on my another env. I am posting because I have a difficulty to understand on how this error is happening. Meaning that which part should I check on or what usually trigger this error. Thanks a lot for your fast response |
The stack trace shows one thing - the error originated from |
How does
Also I can see one (unrelated) error in your entity definition, you cant do |
I used entity generator to populate those properties because as u can see there are too many columns which I can't avoid. BTW here is the simplified
It works fine on single mariadb instance. The error occured on another env that runs mariadb galera cluster. Anyway I am currently reading and learning about the optimistic locking as you suggested :D |
How does your ORM config look like? Maybe you use global contexts? What versions are you on (if not latest, update)? I dont think entity generator would generate |
The only ORM config I have:
Currently using mikro-orm version Thanks for the advice regarding the entity definition. Will ammend that. |
@B4nan another difference is in galera cluster, the id autoincrement by 3 not 1. I wonder if that may be the cause? |
Hmm interesting, that could be doing some issues. Batch inserts won't work with that in mysql, you'd have to disable those ( |
MySQL is currently the only driver not supporting returning statements, so we expect the PKs to be a sequence and compute them based on the returned inserted id. That happens here: https://github.com/mikro-orm/mikro-orm/blob/master/packages/mysql/src/MySqlDriver.ts#L16 |
So if i disabled |
Well, let's first verify this is the culprit, then we can deal with getting around it. If you dont care about the entity instances and you just need to dump the data into the database, you could use QB with multi insert query. Or you could extend the driver and modify that line yourself. |
Yes after disabling batch insert, it works. With current code, it is 3x slower. So I guess I need to try QB multi-insert and see if performance improve. Thanks a lot for the pointer :D |
We could introduce some dialects here to support this out of box, ideally we could detect it upfront. Let's reopen. |
Please confirm that |
@B4nan yes it returns some values. May I know which wsrep property you are interested in? |
Good. FYI the value should be driven by your cluster side, more about this here: https://galeracluster.com/library/kb/auto-increment-multiples.html |
Yes. And seems like there is a number of factors need to be considered too. But it will be a cool feature :D |
@B4nan i saw this changes have been pushed to master. Is it considered included in the latest version? |
You can already use the dev version, every commit to master is published to NPM |
I have an entity like this:
My use case is I am extracting these row from an excel sheet. By looping each of the row (for loop), I called
persist()
andflush()
it once loop exits.But this error occured:
Further console.log in the compiled code it is due to undefined hash.
Any idea what is the root cause of this? It is pretty deep for me to understand since I am quite new to orm. I also noticed that if I use
persistAndFlush()
each row within the loop, it works. But it is very expensive. Currently we are using mariadb galera cluster with 3 nodes.Thanks!
The text was updated successfully, but these errors were encountered: