Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
Created October 29, 2020 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdevilopers/ef075c442adac56865533b2feee798ed to your computer and use it in GitHub Desktop.
Save webdevilopers/ef075c442adac56865533b2feee798ed to your computer and use it in GitHub Desktop.
Prooph Event Stream Projection from merged streams event ordering
@webdevilopers
Copy link
Author

MergedStreamIterator.php#L107�\^�]8;;�\ array:2 [
  0 => array:2 [
    0 => Prooph\EventStore\Pdo\PdoStreamIterator�]8;;file:///var/www/rewotec-personnel/vendor/prooph/pdo-event-store/src/PdoStreamIterator.php#L27�\^�]8;;�\ {#90
      -selectStatement: PDOStatement {#115
        +queryString: """
          SELECT * FROM `_d2588481fc670c20e905cc363144708b697ce254` USE INDEX(ix_query_aggregate)\n
          WHERE `no` >= :fromNumber\n
          ORDER BY `no` ASC\n
          LIMIT :limit;
          """
      }
      -countStatement: PDOStatement {#91
        +queryString: """
          SELECT COUNT(*) FROM `_d2588481fc670c20e905cc363144708b697ce254` USE INDEX(ix_query_aggregate)\n
          WHERE `no` >= :fromNumber
          """
      }
      -messageFactory: Prooph\Common\Messaging\FQCNMessageFactory�]8;;file:///var/www/rewotec-personnel/vendor/prooph/common/src/Messaging/FQCNMessageFactory.php#L20�\^�]8;;�\ {#145}
      -currentItem: false
      -currentKey: -1
      -batchPosition: 1
      -batchSize: 10000
      -fromNumber: 5210
      -currentFromNumber: 5210
      -count: null
      -forward: true
    }
    1 => "person_stream"
  ]
  1 => array:2 [
    0 => Prooph\EventStore\Pdo\PdoStreamIterator�]8;;file:///var/www/rewotec-personnel/vendor/prooph/pdo-event-store/src/PdoStreamIterator.php#L27�\^�]8;;�\ {#87
      -selectStatement: PDOStatement {#89
        +queryString: """
          SELECT * FROM `_c1670165c005fb3d12618b6eb4d4c71cf1767117` USE INDEX(ix_query_aggregate)\n
          WHERE `no` >= :fromNumber\n
          ORDER BY `no` ASC\n
          LIMIT :limit;
          """
      }
      -countStatement: PDOStatement {#88
        +queryString: """
          SELECT COUNT(*) FROM `_c1670165c005fb3d12618b6eb4d4c71cf1767117` USE INDEX(ix_query_aggregate)\n
          WHERE `no` >= :fromNumber
          """
      }
      -messageFactory: Prooph\Common\Messaging\FQCNMessageFactory�]8;;file:///var/www/rewotec-personnel/vendor/prooph/common/src/Messaging/FQCNMessageFactory.php#L20�\^�]8;;�\ {#145}
      -currentItem: false
      -currentKey: -1
      -batchPosition: 1
      -batchSize: 10000
      -fromNumber: 8068
      -currentFromNumber: 8068
      -count: null
      -forward: true
    }
    1 => "service_contract_stream"
  ]
]

@webdevilopers
Copy link
Author

Came from:

We are running a projection reading from two streams. I'm dumping the data on the read model methods. As you can see the "contract" comes first with created_at = 2020-02-10 12:53:44, THEN comes the "person" with created_at = 2020-02-10 12:53:07. Any idea?

Screenshot from 2020-10-29 11-38-12

@webdevilopers
Copy link
Author

No #2068 is the "Person Stream" "PersonAdded" Event created at "2020-02-10 12:53:07.000000" and no #4580 is the related "Contract Stream" "ContractEntered" Event created at "2020-02-10 12:53:44.000000".
Code: $projector->fromStreams('person_stream', 'service_contract_stream')...

Screenshot from 2020-10-29 11-33-36
Screenshot from 2020-10-29 11-34-24

The stream order itself is correct - _d2588481fc670c20e905cc363144708b697ce254 = "Person Stream" at 0 and _c1670165c005fb3d12618b6eb4d4c71cf1767117 = "Contract Stream" at 1 -

@webdevilopers
Copy link
Author

How should the behaviour be in a single stream? It looks like it projection runs using the no order instead of created_at. So I guess we have to rewrite our wrongly ordered manually migrated stream.

Screenshot from 2020-10-29 11-49-36
Screenshot from 2020-10-29 11-51-09

@webdevilopers
Copy link
Author

We rewrote the event stream ordered by "created_at" and re-setting the no. The projection now looks as expected.

If I see this correctly then writing a projection fromStreams does not work if one of the streams has inconsistent ordering between no and created_at. Though this should not happen when correctly using the lib. But the mentioned sort does not seem to solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment