-
Notifications
You must be signed in to change notification settings - Fork 41
Fix autonumbering locking with SQL named locks and Django row locking #7455
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
Open
acwhite211
wants to merge
22
commits into
main
Choose a base branch
from
issue-6490-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6fec1b6
fix autonumbering locking
acwhite211 fe388a8
Merge branch 'main' into issue-6490-1
acwhite211 ccfed12
Lint code with ESLint and Prettier
acwhite211 04512f6
Merge branch 'main' into issue-6490-1
acwhite211 d612278
Lint code with ESLint and Prettier
acwhite211 e604dec
Merge branch 'main' into issue-6490-1
acwhite211 a95ad63
Lint code with ESLint and Prettier
acwhite211 494dcd1
change autonumbering locking naming key to use db_name and table_name
acwhite211 e222a02
try row level locking with django
acwhite211 f5160aa
Add missing autonumbering tables to django model
acwhite211 411ea24
implement lock_ge_range
acwhite211 f1dddc6
add db indexes to help autonumbering range locking
acwhite211 719de2f
Merge branch 'main' into issue-6490-1
acwhite211 bc815be
fix migration after merge
acwhite211 61ddb00
Merge branch 'main' into issue-6490-1
acwhite211 359c152
add PR comment links to lock_tables warning note
acwhite211 3c2437c
remove unneeded autonum tables
acwhite211 5effe3d
remove unused function get_tables_to_lock_strict
acwhite211 a47537e
add more composite indexes for autonumbering
acwhite211 a9a5ea8
fix migration issues
acwhite211 02ab2c3
Remove duplicate invoicenumber index
acwhite211 fb28674
Remove duplicate indexes from migration
acwhite211 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
145 changes: 145 additions & 0 deletions
145
specifyweb/specify/migrations/0042_add_indexes_to_help_autonumbering.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| from django.db import migrations, models | ||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('specify', '0041_add_missing_schema_after_reorganization'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| # accession, accessionnumber, division | ||
| migrations.AddIndex( | ||
| model_name='accession', | ||
| index=models.Index(fields=['division_id', 'accessionnumber'], name='DivAccessionNumberIDX'), | ||
| ), | ||
| # collectionobject, catalognumber, collection | ||
| migrations.AddIndex( | ||
| model_name='collectionobject', | ||
| index=models.Index(fields=['collectionmemberid', 'catalognumber'], name='ColCatalogNumberIDX'), | ||
| ), | ||
| # loan, discipline, loannumber | ||
| migrations.AddIndex( | ||
| model_name='loan', | ||
| index=models.Index(fields=['discipline', 'loannumber'], name='DispLoanNumberIDX'), | ||
| ), | ||
|
|
||
| # borrow, invoicenumber, null | ||
| # migrations.AddIndex( | ||
| # model_name='borrow', | ||
| # index=models.Index(fields=['invoicenumber'], name='BorrowInvoiceNumberIDX'), | ||
| # ), | ||
|
|
||
| # exchangein, exchangeinnumber, division | ||
| migrations.AddIndex( | ||
| model_name='exchangein', | ||
| index=models.Index(fields=['division', 'exchangeinnumber'], name='DivExcInNumberIDX'), | ||
| ), | ||
|
|
||
| # exchangeout, exchangeoutnumber, division | ||
| migrations.AddIndex( | ||
| model_name='exchangeout', | ||
| index=models.Index(fields=['division', 'exchangeoutnumber'], name='DivExcOutNumberIDX'), | ||
| ), | ||
|
|
||
| # collectingevent, stationfieldnumber, discipline | ||
| migrations.AddIndex( | ||
| model_name='collectingevent', | ||
| index=models.Index(fields=['discipline', 'stationfieldnumber'], name='DispStationFieldNumIDX'), | ||
| ), | ||
|
|
||
| # collection, regnumber, discipline | ||
| migrations.AddIndex( | ||
| model_name='collection', | ||
| index=models.Index(fields=['discipline', 'regnumber'], name='DispColRegNumberIDX'), | ||
| ), | ||
|
|
||
| # collector, ordernumber, division | ||
| migrations.AddIndex( | ||
| model_name='collector', | ||
| index=models.Index(fields=['division', 'ordernumber'], name='DivCollectorOrderNumIDX'), | ||
| ), | ||
|
|
||
| # discipline, regnumber, division | ||
| migrations.AddIndex( | ||
| model_name='discipline', | ||
| index=models.Index(fields=['division', 'regnumber'], name='DivDispRegNumberIDX'), | ||
| ), | ||
|
|
||
| # disposal, disposalnumber, null | ||
| # migrations.AddIndex( | ||
| # model_name='disposal', | ||
| # index=models.Index(fields=['disposalnumber'], name='DisposalNumberIDX'), | ||
| # ), | ||
|
|
||
| # division, regnumber, institution | ||
| migrations.AddIndex( | ||
| model_name='division', | ||
| index=models.Index(fields=['institution', 'regnumber'], name='InstDivRegNumberIDX'), | ||
| ), | ||
|
|
||
| # exsiccataitem, number, null | ||
| migrations.AddIndex( | ||
| model_name='exsiccataitem', | ||
| index=models.Index(fields=['number'], name='ExsiccataItemNumberIDX'), | ||
| ), | ||
|
|
||
| # fieldnotebookpage, pagenumber, discipline | ||
| migrations.AddIndex( | ||
| model_name='fieldnotebookpage', | ||
| index=models.Index(fields=['discipline', 'pagenumber'], name='DispFNBPageNumIDX'), | ||
| ), | ||
|
|
||
| # fieldnotebookpageset, ordernumber, discipline | ||
| migrations.AddIndex( | ||
| model_name='fieldnotebookpageset', | ||
| index=models.Index(fields=['discipline', 'ordernumber'], name='DispFNBPageSetNumIDX'), | ||
| ), | ||
|
|
||
| # fundingagent, ordernumber, division | ||
| migrations.AddIndex( | ||
| model_name='fundingagent', | ||
| index=models.Index(fields=['division', 'ordernumber'], name='DivFundingAgentOrderNumIDX'), | ||
| ), | ||
|
|
||
| # gift, giftnumber, discipline | ||
| migrations.AddIndex( | ||
| model_name='gift', | ||
| index=models.Index(fields=['discipline', 'giftnumber'], name='DispGiftNumberIDX'), | ||
| ), | ||
|
|
||
| # groupperson, ordernumber, division | ||
| migrations.AddIndex( | ||
| model_name='groupperson', | ||
| index=models.Index(fields=['division', 'ordernumber'], name='DivGroupPersonOrderNumIDX'), | ||
| ), | ||
|
|
||
| # permit, permitnumber, institution | ||
| migrations.AddIndex( | ||
| model_name='permit', | ||
| index=models.Index(fields=['institution', 'permitnumber'], name='InstPermitNumberIDX'), | ||
| ), | ||
|
|
||
| # referencework, librarynumber, institution | ||
| migrations.AddIndex( | ||
| model_name='referencework', | ||
| index=models.Index(fields=['institution', 'librarynumber'], name='InstRefWorkLibNumIDX'), | ||
| ), | ||
|
|
||
| # repositoryagreement, repositoryagreementnumber, division | ||
| migrations.AddIndex( | ||
| model_name='repositoryagreement', | ||
| index=models.Index(fields=['division', 'repositoryagreementnumber'], name='DivRepoAgreeNumIDX'), | ||
| ), | ||
|
|
||
| # shipment, shipmentnumber, discipline | ||
| migrations.AddIndex( | ||
| model_name='shipment', | ||
| index=models.Index(fields=['discipline', 'shipmentnumber'], name='DispShipmentNumberIDX'), | ||
| ), | ||
|
|
||
| # treatmentevent, treatmentnumber, division | ||
| migrations.AddIndex( | ||
| model_name='treatmentevent', | ||
| index=models.Index(fields=['division', 'treatmentnumber'], name='DivTreatmentNumberIDX'), | ||
| ), | ||
| ] |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(just a note/consideration)
Very nice, glad we're considering some more indices here! 🏆
I would love to see other indices (like those proposed in Add missing field indexes (#7482)) if the benefit of adding them would outweight the cost, although that could definitely be a future PR.
I will warn that indexes can result in a performance loss for write, insert, and delete operations, as each index on a table needs to be maintained (i.e., the B-Tree or similar data structure updated).
In the case of Specify for example, this could slow down (non-negligibly or perhaps even significantly, depending on the index data structure and data being inserted/updated) WorkBench and BatchEdit operations along with common DataEntry operations.
If this is a fine trade-off (such as the case were there will be overall significantly more reads than write and the index is well-structured for the intended optimization), I say shoot for the stars 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, sounds good. I'm looking through the issue, and creating a separate PR for create those specific indexes. The difference for this PR, is that the indexes are always on two values (scoping_field, autonumbering_field). So far we added these two indexes:
For this PR, I'm going through all the proposed indexes and picking out the ones that are common for autonumbering. Let me know if there are any specific ones you want to include?