Problem/Motivation

The query condition for highwater is only added when the map is ignored or the map is joinable.

Proposed resolution

Set the $condition_added flag to true in the high water if block. That way the following test on that flag will cause the highwater condition to be added to the query for all cases.

Remaining tasks

Make a follow to check if this patch will break update migrations. See #21.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

---
The original IS:

Sorry folks I have no enough time to document everything right.

Here:
https://github.com/drupal/drupal/blob/8.2.x/core/modules/migrate/src/Plu...
— the condition is not really added since `$condition_added` is not set to `TRUE`. It would e.g. on a local database (see the line 197), but if the source database is not 'joinable' `$condition_added` just gets no chances.

The patch:

diff --git a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
index 0eac141..6bf48b4 100644
--- a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
+++ b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
@@ -216,6 +216,7 @@ protected function initializeIterator() {
       $high_water_field = $this->getHighWaterField();
       $conditions->condition($high_water_field, $high_water, '>');
       $this->query->orderBy($high_water_field);
+      $condition_added = TRUE;
     }
     if ($condition_added) {
       $this->query->condition($conditions);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

OnkelTem created an issue. See original summary.

OnkelTem’s picture

Issue summary: View changes
iMiksu’s picture

Status: Needs review » Needs work
Issue tags: +Novice

I've updated it back to active as we need to provide a proper patch so that we can let bots to run the tests. See Making a Drupal patch with Git.

Novice task: Can anyone provide the patch file that @OnkelTem has described in summary?

iMiksu’s picture

Also we need steps to reproduce the problem.

quietone’s picture

mikeryan’s picture

Issue tags: +Needs tests

Can we get a fail test demonstrating the problem?

That test will not be a novice task...

faline’s picture

Status: Needs work » Needs review
FileSize
640 bytes

Create a patch file that @OnkelTem described in summary.

Status: Needs review » Needs work

The last submitted patch, 7: highwater_condition-2824267-7.patch, failed testing.

quietone’s picture

Well, here is an attempt at a fail patch. The problem is it still fails with the fix! And just like #7 it fails on asserting the expected count with plugin count. And the failing test in #7, CommentSourceWithHighWaterTest and this one, HighWaterNotJoinableTest, use different test classes. CommentSourceWithHighWaterTest uses MigrateSqlSourceTestCase and #9 uses MigrateSqlSourceTestBase.

It seems that CommentSourceWithHighWaterTest executes SqlBase::initializeIterator and setups the query correctly to return a count of 1, but something changes that to 0. And then HighWaterNotJoinableTest does not execute SqlBase::initializeIterator so the count will always not take into account the high water mark. This is confusing to me.

The last submitted patch, 9: highwater_condition-2824267-9-fail.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 9: highwater_condition-2824267-9.patch, failed testing.

quietone’s picture

Issue tags: -Novice

Results as expected. Removing novice tag.

quietone’s picture

Changed the expected count test to use iterator_count.

The last submitted patch, 13: highwater_condition-2824267-13-fail.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 13: highwater_condition-2824267-13.patch, failed testing.

quietone’s picture

Now we see that the high water value was not initialized properly in MigrateSqlSourceTestCase. Well it was, until #2485385: Move highwater field support to the source plugin, and do not expose its internals on MigrationInterface was committed. With that fixed, this should pass tests now.

The last submitted patch, 16: highwater_condition-2824267-16-fail.patch, failed testing.

mikeryan’s picture

Assigned: Unassigned » mikeryan
mikeryan’s picture

Status: Needs review » Reviewed & tested by the community

So many test LOC for a one-line fix!

Looks good to me...

mikeryan’s picture

Assigned: mikeryan » Unassigned
ohthehugemanatee’s picture

This patch will break update migrations, I think.

Update migrations work by marking everything in the map as needs_update, joining the map to the source, and adding a condition to the source query to include anything with needs_update set. With this patch, if you run an update migration that has a highwater mark set, you will exclude all the rows below the highwater mark.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Needs a reroll and #21 needs answering. Also the issue summary update does not appear to have been done.

shashikant_chauhan’s picture

updated the patch.

moshe weitzman’s picture

This should be fixed. Unfortunately, it will highlight an existing problem - #2844595: SQLBase breaks GROUP BY queries

quietone’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update +blocker
FileSize
6.43 KB

Working on the items in #22. The reroll has been done and setting to NR for testing. The IS has been done.

The remaining item is to address that concern that this will break update migrations. See #21. For that, can we open a follow up?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quietone’s picture

Status: Needs review » Needs work

Setting to NW due to #21.

quietone’s picture

RE #21.

This patch will break update migrations, I think.

I don't think so. The highwater condition is included in an OR condition group. The final query created complies with the comment in SqlBase::initializeIterator.

      //    like (original conditions) AND (map IS NULL OR map needs update
      //      OR above high water).
quietone’s picture

Status: Needs work » Needs review
FileSize
8.67 KB
3.55 KB

Now with a test for highwater when rows are marked for update.

ohthehugemanatee’s picture

Well blow me over with a feather. :)
When I tested by hand as a part of #2841262: Highwater only modifies the Sql query when map table is joinable, including --update in the drush command didn't prompt a review of all nodes. The test looks good to me, though, and clearly comes back green.

What I don't understand, is how does this work when the map is NOT joinable? If mapJoinable() returns FALSE, the query conditions look like: "(original conditions) AND (above high water)." How do we know which rows have NEEDS_UPDATE set?

In any case I think it's safe to split this off into a separate issue if it is even a real problem.

phenaproxima’s picture

I like the change to MigrateSqlSourceTestBase. Looks great. Was meaning to do that myself all along, but was waiting for a use case. And here it is. Full steam ahead! You have my blessing.

mikeryan’s picture

Assigned: Unassigned » mikeryan
mikeryan’s picture

What I don't understand, is how does this work when the map is NOT joinable? If mapJoinable() returns FALSE, the query conditions look like: "(original conditions) AND (above high water)." How do we know which rows have NEEDS_UPDATE set?

In any case I think it's safe to split this off into a separate issue if it is even a real problem.

I think you're right - we only want to add the highwater condition when we're joining to the map, otherwise we need to fallback to the SourcePluginBase iterating the full query and testing NEEDS_UPDATE and highwater marks as it goes. Might be as simple as just moving the highwater condition inside the joinable condition...

I'm going back-and-forth on doing that here versus a follow-up, thoughts?

quietone’s picture

I'm going back-and-forth on doing that here versus a follow-up, thoughts?

Since this is a blocker, I go with followup.

mikeryan’s picture

Assigned: mikeryan » Unassigned
Status: Needs review » Reviewed & tested by the community

Followup created: #2859314: Highwater condition with unjoined maps skips unprocessed and NEEDS_UPDATE rows. This patch looks good to me for its scope.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 8fa8911 to 8.4.x and bd6b010 to 8.3.x. Thanks!

  • alexpott committed 8fa8911 on 8.4.x
    Issue #2824267 by quietone, shashikant_chauhan, faline, mikeryan,...

  • alexpott committed bd6b010 on 8.3.x
    Issue #2824267 by quietone, shashikant_chauhan, faline, mikeryan,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Wim Leers’s picture

The problem that @ohthehugemanatee identified in #30 is much more severe than it was made out to be in this issue. See #2859314-20: Highwater condition with unjoined maps skips unprocessed and NEEDS_UPDATE rows and subsequent comments.