Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc394bd3

Browse files
committed
Use thread-local storage for querybuffer in fmtId() on Windows, when needed (i.e. when
running pg_restore, which might run in parallel).Only reopen archive file when we really need to read from it, in parallel code. Otherwise,close it immediately in a worker, if possible.
1 parentb4df57f commitc394bd3

File tree

4 files changed

+75
-14
lines changed

4 files changed

+75
-14
lines changed

‎src/bin/pg_dump/dumputils.c

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.44 2009/01/22 20:16:07 tgl Exp $
11+
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.45 2009/03/11 03:33:29 adunstan Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -31,25 +31,72 @@ static char *copyAclUserName(PQExpBuffer output, char *input);
3131
staticvoidAddAcl(PQExpBufferaclbuf,constchar*keyword,
3232
constchar*subname);
3333

34+
#ifdefWIN32
35+
staticboolparallel_init_done= false;
36+
staticDWORDtls_index;
37+
#endif
38+
39+
void
40+
init_parallel_dump_utils(void)
41+
{
42+
#ifdefWIN32
43+
if (!parallel_init_done)
44+
{
45+
tls_index=TlsAlloc();
46+
parallel_init_done= true;
47+
}
48+
#endif
49+
}
3450

3551
/*
36-
*Quotes input string if it's not a legitimate SQL identifier as-is.
52+
*Quotes input string if it's not a legitimate SQL identifier as-is.
3753
*
38-
*Note that the returned string must be used before calling fmtId again,
39-
*since we re-use the same return buffer each time. Non-reentrant but
40-
*avoids memory leakage.
54+
* Note that the returned string must be used before calling fmtId again,
55+
* since we re-use the same return buffer each time. Non-reentrant but
56+
* reduces memory leakage. (On Windows the memory leakage will be one buffer
57+
* per thread, which is at least better than one per call).
4158
*/
4259
constchar*
4360
fmtId(constchar*rawid)
4461
{
45-
staticPQExpBufferid_return=NULL;
62+
/*
63+
* The Tls code goes awry if we use a static var, so we provide for both
64+
* static and auto, and omit any use of the static var when using Tls.
65+
*/
66+
staticPQExpBuffers_id_return=NULL;
67+
PQExpBufferid_return;
68+
4669
constchar*cp;
4770
boolneed_quotes= false;
4871

72+
#ifdefWIN32
73+
if (parallel_init_done)
74+
id_return= (PQExpBuffer)TlsGetValue(tls_index);/* 0 when not set */
75+
else
76+
id_return=s_id_return;
77+
#else
78+
id_return=s_id_return;
79+
#endif
80+
4981
if (id_return)/* first time through? */
82+
{
83+
/* same buffer, just wipe contents */
5084
resetPQExpBuffer(id_return);
85+
}
5186
else
87+
{
88+
/* new buffer */
5289
id_return=createPQExpBuffer();
90+
#ifdefWIN32
91+
if (parallel_init_done)
92+
TlsSetValue(tls_index,id_return);
93+
else
94+
s_id_return=id_return;
95+
#else
96+
s_id_return=id_return;
97+
#endif
98+
99+
}
53100

54101
/*
55102
* These checks need to match the identifier production in scan.l. Don't

‎src/bin/pg_dump/dumputils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.h,v 1.23 2009/01/22 20:16:07 tgl Exp $
11+
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.h,v 1.24 2009/03/11 03:33:29 adunstan Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -19,6 +19,7 @@
1919
#include"libpq-fe.h"
2020
#include"pqexpbuffer.h"
2121

22+
externvoidinit_parallel_dump_utils(void);
2223
externconstchar*fmtId(constchar*identifier);
2324
externvoidappendStringLiteral(PQExpBufferbuf,constchar*str,
2425
intencoding,boolstd_strings);

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.165 2009/03/05 14:51:10 petere Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.166 2009/03/11 03:33:29 adunstan Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -3467,12 +3467,20 @@ parallel_restore(RestoreArgs *args)
34673467

34683468
/*
34693469
* Close and reopen the input file so we have a private file pointer
3470-
* that doesn't stomp on anyone else's file pointer.
3470+
* that doesn't stomp on anyone else's file pointer, if we're actually
3471+
* going to need to read from the file. Otherwise, just close it
3472+
* except on Windows, where it will possibly be needed by other threads.
34713473
*
3472-
* Note: on Windows, since we are using threads not processes, this
3473-
* *doesn't* close the original file pointer but just open a new one.
3474+
* Note: on Windows, since we are using threads not processes, the
3475+
* reopen call *doesn't* close the original file pointer but just open
3476+
* a new one.
34743477
*/
3475-
(AH->ReopenPtr) (AH);
3478+
if (te->section==SECTION_DATA )
3479+
(AH->ReopenPtr) (AH);
3480+
#ifndefWIN32
3481+
else
3482+
(AH->ClosePtr) (AH);
3483+
#endif
34763484

34773485
/*
34783486
* We need our own database connection, too
@@ -3490,7 +3498,9 @@ parallel_restore(RestoreArgs *args)
34903498
PQfinish(AH->connection);
34913499
AH->connection=NULL;
34923500

3493-
(AH->ClosePtr) (AH);
3501+
/* If we reopened the file, we are done with it, so close it now */
3502+
if (te->section==SECTION_DATA )
3503+
(AH->ClosePtr) (AH);
34943504

34953505
if (retval==0&&AH->public.n_errors)
34963506
retval=WORKER_IGNORED_ERRORS;

‎src/bin/pg_dump/pg_restore.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
*
3535
*
3636
* IDENTIFICATION
37-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.94 2009/02/26 16:02:38 petere Exp $
37+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.95 2009/03/11 03:33:29 adunstan Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
4141

4242
#include"pg_backup_archiver.h"
43+
#include"dumputils.h"
4344

4445
#include<ctype.h>
4546

@@ -125,6 +126,8 @@ main(int argc, char **argv)
125126

126127
set_pglocale_pgservice(argv[0],PG_TEXTDOMAIN("pg_dump"));
127128

129+
init_parallel_dump_utils();
130+
128131
opts=NewRestoreOptions();
129132

130133
progname=get_progname(argv[0]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp