-
Notifications
You must be signed in to change notification settings - Fork 614
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
Use with Apartment gem leads to wrong sequence being used on postgresql #233
Comments
@ChrisHampel can you provide some code to demonstrate your import process and maybe some details about your environment? My guess is that you have multiple threads and one is modifying the connection context out from beneath another one. |
we are running 2 puma servers with 16 max threads each, however this still happens with 1 server set to 1 max threads this also happens in rake tasks when we are specifically setting the schema. this is our code, but for security reasons only included the applicable code.
the equivelent code we are currently running is due to this bug:
this is obviously orders of magnitude slower. this all happens in a get request due to the dynamic nature of the data generation, infinite possible instance generated on demand. we first noticed this when we were running a large scale data migration to the new system we built. in that we migrated each schema one at a time:
I hope this information is helpful. |
We're experiencing the same issue with the wrong schema being passed to A little backgroundIf you're using Apartment the way we are (the most common way, with Postgres schemas), The issueThe issue isn't really with activerecord-import, but rather ActiveRecord's behavior with sequence names (I looked at 4.2.7, which is what we're on). The reason some other schema is appearing in activerecord-import's insert statements is because of this caching within Fix/workaroundI don't think that ActiveRecord allows explicitly setting a sequence name, too, which is how I plan on working around this, since we're only using it on one table. I set the
@ChrisHampel, since you're looping dynamically through lots of records, you could set these dynamically using this fallback behavior for |
@mtalcott great find! Do you think calling
|
If I get a chance I will test this, but we ended up not using your library, at this time, due to this weirdness |
Yep, I just verified that |
See also this apartment issue. As this cache is set by Rails it is foremost a Rails problem. Next best place to solve this is the apartment gem. I wrote a hack while that issue is getting solved there (see the linked issue). |
Our software has 1 PostgreSQL schema per company using our software using the Apartments gem most of the time it works but when there is a lot of activity we will get SQL where the apartment gem is selecting the right schema to insert data into, but this gem is saying to use the wrong schema's sequence for the primary key.
For example, we will be doing an import into schema 3 and it will look up the sequence for schema 1 which was used recently by another company
This either results in:
neither of which is preferable since the first will lead to the second eventually unless we intervene and the other just stops saving of the new record all together.
It appears that the sequence being passed in here
activerecord-import/lib/activerecord-import/import.rb
Line 492 in c0a4393
For background information Apartments sets the current schema using the search_path and setting it to:
The text was updated successfully, but these errors were encountered: