On Tue, Oct 25, 2016 at 7:12 PM, Magnus Hagander <mag...@hagander.net> wrote: > On Mon, Oct 24, 2016 at 7:46 AM, Michael Paquier <michael.paqu...@gmail.com> > wrote: >> >> On Sun, Oct 23, 2016 at 10:28 PM, Magnus Hagander <mag...@hagander.net> >> wrote: >> + if (format == 'p') >> + stream.walmethod = CreateWalDirectoryMethod(param->xlog, do_sync); >> + else >> + stream.walmethod = CreateWalTarMethod(param->xlog, >> compresslevel, do_sync); >> LogStreamerMain() exits immediately once it is done, but I think that >> we had better be tidy here and clean up the WAL methods that have been >> allocated. I am thinking here about a potentially retry method on >> failure, though the best shot in this area would be with >> ReceiveXlogStream(). > > Wouldn't the same be needed in pg_receivexlog.c in that case?
Oops, missed that. Thanks for the extra checks. Attached is an updated patch. -- Michael
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 16cab97..e2875df 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -495,6 +495,13 @@ LogStreamerMain(logstreamer_param *param) } PQfinish(param->bgconn); + + if (format == 'p') + FreeWalDirectoryMethod(); + else + FreeWalTarMethod(); + pg_free(stream.walmethod); + return 0; } diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c index bbdf96e..99445e6 100644 --- a/src/bin/pg_basebackup/pg_receivexlog.c +++ b/src/bin/pg_basebackup/pg_receivexlog.c @@ -352,6 +352,10 @@ StreamLog(void) } PQfinish(conn); + + FreeWalDirectoryMethod(); + pg_free(stream.walmethod); + conn = NULL; } diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c index d1dc046..656622f 100644 --- a/src/bin/pg_basebackup/walmethods.c +++ b/src/bin/pg_basebackup/walmethods.c @@ -299,6 +299,13 @@ CreateWalDirectoryMethod(const char *basedir, bool sync) return method; } +void +FreeWalDirectoryMethod(void) +{ + pg_free(dir_data->basedir); + pg_free(dir_data); +} + /*------------------------------------------------------------------------- * WalTarMethod - write wal to a tar file containing pg_xlog contents @@ -611,6 +618,9 @@ tar_sync(Walfile f) Assert(f != NULL); tar_clear_error(); + if (!tar_data->sync) + return 0; + /* * Always sync the whole tarfile, because that's all we can do. This makes * no sense on compressed files, so just ignore those. @@ -842,7 +852,8 @@ tar_finish(void) #endif /* sync the empty blocks as well, since they're after the last file */ - fsync(tar_data->fd); + if (tar_data->sync) + fsync(tar_data->fd); if (close(tar_data->fd) != 0) return false; @@ -890,3 +901,14 @@ CreateWalTarMethod(const char *tarbase, int compression, bool sync) return method; } + +void +FreeWalTarMethod(void) +{ + pg_free(tar_data->tarfilename); +#ifdef HAVE_LIBZ + if (tar_data->compression) + pg_free(tar_data->zlibOut); +#endif + pg_free(tar_data); +} diff --git a/src/bin/pg_basebackup/walmethods.h b/src/bin/pg_basebackup/walmethods.h index 0c8eac7..8cea8ff 100644 --- a/src/bin/pg_basebackup/walmethods.h +++ b/src/bin/pg_basebackup/walmethods.h @@ -43,3 +43,7 @@ struct WalWriteMethod */ WalWriteMethod *CreateWalDirectoryMethod(const char *basedir, bool sync); WalWriteMethod *CreateWalTarMethod(const char *tarbase, int compression, bool sync); + +/* Cleanup routines for previously-created methods */ +void FreeWalDirectoryMethod(void); +void FreeWalTarMethod(void);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers