As was discussed in VC, the mail_to column of table reports_events in the database mentat_main contains strange or straight erroneous values. Some of these arrays are empty, some e-mails have prepended spaces and there is at least one "None" which seems to be an alternative realisation of empty.
From discussion: It might be the case that the mail_to column is not really accessed after store and could be removed entirely.
Designs
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related.
Learn more.
Some values are Null because the report was never sent. This happens when abuse group wants to receive only "extra" reports. To create an "extra" a "summary" report must be created before that and those "summary" reports aren't sent. I haven't seen any empty arrays ({}). Should empty value be stored as empty array or Null?
Reports with values {None} contain in the mail_res column this:
message transmission error (552 5.3.4 Error: message file too big)Server said: 552 5.3.4 Error: message file too big
The emails with prepended spaces is caused by the same issue as #7215 (closed), so that issue should be solved first.
I think we should keep the mail_to column. After adding mail_cc column, this would solve #7257.
The first question is - it this information actually accessed/used somewhere after write?
In relation to #7257, do I understand it right that this column bears third type of information - what emails the report actually went to, and that this may diverge from what was in the mail headers?
The first question is - it this information actually accessed/used somewhere after write?
Yes. The values of this this attribute/array are shown in the detail of a report, in the tab 'Metadata', row 'Target email'.
In relation to #7257, do I understand it right that this column bears third type of information - what emails the report actually went to, and that this may diverge from what was in the mail headers?
Correct, it stores actual email addresses that the report went to. So for example, on mentat-alt there is always 'root'. Mail headers change either because of the configuration setting or because the abuse group has option 'report redirection' enabled.
we should not have two values representing one state, so let's settle on empty array for generated but unsent reports and migrate column to not null (and update null -> [])
repair known wrong values (strip leading/trailing whitespace, 'none', or maybe check nonconforming emails), where we are pretty sure we won't break good data
Of course, depends on what worms are going to crawl from the can, we can stil reconsider.
we should not have two values representing one state, so let's settle on empty array for generated but unsent reports and migrate column to not null (and update null -> [])
repair known wrong values (strip leading/trailing whitespace, 'none', or maybe check nonconforming emails), where we are pretty sure we won't break good data
Of course, depends on what worms are going to crawl from the can, we can stil reconsider.
I tried solving this issue and I came up with following code. I don't feel confident in writing efficient SQL queries, so can someone check this code?
Of course, there is just a syntactic difference. Both do exactly the same thing, so pick by personal taste. (Warning: I did not run that code).
The case of mail_to = '{None}' represents a situation when the report was generated and was intended to be sent, but that failed (as it happens, always due to the message being too big, but possibly due to other causes). I am against flatly deleting such unsuccessfully sent reports. Setting them to empty array (as the NULL ones) further hides the distinction (from those not intended to be sent), but that should be marked in logs if the case occurred recently and I guess is of diminishing usefulness over time. If it is important, then this might need an additional attribute or logic (I am unsure whether the mail_res is displayed in the UI somewhere).
The created function is left lingering. I would add something like this somewhere towards the end:
DROPFUNCTIONtrim_array(charactervarying[]);
The code as it stands alters all rows of the table. There is little that can be done to prevent this. Some sort of {VACUUM FULL, CLUSTER, pg_repack} should be performed at the end, otherwise the table and especially the indices would remain horribly bloated. The table is small (<750MB on production), so it would take a short time. Of course, this could be just documented and left for the DB admin.
I would advise on prefixing the names of functions used only during migrations (or any other such temporary entities) with some obvious identifier ('alembic_' + alembic migration id?). It is a rare case (this is only the second time we needed any sort of custom function for migration), but that lowers the chance of a naming conflict and better shows the purpose if a forgotten entity is later found in the DB.
I should be available this week for any follow-up.
A review was requested, here are my remarks (in no particular order):
I would use FOREACH for the loop, as follows:
[...]
Of course, there is just a syntactic difference. Both do exactly the same thing, so pick by personal taste. (Warning: I did not run that code).
I tried running the function with this change and I had to change it a bit. array_append returns an array, so I had to reassign the variable. Also, the trim function is returning type text, so I had to cast it to varchar.
The case of mail_to = '{None}' represents a situation when the report was generated and was intended to be sent, but that failed (as it happens, always due to the message being too big, but possibly due to other causes). I am against flatly deleting such unsuccessfully sent reports. Setting them to empty array (as the NULL ones) further hides the distinction (from those not intended to be sent), but that should be marked in logs if the case occurred recently and I guess is of diminishing usefulness over time. If it is important, then this might need an additional attribute or logic (I am unsure whether the mail_res is displayed in the UI somewhere).
Instead of deleting those reports, I changed the mail_to to empty array. Those reports are from 2017, so I don't think they are useful anymore.
The created function is left lingering. I would add something like this somewhere towards the end:
[...]
I would advise on prefixing the names of functions used only during migrations (or any other such temporary entities) with some obvious identifier ('alembic_' + alembic migration id?). It is a rare case (this is only the second time we needed any sort of custom function for migration), but that lowers the chance of a naming conflict and better shows the purpose if a forgotten entity is later found in the DB.
I renamed the function and added the drop statement at the end.
The code as it stands alters all rows of the table. There is little that can be done to prevent this. Some sort of {VACUUM FULL, CLUSTER, pg_repack} should be performed at the end, otherwise the table and especially the indices would remain horribly bloated. The table is small (<750MB on production), so it would take a short time. Of course, this could be just documented and left for the DB admin.
I tried running CLUSTER VERBOSE reports_events on my local machine with 1010 reports and it seems like not much has happened. I will add it to the migration though (without the verbose option). Is it also important in downgrade? The downgrade will only remove the NOT NULL constraint.
It is also worth mentioning that because this task will be merged before #6227 which has some migrations, Alembic merge-branches will be needed at some point.
Thank you so much for your review. The updated version can be found at the end of this note.
No problem.
Instead of deleting those reports, I changed the mail_to to empty array. Those reports are from 2017, so I don't think they are useful anymore.
Yes, they are probably not, but we keep full history there yet and punching holes is against that.
I tried running CLUSTER VERBOSE reports_events on my local machine with 1010 reports and it seems like not much has happened.
The whole table and its indices was rewritten from scratch. On such a small table, it is a quick operation. There are definitely differences in table and index sizes, albeit small. It is also much more efficient to do any operation on the table.
I will add it to the migration though (without the verbose option).
We did not do that before. This should better be discussed before taking action.
Is it also important in downgrade? The downgrade will only remove the NOT NULL constraint.
No, as no modification to table data is done in that case, only a change in table metadata. The removal of NOT NULL constraint is trivial, does not even need a scan (the data is logically guaranteed to be a subset of the new 'constraints').
Here is the updated version:
[...]
Looks good to me.
It is also worth mentioning that because this task will be merged before #6227 which has some migrations, Alembic merge-branches will be needed at some point.
Well, if I am not missing something, the migration from #6227 can still be rebased on this one by changing the down_revision attribute (plus the comments). It is not like that one was deployed anywhere. OK, except for your development environment, but that should be fixable locally and not blocking.
Even this one might need such a 'rebase' as it is blocked by #7215 (closed), which might need a migration of its own.
Instead of deleting those reports, I changed the mail_to to empty array. Those reports are from 2017, so I don't think they are useful anymore.
Is the mail_res displayed somewhere in the report view? If not, maybe it should be added.
mail_res contains basically the same information as mail_to. Moreover, the reports in the last 3 years have this column empty. Even in the current code this attribute is never assigned nor used, so it seems like it was deleted from the code but not from the database.
Is the mail_res displayed somewhere in the report view? If not, maybe it should be added.
mail_res contains basically the same information as mail_to. Moreover, the reports in the last 3 years have this column empty. Even in the current code this attribute is never assigned nor used, so it seems like it was deleted from the code but not from the database.
I made the Alembic migration in 096d69c4. As adding CLUSTER reports_events into the migration file is still to be discussed, I will keep the 'To be discussed' flag set to 'Yes'.
I made the Alembic migration in 096d69c4. As adding CLUSTER reports_events into the migration file is still to be discussed, I will keep the 'To be discussed' flag set to 'Yes'.
I tried running CLUSTER VERBOSE reports_events on my local machine with 1010 reports and it seems like not much has happened.
The whole table and its indices was rewritten from scratch. On such a small table, it is a quick operation. There are definitely differences in table and index sizes, albeit small. It is also much more efficient to do any operation on the table.
I will add it to the migration though (without the verbose option).
We did not do that before. This should better be discussed before taking action.
I think we have already discussed this and settled against adding VACUUM/CLUSTER/ANALYZE into migrations (see #7215 (closed)), also #7538 started from that. We don't have the documentation cleaned up, however if we do not do CLUSTER here - well reporting table is not small, but also not critical, and nothing much happens without optimizing it. So I'd put the notice into the next release notes and call it a day.