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+ void StartRestoreBlobs (ArchiveHandle * AH )
601+ {
602+ AH -> blobCount = 0 ;
603+ }
604+
605+ /*
606+ * Called by a format handler after all blobs are restored
607+ */
608+ void EndRestoreBlobs (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 */
596628void StartRestoreBlob (ArchiveHandle * AH , int oid )
597629{
598630 int loOid ;
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/***********
0 commit comments