Problem/Motivation
On a migration with highwater "changed" handling i experienced that some source items below highwater are imported.
Debugging showed that highwater is saved for every item, while it should only for higher-water items.
Proposed resolution
Fix.
Remaining tasks
Fix
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | drupal-2991756-2-Highwater-malfunction.patch | 1011 bytes | geek-merlin |
Comments
Comment #2
geek-merlinPatch flying in that should fix this.
Comment #3
geek-merlinPatch applies cleanly on a separate box and fixes the problem for me.
The code did not change for ages so patch should work as well against 8.6.x.
Comment #4
heddnHighwater is a tough nut and is a traditional area of bugs. Can we add a test, as we obviously don't have anything that is broken/fixed with this change.
Comment #5
mikeryanThe intent (which was documented for the D7 migrate module, but does not appear to be documented for D8) is that when using highwater marks you need to sort your source data by the field you're using for your highwater. Then, setting the highwater for every row processed guarantees that you don't remigrate stuff, and if the migration is interrupted unexpectedly you don't miss anything. Well, there is a boundary condition if more than one row has the same value in the highwater field - for safety's sake, they'll all be migrated, even if they were before.
For unsorted data, this patch will indeed prevent unnecessary remigration. However, it will cause you to miss rows that *should* be remigrated, if they've changed since the previous migration (i.e., their highwater field's value is higher than the highwater from that migration), if they come after rows with even higher highwater fields.
The general rule of thumb:
Comment #6
quietone commented@mikeryan, thanks. Always love your summaries.
Right, so plugins extending from SqlBase.php do have the orderBy clause automatically added but those extending from SourcePluginBase will not.
Comment #7
mikeryanI've updated the doc page at https://www.drupal.org/docs/8/api/migrate-api/migrate-api-overview#comme.... The high_water_property doc in SourcePluginBase should at a minimum state that sorted source data is required for highwater marks to work correctly. It might also be good to incorporate the rule of thumb above.
Comment #8
heddnI take it then, we need to roll a new patch for the docs, not necessarily change the code in the way we have it listed in the latest patch?
Comment #9
geek-merlinYess, thanks a lot @mikeryan for the explanation in #5, it perfectly makes sense to me (and patch #2 is obsolete).
As of #6:
> Right, so plugins extending from SqlBase.php do have the orderBy clause automatically added but those extending from SourcePluginBase will not.
Ah, in my case i use ContentEntity as source (which derives from SourcePluginBase) and use 'changed' as highwater - not too uncommon. Should we then add a feature request for ContentEntity to sort according to highwater (or add a sort key)?
Comment #10
mikeryanThis issue got me thinking... #2994072: Consolidate migration mechanisms for reimporting changes
Comment #11
mikeryanI was going to say yes, but the code change wouldn't hurt - it would actually be a (very slight) performance improvement in that the highwater mark wouldn't get rewritten when you have multiple rows with the same highwater value. And it would make unsorted data break less (which may not be a good thing - you'd be less likely to notice that it was indeed broken). I don't have a strong opinion on this...
Comment #12
geek-merlin> And it would make unsorted data break less (which may not be a good thing - you'd be less likely to notice that it was indeed broken). I don't have a strong opinion on this...
As you explained in #5, in the case of an interrupted migration this would lead to an invalid system state, and spradic, hard-to-track malfunctions. We should not allow that. If a source plugin uses a highwater property, having it sort by that must be part of the contract. And if it does not, it should not be silently ignored.
This leads to
* change this patch so that a decrease of highwatermark leads to an exception
* fix core source plugins to respect the highwater contract to sort by the configured property
Comment #13
geek-merlinWhat u mean?
Comment #17
narendra.rajwar27Comment #18
narendra.rajwar27Comment #20
quietone commentedThis is not a novice issue and it needs an issue summary update.
Comment #21
wim leersOMG yes, I wrote about this same problem in
#2859314-21: Highwater condition with unjoined maps skips unprocessed and NEEDS_UPDATE rows:
But as you showed here, the problem is even bigger: not only is it saving the high water before a row is processed, it is simply overwriting whatever the previous value was, no matter if it's greater than or lesser than 😨