Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9d23a70

Browse files
committed
pg_dump: get rid of die_horribly
The old code was using exit_horribly or die_horribly other depending on whether it had an ArchiveHandle on which to close the connection or not; but there were places that were passing a NULL ArchiveHandle to die_horribly, and other places that used exit_horribly while having an AH available. So there wasn't all that much consistency. Improve the situation by keeping only one of the routines, and instead of having to pass the AH down from the caller, arrange for it to be present for an on_exit_nicely callback to operate on. Author: Joachim Wieland Some tweaks by me Per a suggestion from Robert Haas, in the ongoing "parallel pg_dump" saga.
1 parent b251cf3 commit 9d23a70

12 files changed

+409
-327
lines changed

src/bin/pg_dump/compress_io.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ EndCompressorZlib(ArchiveHandle *AH, CompressorState *cs)
256256
DeflateCompressorZlib(AH, cs, true);
257257

258258
if (deflateEnd(zp) != Z_OK)
259-
die_horribly(AH, modulename,
260-
"could not close compression stream: %s\n", zp->msg);
259+
exit_horribly(modulename,
260+
"could not close compression stream: %s\n", zp->msg);
261261

262262
free(cs->zlibOut);
263263
free(cs->zp);
@@ -274,8 +274,8 @@ DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs, bool flush)
274274
{
275275
res = deflate(zp, flush ? Z_FINISH : Z_NO_FLUSH);
276276
if (res == Z_STREAM_ERROR)
277-
die_horribly(AH, modulename,
278-
"could not compress data: %s\n", zp->msg);
277+
exit_horribly(modulename,
278+
"could not compress data: %s\n", zp->msg);
279279
if ((flush && (zp->avail_out < cs->zlibOutSize))
280280
|| (zp->avail_out == 0)
281281
|| (zp->avail_in != 0)
@@ -295,9 +295,9 @@ DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs, bool flush)
295295
size_t len = cs->zlibOutSize - zp->avail_out;
296296

297297
if (cs->writeF(AH, out, len) != len)
298-
die_horribly(AH, modulename,
299-
"could not write to output file: %s\n",
300-
strerror(errno));
298+
exit_horribly(modulename,
299+
"could not write to output file: %s\n",
300+
strerror(errno));
301301
}
302302
zp->next_out = (void *) out;
303303
zp->avail_out = cs->zlibOutSize;
@@ -318,7 +318,7 @@ WriteDataToArchiveZlib(ArchiveHandle *AH, CompressorState *cs,
318318

319319
/*
320320
* we have either succeeded in writing dLen bytes or we have called
321-
* die_horribly()
321+
* exit_horribly()
322322
*/
323323
return dLen;
324324
}
@@ -361,8 +361,8 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF)
361361

362362
res = inflate(zp, 0);
363363
if (res != Z_OK && res != Z_STREAM_END)
364-
die_horribly(AH, modulename,
365-
"could not uncompress data: %s\n", zp->msg);
364+
exit_horribly(modulename,
365+
"could not uncompress data: %s\n", zp->msg);
366366

367367
out[ZLIB_OUT_SIZE - zp->avail_out] = '\0';
368368
ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH);
@@ -377,16 +377,16 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF)
377377
zp->avail_out = ZLIB_OUT_SIZE;
378378
res = inflate(zp, 0);
379379
if (res != Z_OK && res != Z_STREAM_END)
380-
die_horribly(AH, modulename,
381-
"could not uncompress data: %s\n", zp->msg);
380+
exit_horribly(modulename,
381+
"could not uncompress data: %s\n", zp->msg);
382382

383383
out[ZLIB_OUT_SIZE - zp->avail_out] = '\0';
384384
ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH);
385385
}
386386

387387
if (inflateEnd(zp) != Z_OK)
388-
die_horribly(AH, modulename,
389-
"could not close compression library: %s\n", zp->msg);
388+
exit_horribly(modulename,
389+
"could not close compression library: %s\n", zp->msg);
390390

391391
free(buf);
392392
free(out);
@@ -426,9 +426,9 @@ WriteDataToArchiveNone(ArchiveHandle *AH, CompressorState *cs,
426426
* do a check here as well...
427427
*/
428428
if (cs->writeF(AH, data, dLen) != dLen)
429-
die_horribly(AH, modulename,
430-
"could not write to output file: %s\n",
431-
strerror(errno));
429+
exit_horribly(modulename,
430+
"could not write to output file: %s\n",
431+
strerror(errno));
432432
return dLen;
433433
}
434434

src/bin/pg_dump/dumputils.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static void AddAcl(PQExpBuffer aclbuf, const char *keyword,
4949
#ifdef WIN32
5050
static bool parallel_init_done = false;
5151
static DWORD tls_index;
52+
static DWORD mainThreadId;
5253
#endif
5354

5455
void
@@ -59,6 +60,7 @@ init_parallel_dump_utils(void)
5960
{
6061
tls_index = TlsAlloc();
6162
parallel_init_done = true;
63+
mainThreadId = GetCurrentThreadId();
6264
}
6365
#endif
6466
}
@@ -1320,5 +1322,9 @@ exit_nicely(int code)
13201322
while (--on_exit_nicely_index >= 0)
13211323
(*on_exit_nicely_list[on_exit_nicely_index].function)(code,
13221324
on_exit_nicely_list[on_exit_nicely_index].arg);
1325+
#ifdef WIN32
1326+
if (parallel_init_done && GetCurrentThreadId() != mainThreadId)
1327+
ExitThread(code);
1328+
#endif
13231329
exit(code);
13241330
}

src/bin/pg_dump/nls.mk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
CATALOG_NAME = pg_dump
33
AVAIL_LANGUAGES = de es fr it ja ko pt_BR sv tr zh_CN zh_TW
44
GETTEXT_FILES = pg_dump.c common.c pg_backup_archiver.c pg_backup_custom.c \
5-
pg_backup_db.c pg_backup_files.c pg_backup_null.c \
5+
pg_backup_db.c pg_backup_null.c \
66
pg_backup_tar.c pg_restore.c pg_dumpall.c \
77
../../port/exec.c
8-
GETTEXT_TRIGGERS = write_msg:2 die_horribly:3 exit_horribly:2 simple_prompt \
9-
ExecuteSqlCommand:3 ahlog:3
8+
GETTEXT_TRIGGERS = write_msg:2 exit_horribly:2 simple_prompt \
9+
ExecuteSqlCommand:3 ahlog:3 warn_or_exit_horribly:3
1010
GETTEXT_FLAGS = \
1111
write_msg:2:c-format \
12-
die_horribly:3:c-format \
1312
exit_horribly:2:c-format \
14-
ahlog:3:c-format
13+
ahlog:3:c-format \
14+
warn_or_exit_horribly:3:c-format

0 commit comments

Comments
 (0)