Re: Pipeline mode and PQpipelineSync() - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Pipeline mode and PQpipelineSync()
Date
Msg-id 202106252352.5ca4byasfun5@alvherre.pgsql
Whole thread Raw
In response to Re: Pipeline mode and PQpipelineSync()  (Alvaro Herrera <alvaro.herrera@2ndquadrant.com>)
Responses Re: Pipeline mode and PQpipelineSync()
List pgsql-hackers
On 2021-Jun-25, Alvaro Herrera wrote:

> From 071757645ee0f9f15f57e43447d7c234deb062c0 Mon Sep 17 00:00:00 2001
> From: Alvaro Herrera <alvherre@alvh.no-ip.org>
> Date: Fri, 25 Jun 2021 16:02:00 -0400
> Subject: [PATCH v2 2/4] Add PQrequestFlush()

I forgot to mention:

> +/*
> + * Send request for server to flush its buffer
> + */
> +int
> +PQrequestFlush(PGconn *conn)
> +{
> +    if (!conn)
> +        return 0;
> +
> +    /* Don't try to send if we know there's no live connection. */
> +    if (conn->status != CONNECTION_OK)
> +    {
> +        appendPQExpBufferStr(&conn->errorMessage,
> +                             libpq_gettext("no connection to the server\n"));
> +        return 0;
> +    }
> +
> +    /* Can't send while already busy, either, unless enqueuing for later */
> +    if (conn->asyncStatus != PGASYNC_IDLE &&
> +        conn->pipelineStatus == PQ_PIPELINE_OFF)
> +    {
> +        appendPQExpBufferStr(&conn->errorMessage,
> +                             libpq_gettext("another command is already in progress\n"));
> +        return false;
> +    }
> +
> +    if (pqPutMsgStart('H', conn) < 0 ||
> +        pqPutMsgEnd(conn) < 0)
> +    {
> +        return 0;
> +    }
> +    /* XXX useless without a flush ...? */
> +    pqFlush(conn);
> +
> +    return 1;
> +}

I'm not sure if it's a good idea for PQrequestFlush to itself flush
libpq's buffer.  We can just document that PQflush is required ...
opinions?

(I didn't try PQrequestFlush in any scenarios other than the test case I
added.)

-- 
Álvaro Herrera       Valdivia, Chile
Voy a acabar con todos los humanos / con los humanos yo acabaré
voy a acabar con todos (bis) / con todos los humanos acabaré ¡acabaré! (Bender)



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Pipeline mode and PQpipelineSync()
Next
From: Michael Paquier
Date:
Subject: Re: [PATCH] Make jsonapi usable from libpq