OJS upgrade from 3.0.2 to 3.1.0-1, stuck on slow query

Hi,

We tried to upgrade our production server with multiple journals from 3.0.2 to 3.1.0-1.

We basically got stuck here: ojs/upgrade.xml at ojs-stable-3_1_0 · pkp/ojs · GitHub
To be precise to this query: ojs/3.1.0_update_a.xml at ojs-stable-3_1_0 · pkp/ojs · GitHub

UPDATE metrics m, submission_file_settings sfs SET m.assoc_id = sfs.file_id WHERE m.assoc_type = 531 AND sfs.setting_name = 'old-supp-id' AND sfs.setting_value = m.assoc_id

Our metrics table has 3,3 million rows and submission_files_settings has 160 000 rows so the inner join command there seems to take for ages? It ran for 2 hours with no result.

The thing is that our metrics table has 0 hits for assoc_type 531, so two questions (@asmecher @bozana)

  1. Should I be worried that there are no 531 rows? Why is that?
  2. Any way of checking the query and making it faster? Of course I can just remove it, but probably others have large metrics tables as well.
1 Like

Ok, so it seems that in ojs/3.1.0_update.xml at ojs-stable-3_1_0 · pkp/ojs · GitHub the script tries to add those 531 assoc_types. However, in the 3.1.0-1 upgrade script the 3.1.0_update_a.xml file is called before 3.1.0_update.xml, so basically the UPDATE query in 3.1.0_update_a.xml never has any hits, it is just a query that takes very very long to finish?

So basically the 3.1.0-1 package is flawed in the way that it does not update the metrics table as expected???

1 Like

Hi @ajnyga,

@bozana is the best person on the team to take a look at this, but just a heads up that she’s away for a week or two.

Regards,
Alec Smecher
Public Knowledge Project Team

Ok, I probably can not wait that long, because we are preparing for another upgrade attempt within two weeks.

I noticed that in the master branch the queries have been removed from 3.1.0_update_a.xml https://github.com/pkp/ojs/blob/master/dbscripts/xml/upgrade/3.1.0_update_a.xml

And they seem to be added to to the 3.1.1 update script here https://github.com/pkp/ojs/blob/master/dbscripts/xml/upgrade/3.1.1_update.xml#L30-L35

That would maybe make more sense because now the 531’s are added in 3.1.0_update.xml and that conversion is then ran in 3.1.1_update.xml.

So I am basically thinking of removing those sql’s from the 3.1.0_update_a script, because I know that there will be no hits, and maybe run a conversion if needed after the actual upgrade.

Hi @ajnyga,

That sounds like a reasonable solution, and I believe the metrics can be re-migrated and processed after an upgrade (though you’d need to make sure you were merging new with old data if your upgrade went live in the meantime).

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @ajnyga

Hmmm… I think the following query would be needed instead of ojs/3.1.0_update_a.xml at ojs-stable-3_1_0 · pkp/ojs · GitHub
UPDATE metrics m, submission_file_settings sfs SET assoc_type = 531, m.assoc_id = sfs.file_id WHERE m.assoc_type = 515 AND sfs.setting_name = 'old-supp-id' AND sfs.setting_value = m.assoc_id.

The changes introduced in 3.0.0_postupgrade_metrics.xml in this commit pkp/pkp-lib#1791 COUNTER plugin by bozana · Pull Request #1370 · pkp/ojs · GitHub and then further in this commit pkp/pkp-lib#3087 fix metrics assoc_type for supp files · pkp/ojs@c6fc29a · GitHub were unfortunately only considered for OJS <= 3.0.1 updates (s. ojs/upgrade.xml at ojs-stable-3_1_0 · pkp/ojs · GitHub and ojs/upgrade.xml at ojs-stable-3_1_0 · pkp/ojs · GitHub) – I forgot to consider them for OJS > 3.0.1 :frowning:
Thus, those query changes from 3.0.0_postupgrade_metrics.xml will not be executed for OJS 3.0.2 :frowning:

And the query ojs/3.1.0_update_a.xml at ojs-stable-3_1_0 · pkp/ojs · GitHub is different from the query ojs/3.1.0_update.xml at ojs-stable-3_1_0 · pkp/ojs · GitHub – it has a different function: the first considers the migrated supp file ids, that have changed after the migration and the second considers the new added supp files, added after the migration.

Does that make sense? Do/did you have the entries with m.assoc_type = 515 AND sfs.setting_name = 'old-supp-id' AND sfs.setting_value = m.assoc_id in your DB table metrics? If so, I can make a PR with the fix…

Thanks a lot and sorry for the late response!
Bozana

No problem @bozana, I just had to proceed with the upgrade because there were so many important features we had promised the journals would have by the beginning of this year.

I have to check the details, but I removed the mentioned sql altogether simply because the WHERE clause it included did not return any hits in our database. I will check this again and get back to you.

Yes, ok so before the update from 3.0.2. to 3.1.0.1. we had no hits for assoc_type 531, so the query did not find anything. That is why I felt that I could remove it and maybe handle this later.

But now after upgrading to 3.1.0.1. there are hits, because ojs/3.1.0_update.xml at ojs-stable-3_1_0 · pkp/ojs · GitHub added those during the upgrade.

Edit: I tried this sql in my database:
SELECT m.assoc_id FROM metrics m, submission_file_settings sfs WHERE m.assoc_type = 515 AND sfs.setting_name = 'old-supp-id' AND sfs.setting_value = m.assoc_id

edit: @bozana, that query does return 190 000 hits (after 30 minutes)

Hi @ajnyga

OK, yes – those are the views of the supp files from OJS 2.4.x and they should have the new assoc_type = 531 (i.e. ASSOC_TYPE_SUBMISSION_FILE_COUNTER_OTHER, because they should not be considered in the COUNTER article or journal report/numbers) instead of assoc_type = 515 (i.e. ASSOC_TYPE_SUBMISSION_FILE, that is considered in the COUNTER article or journal report/numbers). Also the assoc_id should be the new file_id.
I will provide a patch…

Thanks a lot!
Bozana

S. this GitHub Issue: fix metrics assoc_type for supp files for 3.0.2 · Issue #3309 · pkp/pkp-lib · GitHub

Hmmm… I do not know how could this SQL be made so that is more quick :frowning:

Hmmm… @ajnyga, now I do not understand why this code was not applied for you when you were updating to 3.0.2: ojs/3.0.0_postupgrade_metrics.xml at ojs-3_0_2-0 · pkp/ojs · GitHub :open_mouth:
I.e. the SQL
SELECT m.assoc_id FROM metrics m, submission_file_settings sfs WHERE m.assoc_type = 515 AND sfs.setting_name = 'old-supp-id' AND sfs.setting_value = m.assoc_id
should not return any row, because the assoc_ids were already set to file_ids in the 3.0.2 update.
When I see it well, with the upgrade to 3.0.2 you should have assoc_type = 515 and the assoc_id = file_id. Then when upgrading to 3.1.0-1 the code in 3.1.0_update.xml shold change 515 to 531. Thus, after the upgrade to 3.1.0-1 you should have all correct :stuck_out_tongue:
Hmmm… I am so confused… :-\

I am so confused :joy:
I have to look this through in detail. I am not sure you should do any changes based on our database. When I figure out what the situation is, I can always do a custom upgrade script for 3.2. or whatever comes next.

Ok, so I will try to do our 3.1.0.1 to 3.1.1.2 upgrade now and will rerun:

Just before this: ojs/3.1.1_update.xml at ojs-stable-3_1_1 · pkp/ojs · GitHub

So I basically have I slightly modified upgrade script. If I was able to follow this old discussion correctly, that should sort things out in our metrics database.

(edit: realize that this could take a considerable amount of time, maybe around 30-40 hours, but this is hopefully the last of the metrics table migrations at least for a while :smiley:)