sendFileWithContent() does not advance the source pointer

Started by Antonin Houskaover 3 years ago3 messageshackers
Jump to latest
#1Antonin Houska
ah@cybertec.at

When checking something else in the base backup code, I've noticed that
sendFileWithContent() does not advance the 'content' pointer. The sink buffer
is large enough (32kB) so that the first iteration usually processes the whole
file (only special files are processed by this function), and thus that the
problem is hidden.

However it's possible to hit the issue: if there are too many tablespaces,
pg_basebackup generates corrupted tablespace_map. Instead of writing all the
tablespace paths it writes only some and then starts to write the contents
from the beginning again.

The attached script generates scripts to create many tablespaces as well as
the underlying directories. Fix is attached here as well.

--
Antonin Houska
Web: https://www.cybertec-postgresql.com

Attachments:

many.shtext/x-shellscriptDownload
advance_content_pointer.difftext/x-diffDownload+1-0
#2Andres Freund
andres@anarazel.de
In reply to: Antonin Houska (#1)
Re: sendFileWithContent() does not advance the source pointer

Hi,

On 2022-12-08 20:44:05 +0100, Antonin Houska wrote:

When checking something else in the base backup code, I've noticed that
sendFileWithContent() does not advance the 'content' pointer.

Oof. Luckily it looks like that is a relatively recent issue, introduced in
bef47ff85df, which is only in 15.

Greetings,

Andres Freund

#3Robert Haas
robertmhaas@gmail.com
In reply to: Antonin Houska (#1)
Re: sendFileWithContent() does not advance the source pointer

On Thu, Dec 8, 2022 at 2:43 PM Antonin Houska <ah@cybertec.at> wrote:

When checking something else in the base backup code, I've noticed that
sendFileWithContent() does not advance the 'content' pointer. The sink buffer
is large enough (32kB) so that the first iteration usually processes the whole
file (only special files are processed by this function), and thus that the
problem is hidden.

However it's possible to hit the issue: if there are too many tablespaces,
pg_basebackup generates corrupted tablespace_map. Instead of writing all the
tablespace paths it writes only some and then starts to write the contents
from the beginning again.

Thanks for the report, analysis, and fix. I have committed your patch
and back-patched to v15.

--
Robert Haas
EDB: http://www.enterprisedb.com