Skip to content

Add user interrupt check while waiting for query results to be ready. - #193

Merged
krlmlr merged 6 commits into
r-dbi:masterfrom
zozlak:zozlak
Oct 4, 2018
Merged

krlmlr merged 6 commits into
r-dbi:masterfrom
zozlak:zozlak

Conversation

@zozlak

@zozlak zozlak commented Aug 25, 2018

Copy link
Copy Markdown
Contributor

Sometimes user wants to terminate a query before a first row of results is available (e.g. it turned out that the query is too complicated and he wants to rewrite it instead of waiting for its completion). So far user interrupts where not checked until PQgetResult() completion so the only option to achieve that was to terminate whole R session or to terminate the query on the database server.

This pull requests adds user interrupts check between PQsendQueryPrepared() and PQgetResult().

It is done by waiting for data on the database connection socket with a timeout (1 second) using glibc's select() and running checkUserInterrupt() if the timeout is hit.

… Allows safe interruption of long-running queries.

@krlmlr krlmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! The new code contains some libpq function calls I'm not familiar with, could we make this optional for now?

Comment thread DESCRIPTION Outdated
person("Hadley", "Wickham", role = "aut"),
person("Jeroen", "Ooms", role = "aut"),
person("Kirill", "M\u00fcller", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0002-1416-3412")),
person("Mateusz", "\u017b\u00f3\u0142tak", role = c("ctb")),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In this project, we acknowledge in the NEWS.md file. I'll add an acknowledgment for all contributors to r-dbi repos to the upcoming DBI blog post too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to NEWS.md in d6dcba9

Comment thread src/PqResultImpl.cpp Resolved
@zozlak

zozlak commented Aug 27, 2018

Copy link
Copy Markdown
Contributor Author

The new code contains some libpq function calls I'm not familiar with, could we make this optional for now?

Of course we can. How would you prefer it to be done?

By the way I added a link to the PG documentation in the code and an example of using PQconsumeInput() can be found at https://www.postgresql.org/docs/current/static/libpq-example.html (they don't use PQisBusy() in the example because they are waiting for notifications and not data but the idea is the same)

@krlmlr

krlmlr commented Aug 28, 2018

Copy link
Copy Markdown
Member

Thanks. I think an argument to dbConnect() would be a good way.

Can you please also resolve the conflicts? I can take care of the NEWS entry.

@zozlak

zozlak commented Aug 28, 2018

Copy link
Copy Markdown
Contributor Author

Conflicts removed, adding dbConnect() parameter requires a little more time :)

@zozlak

zozlak commented Aug 30, 2018

Copy link
Copy Markdown
Contributor Author

I've been quite busy last few days, I'll provide the dbConnect() switch during the weekend.

@zozlak

zozlak commented Sep 1, 2018

Copy link
Copy Markdown
Contributor Author

Any idea how to name the parameter?

…f user interrupts should be checked while waiting for the first row of data to be available.
@zozlak

zozlak commented Sep 1, 2018

Copy link
Copy Markdown
Contributor Author

I added it as checkInterrupts but I'm not attached to the name :)

@krlmlr krlmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your PR. I'll tweak myself.

Comment thread src/PqResultImpl.cpp Resolved
Comment thread R/PqConnection.R Resolved
Comment thread NEWS.md Resolved
Comment thread src/PqResultImpl.cpp Resolved
Comment thread src/PqResultImpl.cpp Resolved
Comment thread src/PqResultImpl.cpp Resolved
@krlmlr
krlmlr merged commit 06dde3a into r-dbi:master Oct 4, 2018
@krlmlr

krlmlr commented Oct 4, 2018

Copy link
Copy Markdown
Member

Could you please double-check if the code still works as intended after my tweaks? In master now.

@zozlak

zozlak commented Oct 4, 2018

Copy link
Copy Markdown
Contributor Author

Seems to work fine :)

Just a very minor remark - as you moved the timeval timeout declaration inside the loop in the src/PqResultImpl.cpp:485 it can be written as

timeval timeout = {1, 0};

instead of

timeval timeout = {0, 0};
timeout.tv_sec = 1;

@krlmlr

krlmlr commented Oct 5, 2018

Copy link
Copy Markdown
Member

Thanks. The code is slightly more expressive in the current state, I'm keeping it.

This was referenced Dec 17, 2019
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants