-
Notifications
You must be signed in to change notification settings - Fork 409
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
Tired: message.assignment_id; Wired: message.campaign_contact_id #1311
Conversation
…t_id; also adds message.messageservice_sid TODO: migration and schema defining the new indexes desired on message
… message.campaign_contact_id
@schuyler1d noticing the test suite is failing here, do you know why? |
The deleted test was replaced by __test__/server/api/createOptOut.test.js
@ibrand the main test test/server/texter.test/correctOptOut.test.js has some loading issues (basically we should fully deprecate To fix this in my branch, I |
nope, it's something else:
I think I see the issue (basically we need to use transactions in twilio.postMessageSave -- after trying to save 'just once' |
ok, tests passing -- letting the default migrations stay transactional in all cases which makes tests pass more easily, and also anyone that has a bigger db to migrate would have to be manually running these migrations anyway. |
@ibrand please review these instructions, but also they would go into wherever we want them for the RELEASE_NOTES. Instructions for migrating large database instances (>1million messages/contacts)
2.1 Create the additional columns:
These should be non-blocking and 'quick' -- i.e. downtime is probably unnecessary. 2.2 Once those complete, you will want to create the campaign_contact_id INDEX:
The CONCURRENTLY adverb should make this possible without downtime, but sometimes caution is best. 2.3 (LOCKING: Best with system unstressed/down) Next you want to start filling in the campaign_contact_id. You may want to prioritize live or recent campaigns with additional qualifications or do this in batches with a command similar to:
Note the "LIMIT 100000" is doing it in batches of 1 million. Another strategy would be to find the lowest campaign_contact_id value for your live campaigns and add a This WILL LOCK the MESSAGE table -- and thus stop processing of events, so you will want to do this off-hours, ideally with the system down. Once you have done this with the majority of messages, especially messages for live campaigns, you should now be ready for real downtime. 2.4 (LOCKING: Requires downtime) The final step is to definitely take the system down if you haven't already. Complete updates to messageservice_sid and campaign_contact_id, there are some final steps:
2.5 Deploy the new code!
NOTES:
|
@schuyler1d Thank you for writing up such thorough instructions! I'm especially into the notes around what locks the tables and what doesn't. One thing that might be helpful to add is to give ballpark time estimates. For example: |
move code from using message.assignment_id => message.campaign_contact_id; also adds message.messageservice_sid
TODO:
Description
Schema changes for better scaling in the prototype scaling branch
Architecture Proposal
This creates a schema change where many places in the code joined
message.assignment_id = campaign_contact.assignment_id AND message.contact_number = campaign_contact.cell
Motivation
This has some negative performance issues:
message
table -- a costly and dangerous thing with high throughputThere is precedence and experience in the Politics Rewired branch
Proposal Details
This varies slightly with the Politics Rewired structure. In ours, we also add a
message.messageservice_sid
column. This allows us to track something in the table that can participate in lookup for an incoming message. In the future orgs (and/or contacts) can have different meessageservice_sids -- this can separate accounting aspects and also how to track different orgs texting the same contact. In Twilio, a messageservice_sid corresponds to the Message Service used. However, it could also be a 'from' number (and is for Nexmo in this PR) -- i.e. anything unique that is known before sending and is identifiable from an incoming message.Deferred/Future Work
Checklist: