Processes several queries in FIFO manner, optimized for high throughput. More...
#include <pipeline.hxx>
Classes | |
struct | getquery |
class | Query |
Public Types | |
typedef long | query_id |
Public Member Functions | |
pipeline (transaction_base &, const PGSTD::string &Name=PGSTD::string()) | |
~pipeline () throw () | |
void | cancel () |
Cancel ongoing query, if any. More... | |
const PGSTD::string & | classname () const throw () |
void | complete () |
Wait for all ongoing or pending operations to complete. More... | |
PGSTD::string | description () const |
bool | empty () const throw () |
void | flush () |
Forget all ongoing or pending operations and retrieved results. More... | |
query_id | insert (const PGSTD::string &) |
Add query to the pipeline. More... | |
bool | is_finished (query_id) const |
Is result for given query available? More... | |
const PGSTD::string & | name () const throw () |
void | resume () |
Resume retained query emission (harmless when not needed) More... | |
int | retain (int retain_max=2) |
Set maximum number of queries to retain before issuing them to the backend. More... | |
result | retrieve (query_id qid) |
Retrieve result for given query. More... | |
PGSTD::pair< query_id, result > | retrieve () |
Retrieve oldest unretrieved result (possibly wait for one) More... | |
Protected Member Functions | |
void | reg_pending_error (const PGSTD::string &) throw () |
void | register_me () |
bool | registered () const throw () |
void | unregister_me () throw () |
Protected Attributes | |
transaction_base & | m_Trans |
Private Types | |
typedef PGSTD::map< query_id, Query > | QueryMap |
Private Member Functions | |
pipeline (const pipeline &) | |
Not allowed. More... | |
void | attach () |
void PQXX_PRIVATE | check_end_results () |
void | detach () |
query_id PQXX_PRIVATE | generate_id () |
Create new query_id. More... | |
void PQXX_PRIVATE | get_further_available_results () |
bool | have_pending () const throw () |
void PQXX_PRIVATE PQXX_NORETURN | internal_error (const PGSTD::string &err) throw (PGSTD::logic_error) |
void PQXX_PRIVATE | issue () |
void PQXX_PRIVATE | obtain_dummy () |
bool PQXX_PRIVATE | obtain_result (bool expect_none=false) |
pipeline & | operator= (const pipeline &) |
Not allowed. More... | |
void PQXX_PRIVATE | receive (pipeline::QueryMap::const_iterator stop) |
Receive results, up to stop if possible. More... | |
void PQXX_PRIVATE | receive_if_available () |
Receive any results that happen to be available; it's not urgent. More... | |
PGSTD::pair < pipeline::query_id, result > | retrieve (pipeline::QueryMap::iterator) |
void | set_error_at (query_id qid) throw () |
The given query failed; never issue anything beyond that. More... | |
Static Private Member Functions | |
static query_id | qid_limit () throw () |
Upper bound to query id's. More... | |
Private Attributes | |
bool | m_dummy_pending |
Is there a "dummy query" pending? More... | |
query_id | m_error |
Point at which an error occurred; no results beyond it will be available. More... | |
PGSTD::pair < QueryMap::iterator, QueryMap::iterator > | m_issuedrange |
int | m_num_waiting |
query_id | m_q_id |
QueryMap | m_queries |
int | m_retain |
Processes several queries in FIFO manner, optimized for high throughput.
Use a pipeline if you want to execute queries without always sitting still while they execute. Result retrieval is decoupled from execution request; queries "go in at the front" and results "come out the back." Actually results may be retrieved in any order, if you want.
Feel free to pump as many queries into the pipeline as possible, even if they were generated after looking at a result from the same pipeline. To get the best possible throughput, try to make insertion of queries run as far ahead of results retrieval as possible; issue each query as early as possible and retrieve their results as late as possible, so the pipeline has as many ongoing queries as possible at any given time. In other words, keep it busy!
One warning: if any of the queries you insert leads to a syntactic error, the error may be returned as if it were generated by an older query. Future versions may try to work around this if working in a nontransaction.
typedef long pqxx::pipeline::query_id |
|
private |
|
explicit |
pqxx::pipeline::~pipeline | ( | ) | throw () |
|
private |
Not allowed.
|
private |
void pqxx::pipeline::cancel | ( | ) |
Cancel ongoing query, if any.
May cancel any or all of the queries that have been inserted at this point whose results have not yet been retrieved. If the pipeline lives in a backend transaction, that transaction may be left in a nonfunctional state in which it can only be aborted.
Therefore, either use this function in a nontransaction, or abort the transaction after calling it.
|
private |
|
inlineinherited |
void pqxx::pipeline::complete | ( | ) |
Wait for all ongoing or pending operations to complete.
Detaches from the transaction when done.
|
inherited |
|
private |
|
inline |
void pqxx::pipeline::flush | ( | ) |
Forget all ongoing or pending operations and retrieved results.
Queries already sent to the backend may still be completed, depending on implementation and timing.
Any error state (unless caused by an internal error) will also be cleared. This is mostly useful in a nontransaction, since a backend transaction is aborted automatically when an error occurs.
Detaches from the transaction when done.
|
private |
Create new query_id.
|
private |
|
inlineprivate |
query_id pqxx::pipeline::insert | ( | const PGSTD::string & | ) |
Add query to the pipeline.
Queries are accumulated in the pipeline and sent to the backend in a concatenated format, separated by semicolons. The queries you insert must not use this construct themselves, or the pipeline will get hopelessly confused!
|
private |
bool pqxx::pipeline::is_finished | ( | query_id | ) | const |
Is result for given query available?
|
private |
|
inlineinherited |
|
private |
|
private |
|
inlinestaticprivate |
Upper bound to query id's.
|
private |
Receive results, up to stop if possible.
|
private |
Receive any results that happen to be available; it's not urgent.
|
protectedinherited |
|
protectedinherited |
|
inlineprotectedinherited |
void pqxx::pipeline::resume | ( | ) |
Resume retained query emission (harmless when not needed)
int pqxx::pipeline::retain | ( | int | retain_max = 2 | ) |
Set maximum number of queries to retain before issuing them to the backend.
The pipeline will perform better if multiple queries are issued at once, but retaining queries until the results are needed (as opposed to issuing them to the backend immediately) may negate any performance benefits the pipeline can offer.
Recommended practice is to set this value no higher than the number of queries you intend to insert at a time.
retain_max | A nonnegative "retention capacity;" passing zero will cause queries to be issued immediately |
Retrieve result for given query.
If the query failed for whatever reason, this will throw an exception. The function will block if the query has not finished yet.
References retrieve().
Referenced by retrieve().
Retrieve oldest unretrieved result (possibly wait for one)
|
private |
|
inlineprivate |
The given query failed; never issue anything beyond that.
|
protectedinherited |
|
private |
Is there a "dummy query" pending?
|
private |
Point at which an error occurred; no results beyond it will be available.
|
private |
|
private |
|
private |
|
private |
|
private |
|
protectedinherited |