Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pg-query-stream module #2035

Merged
merged 80 commits into from
Dec 23, 2019
Merged

Add pg-query-stream module #2035

merged 80 commits into from
Dec 23, 2019

Conversation

brianc
Copy link
Owner

@brianc brianc commented Dec 20, 2019

This uses git subtree as awesomely recommended by @charmander to pull in the history of the pg-query-stream into this module. As was done with #2030 I haven't used lerna to manage sub-module dependencies between this & pg-cursor yet. I'll do that in a follow on PR.

important: need to use merge commit button here to merge this, not squash.

brianc and others added 30 commits October 21, 2013 23:57
Consider a system where one component is scheduling tasks that yield
streams, and passing them to (unknown) clients for consumption.

It would be useful for the scheduler to know that the query
underlying the stream is completed (so it can continue on to it's
next task) without having to wait for the consumer to finish reading
all results.
Emit 'close' events when query completes
pg-cursor no longer returns the empty array 'done' signal to the callback
until the cursor recieves a readyForQuery message.  This means pg-query-stream
will not emit 'close' or 'end' events until the server is __truly__ ready for
the next query.  This fixes some race-conditions where some queries
are triggered off of the `end` event of the query-stream

closes #3
- appears that timestamp queries emit a lot of `rows` with length == 0
- `self.once('end')` is added each of these times
- assertion on listener count shows that more than 10 listeners are applied
- moves 'end' event listener to constructor, only listen once
- ensures all existing tests still green
maxListeners on timestamp queries
brianc and others added 6 commits October 30, 2019 13:03
This includes fixes in [email protected].  I've relaxed semver a touch so I don't have to release a new version here just for patch changes to pg-cursor.
* Bump version of pg-cursor

This includes fixes in [email protected].  I've relaxed semver a touch so I don't have to release a new version here just for patch changes to pg-cursor.

* Pass options to pg-cursor

fixes #55
…d87bfc9035e487e8'

git-subtree-dir: packages/pg-query-stream
git-subtree-mainline: cccf84e
git-subtree-split: 9ced05e
@brianc brianc assigned brianc and charmander and unassigned brianc and charmander Dec 20, 2019
Delete accidental addition
@brianc
Copy link
Owner Author

brianc commented Dec 20, 2019

looks like there's a flaky test on node 8 I'll need to take a look at

@brianc
Copy link
Owner Author

brianc commented Dec 20, 2019

oh wasn't a flaky test it was just running tests from all packages in parallel mode isn't gonna work since they use a postgres instance and some of the tests in the main package cancel all running queries and the like. I was wondering why it was saying "command terminated due to administrative command." Now I know...

@brianc
Copy link
Owner Author

brianc commented Dec 23, 2019

Thanks for the review!

@brianc brianc merged commit bd3efaa into master Dec 23, 2019
@brianc brianc deleted the bmc/add-pg-query-stream branch December 23, 2019 16:49
const query = client.query(stream)
const iteratorRows = []
for await (const row of query) {
iteratorRows.push(row)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should make:

  1. a test that breaks in the first iteration
  2. a test that triggers two breaking loops
  3. a test that await new Promise(r => setTimeout(r)) in the loop body

These tests will fail due to the poor implementation of pg-query

Copy link
Contributor

@matthieusieben matthieusieben Dec 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to brianc/node-pg-query-stream#52 (comment) for an alternative implementation

@matthieusieben
Copy link
Contributor

matthieusieben commented Dec 28, 2019

You really shouldn't have just copied the code from brianc/node-pg-query-stream as it is an invalid implementation of the Readable interface. Using the current implementation breaks the pg connection when used with async iterables.

@brianc
Copy link
Owner Author

brianc commented Dec 28, 2019

You really shouldn't have just copied the code from brianc/node-pg-query-stream as it is an invalid implementation of the Readable interface. Using the current implementation breaks the pg connection when used with async iterables.

Ohhh yeah I wanted to keep the operations discrete: first merge the old repo as is just to keep it contained in a single step, then implement your changes, add tests, release a new version, then convert to typescript, etc....versus doing it all in 1 big bang as it's harder to follow that way for me. Thanks for reminding me though, I'll get to fixing the stream right now!

what do you mean by

a test that triggers two breaking loops?

brianc added a commit that referenced this pull request Dec 28, 2019
There were some subtle behaviors with the stream being implemented incorrectly & not working as expected with async iteration.  I've modified the code based on #2050 and comments in #2035 to have better test coverage of async iterables and update the internals significantly to more closely match the readable stream interface.

Note: this is a __breaking__ (semver major) change to this package as the close event behavior is changed slightly, and `highWaterMark` is no longer supported.  It shouldn't impact most usage, but breaking regardless.
@matthieusieben
Copy link
Contributor

matthieusieben commented Dec 28, 2019

for await (const r of getNewStream()) break
for await (const r of getNewStream()) break

With each stream running a query that results in more than batchSize entries.

(I am on mobile, sorry for the poor example)

@brianc
Copy link
Owner Author

brianc commented Dec 28, 2019 via email

brianc added a commit that referenced this pull request Dec 30, 2019
* Fix pg-query-stream

There were some subtle behaviors with the stream being implemented incorrectly & not working as expected with async iteration.  I've modified the code based on #2050 and comments in #2035 to have better test coverage of async iterables and update the internals significantly to more closely match the readable stream interface.

Note: this is a __breaking__ (semver major) change to this package as the close event behavior is changed slightly, and `highWaterMark` is no longer supported.  It shouldn't impact most usage, but breaking regardless.

* Remove a bunch of additional code

* Add test for destroy + error propagation

* Add failing test for destroying unsubmitted stream

* Do not throw an uncatchable error when closing an unused cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants