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

Commit44954fa

Browse files
committed
Added long-standing transaction when restoring BLOBS (uses commit every BLOB_BATCH_SIZE)
Prevent dumping of languages from template1.
1 parent0babf31 commit44954fa

File tree

8 files changed

+109
-21
lines changed

8 files changed

+109
-21
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
* Modifications - 31-Jul-2000 - pjw@rhyme.com.au (1.46, 1.47)
2424
*Fixed version number initialization in _allocAH (pg_backup_archiver.c)
2525
*
26+
*
27+
* Modifications - 30-Oct-2000 - pjw@rhyme.com.au
28+
*Added {Start,End}RestoreBlobs to allow extended TX during BLOB restore.
29+
*
2630
*-------------------------------------------------------------------------
2731
*/
2832

@@ -590,13 +594,43 @@ int EndBlob(Archive* AHX, int oid)
590594
* BLOB Restoration
591595
**********/
592596

597+
/*
598+
* Called by a format handler before any blobs are restored
599+
*/
600+
voidStartRestoreBlobs(ArchiveHandle*AH)
601+
{
602+
AH->blobCount=0;
603+
}
604+
605+
/*
606+
* Called by a format handler after all blobs are restored
607+
*/
608+
voidEndRestoreBlobs(ArchiveHandle*AH)
609+
{
610+
if (AH->txActive)
611+
{
612+
ahlog(AH,2,"Committing BLOB transactions\n");
613+
CommitTransaction(AH);
614+
}
615+
616+
if (AH->blobTxActive)
617+
{
618+
CommitTransactionXref(AH);
619+
}
620+
621+
ahlog(AH,1,"Restored %d BLOBs\n",AH->blobCount);
622+
}
623+
624+
593625
/*
594626
* Called by a format handler to initiate restoration of a blob
595627
*/
596628
voidStartRestoreBlob(ArchiveHandle*AH,intoid)
597629
{
598630
intloOid;
599631

632+
AH->blobCount++;
633+
600634
if (!AH->createdBlobXref)
601635
{
602636
if (!AH->connection)
@@ -606,7 +640,18 @@ void StartRestoreBlob(ArchiveHandle* AH, int oid)
606640
AH->createdBlobXref=1;
607641
}
608642

609-
StartTransaction(AH);
643+
/*
644+
* Start long-running TXs if necessary
645+
*/
646+
if (!AH->txActive)
647+
{
648+
ahlog(AH,2,"Starting BLOB transactions\n");
649+
StartTransaction(AH);
650+
}
651+
if (!AH->blobTxActive)
652+
{
653+
StartTransactionXref(AH);
654+
}
610655

611656
loOid=lo_creat(AH->connection,INV_READ |INV_WRITE);
612657
if (loOid==0)
@@ -628,7 +673,15 @@ void EndRestoreBlob(ArchiveHandle* AH, int oid)
628673
lo_close(AH->connection,AH->loFd);
629674
AH->writingBlob=0;
630675

631-
CommitTransaction(AH);
676+
/*
677+
* Commit every BLOB_BATCH_SIZE blobs...
678+
*/
679+
if ( ((AH->blobCount /BLOB_BATCH_SIZE)*BLOB_BATCH_SIZE)==AH->blobCount)
680+
{
681+
ahlog(AH,2,"Committing BLOB transactions\n");
682+
CommitTransaction(AH);
683+
CommitTransactionXref(AH);
684+
}
632685
}
633686

634687
/***********

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
6262

6363
#defineK_VERS_MAJOR 1
6464
#defineK_VERS_MINOR 4
65-
#defineK_VERS_REV21
65+
#defineK_VERS_REV22
6666

6767
/* Data block types */
6868
#defineBLK_DATA 1
@@ -76,6 +76,9 @@ typedef z_stream *z_streamp;
7676
#defineK_VERS_1_4 (( (1 * 256 + 4) * 256 + 0) * 256 + 0)/* Date & name in header */
7777
#defineK_VERS_MAX (( (1 * 256 + 4) * 256 + 255) * 256 + 0)
7878

79+
/* No of BLOBs to restore in 1 TX */
80+
#defineBLOB_BATCH_SIZE100
81+
7982
struct_archiveHandle;
8083
struct_tocEntry;
8184
struct_restoreList;
@@ -186,13 +189,16 @@ typedef struct _archiveHandle {
186189
char*pgport;
187190
PGconn*connection;
188191
PGconn*blobConnection;/* Connection for BLOB xref */
192+
inttxActive;/* Flag set if TX active on connection */
193+
intblobTxActive;/* Flag set if TX active on blobConnection */
189194
intconnectToDB;/* Flag to indicate if direct DB connection is required */
190195
intpgCopyIn;/* Currently in libpq 'COPY IN' mode. */
191196
PQExpBufferpgCopyBuf;/* Left-over data from incomplete lines in COPY IN */
192197

193198
intloFd;/* BLOB fd */
194199
intwritingBlob;/* Flag */
195200
intcreatedBlobXref;/* Flag */
201+
intblobCount;/* # of blobs restored */
196202

197203
intlastID;/* Last internal ID for a TOC entry */
198204
char*fSpec;/* Archive File Spec */
@@ -256,8 +262,10 @@ extern int ReadInt(ArchiveHandle* AH);
256262
externchar*ReadStr(ArchiveHandle*AH);
257263
externintWriteStr(ArchiveHandle*AH,char*s);
258264

265+
externvoidStartRestoreBlobs(ArchiveHandle*AH);
259266
externvoidStartRestoreBlob(ArchiveHandle*AH,intoid);
260267
externvoidEndRestoreBlob(ArchiveHandle*AH,intoid);
268+
externvoidEndRestoreBlobs(ArchiveHandle*AH);
261269

262270
externvoidInitArchiveFmt_Custom(ArchiveHandle*AH);
263271
externvoidInitArchiveFmt_Files(ArchiveHandle*AH);

‎src/bin/pg_dump/pg_backup_custom.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ static void_LoadBlobs(ArchiveHandle* AH)
585585
{
586586
intoid;
587587

588+
StartRestoreBlobs(AH);
589+
588590
oid=ReadInt(AH);
589591
while(oid!=0)
590592
{
@@ -593,6 +595,9 @@ static void_LoadBlobs(ArchiveHandle* AH)
593595
EndRestoreBlob(AH,oid);
594596
oid=ReadInt(AH);
595597
}
598+
599+
EndRestoreBlobs(AH);
600+
596601
}
597602

598603
/*
@@ -608,8 +613,8 @@ static void_skipBlobs(ArchiveHandle* AH)
608613
oid=ReadInt(AH);
609614
while(oid!=0)
610615
{
611-
_skipData(AH);
612-
oid=ReadInt(AH);
616+
_skipData(AH);
617+
oid=ReadInt(AH);
613618
}
614619
}
615620

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,17 @@ void StartTransaction(ArchiveHandle* AH)
675675
appendPQExpBuffer(qry,"Begin;");
676676

677677
ExecuteSqlCommand(AH,qry,"can not start database transaction");
678+
AH->txActive= true;
679+
}
680+
681+
voidStartTransactionXref(ArchiveHandle*AH)
682+
{
683+
PQExpBufferqry=createPQExpBuffer();
684+
685+
appendPQExpBuffer(qry,"Begin;");
686+
687+
_executeSqlCommand(AH,AH->blobConnection,qry,"can not start BLOB xref transaction");
688+
AH->blobTxActive= true;
678689
}
679690

680691
voidCommitTransaction(ArchiveHandle*AH)
@@ -684,6 +695,15 @@ void CommitTransaction(ArchiveHandle* AH)
684695
appendPQExpBuffer(qry,"Commit;");
685696

686697
ExecuteSqlCommand(AH,qry,"can not commit database transaction");
698+
AH->txActive= false;
687699
}
688700

701+
voidCommitTransactionXref(ArchiveHandle*AH)
702+
{
703+
PQExpBufferqry=createPQExpBuffer();
689704

705+
appendPQExpBuffer(qry,"Commit;");
706+
707+
_executeSqlCommand(AH,AH->blobConnection,qry,"can not commit BLOB xref transaction");
708+
AH->blobTxActive= false;
709+
}

‎src/bin/pg_dump/pg_backup_db.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ extern int ExecuteSqlCommandBuf(ArchiveHandle* AH, void *qry, int bufLen);
1212
externvoidCreateBlobXrefTable(ArchiveHandle*AH);
1313
externvoidInsertBlobXref(ArchiveHandle*AH,intold,intnew);
1414
externvoidStartTransaction(ArchiveHandle*AH);
15+
externvoidStartTransactionXref(ArchiveHandle*AH);
1516
externvoidCommitTransaction(ArchiveHandle*AH);
17+
externvoidCommitTransactionXref(ArchiveHandle*AH);
1618

‎src/bin/pg_dump/pg_backup_files.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ static void_LoadBlobs(ArchiveHandle* AH, RestoreOptions *ropt)
318318
lclContext*ctx= (lclContext*)AH->formatData;
319319
charfname[K_STD_BUF_SIZE];
320320

321+
StartRestoreBlobs(AH);
322+
321323
ctx->blobToc=fopen("blobs.toc",PG_BINARY_R);
322324

323325
_getBlobTocEntry(AH,&oid,fname);
@@ -331,6 +333,8 @@ static void_LoadBlobs(ArchiveHandle* AH, RestoreOptions *ropt)
331333
}
332334

333335
fclose(ctx->blobToc);
336+
337+
EndRestoreBlobs(AH);
334338
}
335339

336340

‎src/bin/pg_dump/pg_backup_tar.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ static void_LoadBlobs(ArchiveHandle* AH, RestoreOptions *ropt)
627627
intcnt;
628628
charbuf[4096];
629629

630+
StartRestoreBlobs(AH);
631+
630632
th=tarOpen(AH,NULL,'r');/* Open next file */
631633
while (th!=NULL)
632634
{
@@ -652,21 +654,8 @@ static void_LoadBlobs(ArchiveHandle* AH, RestoreOptions *ropt)
652654
th=tarOpen(AH,NULL,'r');
653655
}
654656

655-
/*
656-
* ctx->blobToc = tarOpen(AH, "blobs.toc", 'r');
657-
*
658-
* _getBlobTocEntry(AH, &oid, fname);
659-
*
660-
* while(oid != 0)
661-
* {
662-
*StartRestoreBlob(AH, oid);
663-
*_PrintFileData(AH, fname, ropt);
664-
*EndRestoreBlob(AH, oid);
665-
*_getBlobTocEntry(AH, &oid, fname);
666-
* }
667-
*
668-
* tarClose(AH, ctx->blobToc);
669-
*/
657+
EndRestoreBlobs(AH);
658+
670659
}
671660

672661

‎src/bin/pg_dump/pg_dump.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.176 2000/10/24 13:24:30 pjw Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.177 2000/10/31 14:20:30 pjw Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -2872,6 +2872,7 @@ dumpProcLangs(Archive *fout, FuncInfo *finfo, int numFuncs,
28722872
inti_lanpltrusted;
28732873
inti_lanplcallfoid;
28742874
inti_lancompiler;
2875+
Oidlanoid;
28752876
char*lanname;
28762877
char*lancompiler;
28772878
constchar*lanplcallfoid;
@@ -2898,7 +2899,13 @@ dumpProcLangs(Archive *fout, FuncInfo *finfo, int numFuncs,
28982899

28992900
for (i=0;i<ntups;i++)
29002901
{
2902+
lanoid=atoi(PQgetvalue(res,i,i_oid));
2903+
if (lanoid <=g_last_builtin_oid)
2904+
continue;
2905+
29012906
lanplcallfoid=PQgetvalue(res,i,i_lanplcallfoid);
2907+
2908+
29022909
for (fidx=0;fidx<numFuncs;fidx++)
29032910
{
29042911
if (!strcmp(finfo[fidx].oid,lanplcallfoid))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp