~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/bin/pg_dump/pg_backup_archiver.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 *
17
17
 * IDENTIFICATION
18
 
 *              $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.170 2009/04/12 21:02:44 adunstan Exp $
 
18
 *              $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.172 2009/06/11 14:49:07 momjian Exp $
19
19
 *
20
20
 *-------------------------------------------------------------------------
21
21
 */
62
62
typedef struct _restore_args
63
63
{
64
64
        ArchiveHandle *AH;
65
 
        TocEntry      *te;
 
65
        TocEntry   *te;
66
66
} RestoreArgs;
67
67
 
68
68
typedef struct _parallel_slot
111
111
static void ResetOutput(ArchiveHandle *AH, OutputContext savedContext);
112
112
 
113
113
static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
114
 
                                                         RestoreOptions *ropt, bool is_parallel);
 
114
                                  RestoreOptions *ropt, bool is_parallel);
115
115
static void restore_toc_entries_parallel(ArchiveHandle *AH);
116
116
static thandle spawn_restore(RestoreArgs *args);
117
117
static thandle reap_child(ParallelSlot *slots, int n_slots, int *work_status);
118
118
static bool work_in_progress(ParallelSlot *slots, int n_slots);
119
 
static int get_next_slot(ParallelSlot *slots, int n_slots);
 
119
static int      get_next_slot(ParallelSlot *slots, int n_slots);
120
120
static TocEntry *get_next_work_item(ArchiveHandle *AH,
121
 
                                                                        TocEntry **first_unprocessed,
122
 
                                                                        ParallelSlot *slots, int n_slots);
 
121
                                   TocEntry **first_unprocessed,
 
122
                                   ParallelSlot *slots, int n_slots);
123
123
static parallel_restore_result parallel_restore(RestoreArgs *args);
124
124
static void mark_work_done(ArchiveHandle *AH, thandle worker, int status,
125
 
                                                   ParallelSlot *slots, int n_slots);
 
125
                           ParallelSlot *slots, int n_slots);
126
126
static void fix_dependencies(ArchiveHandle *AH);
127
127
static bool has_lock_conflicts(TocEntry *te1, TocEntry *te2);
128
128
static void repoint_table_dependencies(ArchiveHandle *AH,
129
 
                                                                           DumpId tableId, DumpId tableDataId);
 
129
                                                   DumpId tableId, DumpId tableDataId);
130
130
static void identify_locking_dependencies(TocEntry *te,
131
 
                                                                                  TocEntry **tocsByDumpId);
 
131
                                                          TocEntry **tocsByDumpId);
132
132
static void reduce_dependencies(ArchiveHandle *AH, TocEntry *te);
133
133
static void mark_create_done(ArchiveHandle *AH, TocEntry *te);
134
134
static void inhibit_data_for_failed_table(ArchiveHandle *AH, TocEntry *te);
211
211
                die_horribly(AH, modulename, "-C and -c are incompatible options\n");
212
212
 
213
213
        /*
214
 
         * -1 is not compatible with -C, because we can't create a database
215
 
         *  inside a transaction block.
 
214
         * -1 is not compatible with -C, because we can't create a database inside
 
215
         * a transaction block.
216
216
         */
217
217
        if (ropt->create && ropt->single_txn)
218
218
                die_horribly(AH, modulename, "-C and -1 are incompatible options\n");
221
221
         * Make sure we won't need (de)compression we haven't got
222
222
         */
223
223
#ifndef HAVE_LIBZ
224
 
        if (AH->compression != 0 && AH->PrintTocDataPtr != NULL)
 
224
        if (AH->compression != 0 && AH->PrintTocDataPtr !=NULL)
225
225
        {
226
226
                for (te = AH->toc->next; te != AH->toc; te = te->next)
227
227
                {
420
420
restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
421
421
                                  RestoreOptions *ropt, bool is_parallel)
422
422
{
423
 
        int         retval = 0;
 
423
        int                     retval = 0;
424
424
        teReqs          reqs;
425
425
        bool            defnDumped;
426
426
 
440
440
 
441
441
        defnDumped = false;
442
442
 
443
 
        if ((reqs & REQ_SCHEMA) != 0)   /* We want the schema */
 
443
        if ((reqs & REQ_SCHEMA) != 0)           /* We want the schema */
444
444
        {
445
445
                ahlog(AH, 1, "creating %s %s\n", te->desc, te->tag);
446
446
 
452
452
                        if (AH->lastErrorTE == te)
453
453
                        {
454
454
                                /*
455
 
                                 * We failed to create the table.
456
 
                                 * If --no-data-for-failed-tables was given,
457
 
                                 * mark the corresponding TABLE DATA to be ignored.
 
455
                                 * We failed to create the table. If
 
456
                                 * --no-data-for-failed-tables was given, mark the
 
457
                                 * corresponding TABLE DATA to be ignored.
458
458
                                 *
459
 
                                 * In the parallel case this must be done in the parent,
460
 
                                 * so we just set the return value.
 
459
                                 * In the parallel case this must be done in the parent, so we
 
460
                                 * just set the return value.
461
461
                                 */
462
462
                                if (ropt->noDataForFailedTables)
463
463
                                {
470
470
                        else
471
471
                        {
472
472
                                /*
473
 
                                 * We created the table successfully.  Mark the
474
 
                                 * corresponding TABLE DATA for possible truncation.
 
473
                                 * We created the table successfully.  Mark the corresponding
 
474
                                 * TABLE DATA for possible truncation.
475
475
                                 *
476
 
                                 * In the parallel case this must be done in the parent,
477
 
                                 * so we just set the return value.
 
476
                                 * In the parallel case this must be done in the parent, so we
 
477
                                 * just set the return value.
478
478
                                 */
479
479
                                if (is_parallel)
480
480
                                        retval = WORKER_CREATE_DONE;
498
498
        if ((reqs & REQ_DATA) != 0)
499
499
        {
500
500
                /*
501
 
                 * hadDumper will be set if there is genuine data component for
502
 
                 * this node. Otherwise, we need to check the defn field for
503
 
                 * statements that need to be executed in data-only restores.
 
501
                 * hadDumper will be set if there is genuine data component for this
 
502
                 * node. Otherwise, we need to check the defn field for statements
 
503
                 * that need to be executed in data-only restores.
504
504
                 */
505
505
                if (te->hadDumper)
506
506
                {
507
507
                        /*
508
508
                         * If we can output the data, then restore it.
509
509
                         */
510
 
                        if (AH->PrintTocDataPtr != NULL && (reqs & REQ_DATA) != 0)
 
510
                        if (AH->PrintTocDataPtr !=NULL && (reqs & REQ_DATA) != 0)
511
511
                        {
512
512
                                _printTocEntry(AH, te, ropt, true, false);
513
513
 
532
532
                                                  te->tag);
533
533
 
534
534
                                        /*
535
 
                                         * In parallel restore, if we created the table earlier
536
 
                                         * in the run then we wrap the COPY in a transaction and
537
 
                                         * precede it with a TRUNCATE.  If archiving is not on
538
 
                                         * this prevents WAL-logging the COPY.  This obtains a
539
 
                                         * speedup similar to that from using single_txn mode
540
 
                                         * in non-parallel restores.
 
535
                                         * In parallel restore, if we created the table earlier in
 
536
                                         * the run then we wrap the COPY in a transaction and
 
537
                                         * precede it with a TRUNCATE.  If archiving is not on
 
538
                                         * this prevents WAL-logging the COPY.  This obtains a
 
539
                                         * speedup similar to that from using single_txn mode in
 
540
                                         * non-parallel restores.
541
541
                                         */
542
542
                                        if (is_parallel && te->created)
543
543
                                        {
559
559
                                        }
560
560
 
561
561
                                        /*
562
 
                                         * If we have a copy statement, use it. As of V1.3,
563
 
                                         * these are separate to allow easy import from
564
 
                                         * withing a database connection. Pre 1.3 archives can
565
 
                                         * not use DB connections and are sent to output only.
 
562
                                         * If we have a copy statement, use it. As of V1.3, these
 
563
                                         * are separate to allow easy import from withing a
 
564
                                         * database connection. Pre 1.3 archives can not use DB
 
565
                                         * connections and are sent to output only.
566
566
                                         *
567
 
                                         * For V1.3+, the table data MUST have a copy
568
 
                                         * statement so that we can go into appropriate mode
569
 
                                         * with libpq.
 
567
                                         * For V1.3+, the table data MUST have a copy statement so
 
568
                                         * that we can go into appropriate mode with libpq.
570
569
                                         */
571
570
                                        if (te->copyStmt && strlen(te->copyStmt) > 0)
572
571
                                        {
807
806
                                         te->tag, te->owner);
808
807
                if (ropt->verbose && te->nDeps > 0)
809
808
                {
810
 
                        int             i;
 
809
                        int                     i;
811
810
 
812
811
                        ahprintf(AH, ";\tdepends on:");
813
812
                        for (i = 0; i < te->nDeps; i++)
1235
1234
 
1236
1235
                res = lo_write(AH->connection, AH->loFd, AH->lo_buf, AH->lo_buf_used);
1237
1236
                ahlog(AH, 5, ngettext("wrote %lu byte of large object data (result = %lu)\n",
1238
 
                                                          "wrote %lu bytes of large object data (result = %lu)\n",
 
1237
                                         "wrote %lu bytes of large object data (result = %lu)\n",
1239
1238
                                                          AH->lo_buf_used),
1240
1239
                          (unsigned long) AH->lo_buf_used, (unsigned long) res);
1241
1240
                if (res != AH->lo_buf_used)
1786
1785
        else
1787
1786
                AH->lookaheadLen = 0;   /* Don't bother since we've reset the file */
1788
1787
 
1789
 
#if 0
1790
 
        write_msg(modulename, ngettext("read %lu byte into lookahead buffer\n",
1791
 
                                                                   "read %lu bytes into lookahead buffer\n",
1792
 
                                                                   AH->lookaheadLen),
1793
 
                          (unsigned long) AH->lookaheadLen);
1794
 
#endif
1795
 
 
1796
1788
        /* Close the file */
1797
1789
        if (wantClose)
1798
1790
                if (fclose(fh) != 0)
2322
2314
static void
2323
2315
_doSetFixedOutputState(ArchiveHandle *AH)
2324
2316
{
2325
 
        /* Disable statement_timeout in archive for pg_restore/psql      */
 
2317
        /* Disable statement_timeout in archive for pg_restore/psql  */
2326
2318
        ahprintf(AH, "SET statement_timeout = 0;\n");
2327
2319
 
2328
2320
        /* Select the correct character set encoding */
3078
3070
        thandle         ret_child;
3079
3071
        TocEntry   *te;
3080
3072
 
3081
 
        ahlog(AH,2,"entering restore_toc_entries_parallel\n");
 
3073
        ahlog(AH, 2, "entering restore_toc_entries_parallel\n");
3082
3074
 
3083
3075
        /* we haven't got round to making this work for all archive formats */
3084
3076
        if (AH->ClonePtr == NULL || AH->ReopenPtr == NULL)
3090
3082
        fix_dependencies(AH);
3091
3083
 
3092
3084
        /*
3093
 
         * Do all the early stuff in a single connection in the parent.
3094
 
         * There's no great point in running it in parallel, in fact it will
3095
 
         * actually run faster in a single connection because we avoid all the
3096
 
         * connection and setup overhead.
 
3085
         * Do all the early stuff in a single connection in the parent. There's no
 
3086
         * great point in running it in parallel, in fact it will actually run
 
3087
         * faster in a single connection because we avoid all the connection and
 
3088
         * setup overhead.
3097
3089
         */
3098
3090
        while ((next_work_item = get_next_work_item(AH, &first_unprocessed,
3099
3091
                                                                                                NULL, 0)) != NULL)
3113
3105
        }
3114
3106
 
3115
3107
        /*
3116
 
         * Now close parent connection in prep for parallel steps.  We do this
 
3108
         * Now close parent connection in prep for parallel steps.      We do this
3117
3109
         * mainly to ensure that we don't exceed the specified number of parallel
3118
3110
         * connections.
3119
3111
         */
3139
3131
         * left to be done.
3140
3132
         */
3141
3133
 
3142
 
        ahlog(AH,1,"entering main parallel loop\n");
 
3134
        ahlog(AH, 1, "entering main parallel loop\n");
3143
3135
 
3144
3136
        while ((next_work_item = get_next_work_item(AH, &first_unprocessed,
3145
3137
                                                                                                slots, n_slots)) != NULL ||
3147
3139
        {
3148
3140
                if (next_work_item != NULL)
3149
3141
                {
3150
 
                        teReqs    reqs;
 
3142
                        teReqs          reqs;
3151
3143
 
3152
3144
                        /* If not to be dumped, don't waste time launching a worker */
3153
3145
                        reqs = _tocEntryRequired(next_work_item, AH->ropt, false);
3166
3158
                        if ((next_slot = get_next_slot(slots, n_slots)) != NO_SLOT)
3167
3159
                        {
3168
3160
                                /* There is work still to do and a worker slot available */
3169
 
                                thandle child;
 
3161
                                thandle         child;
3170
3162
                                RestoreArgs *args;
3171
3163
 
3172
3164
                                ahlog(AH, 1, "launching item %d %s %s\n",
3210
3202
                }
3211
3203
        }
3212
3204
 
3213
 
        ahlog(AH,1,"finished main parallel loop\n");
 
3205
        ahlog(AH, 1, "finished main parallel loop\n");
3214
3206
 
3215
3207
        /*
3216
3208
         * Now reconnect the single parent connection.
3222
3214
        _doSetFixedOutputState(AH);
3223
3215
 
3224
3216
        /*
3225
 
         * Make sure there is no non-ACL work left due to, say,
3226
 
         * circular dependencies, or some other pathological condition.
3227
 
         * If so, do it in the single parent connection.
 
3217
         * Make sure there is no non-ACL work left due to, say, circular
 
3218
         * dependencies, or some other pathological condition. If so, do it in the
 
3219
         * single parent connection.
3228
3220
         */
3229
3221
        for (te = AH->toc->next; te != AH->toc; te = te->next)
3230
3222
        {
3245
3237
static thandle
3246
3238
spawn_restore(RestoreArgs *args)
3247
3239
{
3248
 
        thandle child;
 
3240
        thandle         child;
3249
3241
 
3250
3242
        /* Ensure stdio state is quiesced before forking */
3251
3243
        fflush(NULL);
3279
3271
}
3280
3272
 
3281
3273
/*
3282
 
 *  collect status from a completed worker child
 
3274
 *      collect status from a completed worker child
3283
3275
 */
3284
3276
static thandle
3285
3277
reap_child(ParallelSlot *slots, int n_slots, int *work_status)
3289
3281
        return wait(work_status);
3290
3282
#else
3291
3283
        static HANDLE *handles = NULL;
3292
 
        int hindex, snum, tnum;
3293
 
        thandle ret_child;
3294
 
        DWORD res;
 
3284
        int                     hindex,
 
3285
                                snum,
 
3286
                                tnum;
 
3287
        thandle         ret_child;
 
3288
        DWORD           res;
3295
3289
 
3296
3290
        /* first time around only, make space for handles to listen on */
3297
3291
        if (handles == NULL)
3298
 
                handles = (HANDLE *) calloc(sizeof(HANDLE),n_slots);
 
3292
                handles = (HANDLE *) calloc(sizeof(HANDLE), n_slots);
3299
3293
 
3300
3294
        /* set up list of handles to listen to */
3301
 
        for (snum=0, tnum=0; snum < n_slots; snum++)
 
3295
        for (snum = 0, tnum = 0; snum < n_slots; snum++)
3302
3296
                if (slots[snum].child_id != 0)
3303
3297
                        handles[tnum++] = slots[snum].child_id;
3304
3298
 
3309
3303
        ret_child = handles[hindex - WAIT_OBJECT_0];
3310
3304
 
3311
3305
        /* get the result */
3312
 
        GetExitCodeThread(ret_child,&res);
 
3306
        GetExitCodeThread(ret_child, &res);
3313
3307
        *work_status = res;
3314
3308
 
3315
3309
        /* dispose of handle to stop leaks */
3325
3319
static bool
3326
3320
work_in_progress(ParallelSlot *slots, int n_slots)
3327
3321
{
3328
 
        int i;
 
3322
        int                     i;
3329
3323
 
3330
3324
        for (i = 0; i < n_slots; i++)
3331
3325
        {
3341
3335
static int
3342
3336
get_next_slot(ParallelSlot *slots, int n_slots)
3343
3337
{
3344
 
        int i;
 
3338
        int                     i;
3345
3339
 
3346
3340
        for (i = 0; i < n_slots; i++)
3347
3341
        {
3359
3353
static bool
3360
3354
has_lock_conflicts(TocEntry *te1, TocEntry *te2)
3361
3355
{
3362
 
        int j,k;
 
3356
        int                     j,
 
3357
                                k;
3363
3358
 
3364
3359
        for (j = 0; j < te1->nLockDeps; j++)
3365
3360
        {
3394
3389
get_next_work_item(ArchiveHandle *AH, TocEntry **first_unprocessed,
3395
3390
                                   ParallelSlot *slots, int n_slots)
3396
3391
{
3397
 
        bool      pref_non_data = false; /* or get from AH->ropt */
3398
 
        TocEntry *data_te = NULL;
3399
 
        TocEntry *te;
3400
 
        int       i,k;
 
3392
        bool            pref_non_data = false;  /* or get from AH->ropt */
 
3393
        TocEntry   *data_te = NULL;
 
3394
        TocEntry   *te;
 
3395
        int                     i,
 
3396
                                k;
3401
3397
 
3402
3398
        /*
3403
3399
         * Bogus heuristics for pref_non_data
3404
3400
         */
3405
3401
        if (pref_non_data)
3406
3402
        {
3407
 
                int count = 0;
 
3403
                int                     count = 0;
3408
3404
 
3409
 
                for (k=0; k < n_slots; k++)
 
3405
                for (k = 0; k < n_slots; k++)
3410
3406
                        if (slots[k].args->te != NULL &&
3411
3407
                                slots[k].args->te->section == SECTION_DATA)
3412
3408
                                count++;
3429
3425
         */
3430
3426
        for (; te != AH->toc; te = te->next)
3431
3427
        {
3432
 
                bool conflicts = false;
 
3428
                bool            conflicts = false;
3433
3429
 
3434
3430
                /* Ignore if already done or still waiting on dependencies */
3435
3431
                if (te->restored || te->depCount > 0)
3437
3433
 
3438
3434
                /*
3439
3435
                 * Check to see if the item would need exclusive lock on something
3440
 
                 * that a currently running item also needs lock on, or vice versa.
3441
 
                 * If so, we don't want to schedule them together.
 
3436
                 * that a currently running item also needs lock on, or vice versa. If
 
3437
                 * so, we don't want to schedule them together.
3442
3438
                 */
3443
3439
                for (i = 0; i < n_slots && !conflicts; i++)
3444
3440
                {
3445
 
                        TocEntry *running_te;
 
3441
                        TocEntry   *running_te;
3446
3442
 
3447
3443
                        if (slots[i].args == NULL)
3448
3444
                                continue;
3473
3469
        if (data_te != NULL)
3474
3470
                return data_te;
3475
3471
 
3476
 
        ahlog(AH,2,"no item ready\n");
 
3472
        ahlog(AH, 2, "no item ready\n");
3477
3473
        return NULL;
3478
3474
}
3479
3475
 
3488
3484
parallel_restore(RestoreArgs *args)
3489
3485
{
3490
3486
        ArchiveHandle *AH = args->AH;
3491
 
        TocEntry *te = args->te;
 
3487
        TocEntry   *te = args->te;
3492
3488
        RestoreOptions *ropt = AH->ropt;
3493
 
        int retval;
 
3489
        int                     retval;
3494
3490
 
3495
3491
        /*
3496
 
         * Close and reopen the input file so we have a private file pointer
3497
 
         * that doesn't stomp on anyone else's file pointer, if we're actually 
3498
 
         * going to need to read from the file. Otherwise, just close it
3499
 
         * except on Windows, where it will possibly be needed by other threads.
 
3492
         * Close and reopen the input file so we have a private file pointer that
 
3493
         * doesn't stomp on anyone else's file pointer, if we're actually going to
 
3494
         * need to read from the file. Otherwise, just close it except on Windows,
 
3495
         * where it will possibly be needed by other threads.
3500
3496
         *
3501
 
         * Note: on Windows, since we are using threads not processes, the
3502
 
         * reopen call *doesn't* close the original file pointer but just open 
3503
 
         * a new one.
 
3497
         * Note: on Windows, since we are using threads not processes, the reopen
 
3498
         * call *doesn't* close the original file pointer but just open a new one.
3504
3499
         */
3505
 
        if (te->section == SECTION_DATA )
 
3500
        if (te->section == SECTION_DATA)
3506
3501
                (AH->ReopenPtr) (AH);
3507
3502
#ifndef WIN32
3508
3503
        else
3526
3521
        AH->connection = NULL;
3527
3522
 
3528
3523
        /* If we reopened the file, we are done with it, so close it now */
3529
 
        if (te->section == SECTION_DATA )
 
3524
        if (te->section == SECTION_DATA)
3530
3525
                (AH->ClosePtr) (AH);
3531
3526
 
3532
3527
        if (retval == 0 && AH->public.n_errors)
3550
3545
mark_work_done(ArchiveHandle *AH, thandle worker, int status,
3551
3546
                           ParallelSlot *slots, int n_slots)
3552
3547
{
3553
 
        TocEntry *te = NULL;
3554
 
        int i;
 
3548
        TocEntry   *te = NULL;
 
3549
        int                     i;
3555
3550
 
3556
3551
        for (i = 0; i < n_slots; i++)
3557
3552
        {
3604
3599
{
3605
3600
        TocEntry  **tocsByDumpId;
3606
3601
        TocEntry   *te;
3607
 
        int i;
 
3602
        int                     i;
3608
3603
 
3609
3604
        /*
3610
3605
         * For some of the steps here, it is convenient to have an array that
3611
 
         * indexes the TOC entries by dump ID, rather than searching the TOC
3612
 
         * list repeatedly.  Entries for dump IDs not present in the TOC will
3613
 
         * be NULL.
 
3606
         * indexes the TOC entries by dump ID, rather than searching the TOC list
 
3607
         * repeatedly.  Entries for dump IDs not present in the TOC will be NULL.
3614
3608
         *
3615
3609
         * Also, initialize the depCount fields.
3616
3610
         */
3629
3623
         * dependencies.
3630
3624
         *
3631
3625
         * Note: currently, a TABLE DATA should always have exactly one
3632
 
         * dependency, on its TABLE item.  So we don't bother to search,
3633
 
         * but look just at the first dependency.  We do trouble to make sure
3634
 
         * that it's a TABLE, if possible.  However, if the dependency isn't
3635
 
         * in the archive then just assume it was a TABLE; this is to cover
3636
 
         * cases where the table was suppressed but we have the data and some
3637
 
         * dependent post-data items.
 
3626
         * dependency, on its TABLE item.  So we don't bother to search, but look
 
3627
         * just at the first dependency.  We do trouble to make sure that it's a
 
3628
         * TABLE, if possible.  However, if the dependency isn't in the archive
 
3629
         * then just assume it was a TABLE; this is to cover cases where the table
 
3630
         * was suppressed but we have the data and some dependent post-data items.
3638
3631
         */
3639
3632
        for (te = AH->toc->next; te != AH->toc; te = te->next)
3640
3633
        {
3641
3634
                if (strcmp(te->desc, "TABLE DATA") == 0 && te->nDeps > 0)
3642
3635
                {
3643
 
                        DumpId  tableId = te->dependencies[0];
 
3636
                        DumpId          tableId = te->dependencies[0];
3644
3637
 
3645
3638
                        if (tocsByDumpId[tableId - 1] == NULL ||
3646
3639
                                strcmp(tocsByDumpId[tableId - 1]->desc, "TABLE") == 0)
3651
3644
        }
3652
3645
 
3653
3646
        /*
3654
 
         * Pre-8.4 versions of pg_dump neglected to set up a dependency from
3655
 
         * BLOB COMMENTS to BLOBS.  Cope.  (We assume there's only one BLOBS
3656
 
         * and only one BLOB COMMENTS in such files.)
 
3647
         * Pre-8.4 versions of pg_dump neglected to set up a dependency from BLOB
 
3648
         * COMMENTS to BLOBS.  Cope.  (We assume there's only one BLOBS and only
 
3649
         * one BLOB COMMENTS in such files.)
3657
3650
         */
3658
3651
        if (AH->version < K_VERS_1_11)
3659
3652
        {
3681
3674
 
3682
3675
        /*
3683
3676
         * It is possible that the dependencies list items that are not in the
3684
 
         * archive at all.  Subtract such items from the depCounts.
 
3677
         * archive at all.      Subtract such items from the depCounts.
3685
3678
         */
3686
3679
        for (te = AH->toc->next; te != AH->toc; te = te->next)
3687
3680
        {
3714
3707
                                                   DumpId tableId, DumpId tableDataId)
3715
3708
{
3716
3709
        TocEntry   *te;
3717
 
        int i;
 
3710
        int                     i;
3718
3711
 
3719
3712
        for (te = AH->toc->next; te != AH->toc; te = te->next)
3720
3713
        {
3760
3753
 
3761
3754
        /*
3762
3755
         * We assume the item requires exclusive lock on each TABLE DATA item
3763
 
         * listed among its dependencies.  (This was originally a dependency
3764
 
         * on the TABLE, but fix_dependencies repointed it to the data item.
3765
 
         * Note that all the entry types we are interested in here are POST_DATA,
3766
 
         * so they will all have been changed this way.)
 
3756
         * listed among its dependencies.  (This was originally a dependency on
 
3757
         * the TABLE, but fix_dependencies repointed it to the data item. Note
 
3758
         * that all the entry types we are interested in here are POST_DATA, so
 
3759
         * they will all have been changed this way.)
3767
3760
         */
3768
3761
        lockids = (DumpId *) malloc(te->nDeps * sizeof(DumpId));
3769
3762
        nlockids = 0;
3770
3763
        for (i = 0; i < te->nDeps; i++)
3771
3764
        {
3772
 
                DumpId  depid = te->dependencies[i];
 
3765
                DumpId          depid = te->dependencies[i];
3773
3766
 
3774
3767
                if (tocsByDumpId[depid - 1] &&
3775
3768
                        strcmp(tocsByDumpId[depid - 1]->desc, "TABLE DATA") == 0)
3793
3786
static void
3794
3787
reduce_dependencies(ArchiveHandle *AH, TocEntry *te)
3795
3788
{
3796
 
        DumpId target = te->dumpId;
3797
 
        int i;
 
3789
        DumpId          target = te->dumpId;
 
3790
        int                     i;
3798
3791
 
3799
 
        ahlog(AH,2,"reducing dependencies for %d\n",target);
 
3792
        ahlog(AH, 2, "reducing dependencies for %d\n", target);
3800
3793
 
3801
3794
        /*
3802
3795
         * We must examine all entries, not only the ones after the target item,
3877
3870
        ArchiveHandle *clone;
3878
3871
 
3879
3872
        /* Make a "flat" copy */
3880
 
        clone = (ArchiveHandle *) malloc(sizeof(ArchiveHandle)); 
 
3873
        clone = (ArchiveHandle *) malloc(sizeof(ArchiveHandle));
3881
3874
        if (clone == NULL)
3882
3875
                die_horribly(AH, modulename, "out of memory\n");
3883
3876
        memcpy(clone, AH, sizeof(ArchiveHandle));