@@ -320,7 +320,7 @@ static DataTypesUsageChecks data_types_usage_checks[] =
320
320
struct data_type_check_state
321
321
{
322
322
DataTypesUsageChecks * check ; /* the check for this step */
323
- bool * result ; /* true if check failed for any database */
323
+ bool result ; /* true if check failed for any database */
324
324
PQExpBuffer * report ; /* buffer for report on failed checks */
325
325
};
326
326
@@ -390,69 +390,54 @@ process_data_type_check(DbInfo *dbinfo, PGresult *res, void *arg)
390
390
{
391
391
struct data_type_check_state * state = (struct data_type_check_state * ) arg ;
392
392
int ntups = PQntuples (res );
393
+ char output_path [MAXPGPATH ];
394
+ int i_nspname = PQfnumber (res , "nspname" );
395
+ int i_relname = PQfnumber (res , "relname" );
396
+ int i_attname = PQfnumber (res , "attname" );
397
+ FILE * script = NULL ;
393
398
394
399
AssertVariableIsOfType (& process_data_type_check , UpgradeTaskProcessCB );
395
400
396
- if (ntups )
397
- {
398
- char output_path [MAXPGPATH ];
399
- int i_nspname ;
400
- int i_relname ;
401
- int i_attname ;
402
- FILE * script = NULL ;
403
- bool db_used = false;
401
+ if (ntups == 0 )
402
+ return ;
404
403
405
- snprintf (output_path , sizeof (output_path ), "%s/%s" ,
406
- log_opts .basedir ,
407
- state -> check -> report_filename );
404
+ snprintf (output_path , sizeof (output_path ), "%s/%s" ,
405
+ log_opts .basedir ,
406
+ state -> check -> report_filename );
408
407
409
- /*
410
- * Make sure we have a buffer to save reports to now that we found a
411
- * first failing check.
412
- */
413
- if (* state -> report == NULL )
414
- * state -> report = createPQExpBuffer ();
408
+ /*
409
+ * Make sure we have a buffer to save reports to now that we found a first
410
+ * failing check.
411
+ */
412
+ if (* state -> report == NULL )
413
+ * state -> report = createPQExpBuffer ();
415
414
416
- /*
417
- * If this is the first time we see an error for the check in question
418
- * then print a status message of the failure.
419
- */
420
- if (!( * state -> result ) )
421
- {
422
- pg_log (PG_REPORT , "failed check: %s" , _ (state -> check -> status ));
423
- appendPQExpBuffer (* state -> report , "\n%s\n%s %s\n" ,
424
- _ (state -> check -> report_text ),
425
- _ ("A list of the problem columns is in the file:" ),
426
- output_path );
427
- }
428
- * state -> result = true;
415
+ /*
416
+ * If this is the first time we see an error for the check in question
417
+ * then print a status message of the failure.
418
+ */
419
+ if (!state -> result )
420
+ {
421
+ pg_log (PG_REPORT , "failed check: %s" , _ (state -> check -> status ));
422
+ appendPQExpBuffer (* state -> report , "\n%s\n%s %s\n" ,
423
+ _ (state -> check -> report_text ),
424
+ _ ("A list of the problem columns is in the file:" ),
425
+ output_path );
426
+ }
427
+ state -> result = true;
429
428
430
- i_nspname = PQfnumber (res , "nspname" );
431
- i_relname = PQfnumber (res , "relname" );
432
- i_attname = PQfnumber (res , "attname" );
429
+ if ((script = fopen_priv (output_path , "a" )) == NULL )
430
+ pg_fatal ("could not open file \"%s\": %m" , output_path );
433
431
434
- for (int rowno = 0 ; rowno < ntups ; rowno ++ )
435
- {
436
- if (script == NULL && (script = fopen_priv (output_path , "a" )) == NULL )
437
- pg_fatal ("could not open file \"%s\": %m" , output_path );
432
+ fprintf (script , "In database: %s\n" , dbinfo -> db_name );
438
433
439
- if (!db_used )
440
- {
441
- fprintf (script , "In database: %s\n" , dbinfo -> db_name );
442
- db_used = true;
443
- }
444
- fprintf (script , " %s.%s.%s\n" ,
445
- PQgetvalue (res , rowno , i_nspname ),
446
- PQgetvalue (res , rowno , i_relname ),
447
- PQgetvalue (res , rowno , i_attname ));
448
- }
434
+ for (int rowno = 0 ; rowno < ntups ; rowno ++ )
435
+ fprintf (script , " %s.%s.%s\n" ,
436
+ PQgetvalue (res , rowno , i_nspname ),
437
+ PQgetvalue (res , rowno , i_relname ),
438
+ PQgetvalue (res , rowno , i_attname ));
449
439
450
- if (script )
451
- {
452
- fclose (script );
453
- script = NULL ;
454
- }
455
- }
440
+ fclose (script );
456
441
}
457
442
458
443
/*
@@ -477,7 +462,6 @@ process_data_type_check(DbInfo *dbinfo, PGresult *res, void *arg)
477
462
static void
478
463
check_for_data_types_usage (ClusterInfo * cluster )
479
464
{
480
- bool * results ;
481
465
PQExpBuffer report = NULL ;
482
466
DataTypesUsageChecks * tmp = data_types_usage_checks ;
483
467
int n_data_types_usage_checks = 0 ;
@@ -494,8 +478,7 @@ check_for_data_types_usage(ClusterInfo *cluster)
494
478
tmp ++ ;
495
479
}
496
480
497
- /* Prepare an array to store the results of checks in */
498
- results = pg_malloc0 (sizeof (bool ) * n_data_types_usage_checks );
481
+ /* Allocate memory for queries and for task states */
499
482
queries = pg_malloc0 (sizeof (char * ) * n_data_types_usage_checks );
500
483
states = pg_malloc0 (sizeof (struct data_type_check_state ) * n_data_types_usage_checks );
501
484
@@ -525,7 +508,6 @@ check_for_data_types_usage(ClusterInfo *cluster)
525
508
queries [i ] = data_type_check_query (i );
526
509
527
510
states [i ].check = check ;
528
- states [i ].result = & results [i ];
529
511
states [i ].report = & report ;
530
512
531
513
upgrade_task_add_step (task , queries [i ], process_data_type_check ,
@@ -545,7 +527,6 @@ check_for_data_types_usage(ClusterInfo *cluster)
545
527
destroyPQExpBuffer (report );
546
528
}
547
529
548
- pg_free (results );
549
530
for (int i = 0 ; i < n_data_types_usage_checks ; i ++ )
550
531
{
551
532
if (queries [i ])
@@ -1234,7 +1215,6 @@ check_for_prepared_transactions(ClusterInfo *cluster)
1234
1215
static void
1235
1216
process_isn_and_int8_passing_mismatch (DbInfo * dbinfo , PGresult * res , void * arg )
1236
1217
{
1237
- bool db_used = false;
1238
1218
int ntups = PQntuples (res );
1239
1219
int i_nspname = PQfnumber (res , "nspname" );
1240
1220
int i_proname = PQfnumber (res , "proname" );
@@ -1243,20 +1223,19 @@ process_isn_and_int8_passing_mismatch(DbInfo *dbinfo, PGresult *res, void *arg)
1243
1223
AssertVariableIsOfType (& process_isn_and_int8_passing_mismatch ,
1244
1224
UpgradeTaskProcessCB );
1245
1225
1226
+ if (ntups == 0 )
1227
+ return ;
1228
+
1229
+ if (report -> file == NULL &&
1230
+ (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1231
+ pg_fatal ("could not open file \"%s\": %m" , report -> path );
1232
+
1233
+ fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1234
+
1246
1235
for (int rowno = 0 ; rowno < ntups ; rowno ++ )
1247
- {
1248
- if (report -> file == NULL &&
1249
- (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1250
- pg_fatal ("could not open file \"%s\": %m" , report -> path );
1251
- if (!db_used )
1252
- {
1253
- fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1254
- db_used = true;
1255
- }
1256
1236
fprintf (report -> file , " %s.%s\n" ,
1257
1237
PQgetvalue (res , rowno , i_nspname ),
1258
1238
PQgetvalue (res , rowno , i_proname ));
1259
- }
1260
1239
}
1261
1240
1262
1241
/*
@@ -1324,7 +1303,6 @@ process_user_defined_postfix_ops(DbInfo *dbinfo, PGresult *res, void *arg)
1324
1303
{
1325
1304
UpgradeTaskReport * report = (UpgradeTaskReport * ) arg ;
1326
1305
int ntups = PQntuples (res );
1327
- bool db_used = false;
1328
1306
int i_oproid = PQfnumber (res , "oproid" );
1329
1307
int i_oprnsp = PQfnumber (res , "oprnsp" );
1330
1308
int i_oprname = PQfnumber (res , "oprname" );
@@ -1334,26 +1312,22 @@ process_user_defined_postfix_ops(DbInfo *dbinfo, PGresult *res, void *arg)
1334
1312
AssertVariableIsOfType (& process_user_defined_postfix_ops ,
1335
1313
UpgradeTaskProcessCB );
1336
1314
1337
- if (! ntups )
1315
+ if (ntups == 0 )
1338
1316
return ;
1339
1317
1318
+ if (report -> file == NULL &&
1319
+ (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1320
+ pg_fatal ("could not open file \"%s\": %m" , report -> path );
1321
+
1322
+ fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1323
+
1340
1324
for (int rowno = 0 ; rowno < ntups ; rowno ++ )
1341
- {
1342
- if (report -> file == NULL &&
1343
- (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1344
- pg_fatal ("could not open file \"%s\": %m" , report -> path );
1345
- if (!db_used )
1346
- {
1347
- fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1348
- db_used = true;
1349
- }
1350
1325
fprintf (report -> file , " (oid=%s) %s.%s (%s.%s, NONE)\n" ,
1351
1326
PQgetvalue (res , rowno , i_oproid ),
1352
1327
PQgetvalue (res , rowno , i_oprnsp ),
1353
1328
PQgetvalue (res , rowno , i_oprname ),
1354
1329
PQgetvalue (res , rowno , i_typnsp ),
1355
1330
PQgetvalue (res , rowno , i_typname ));
1356
- }
1357
1331
}
1358
1332
1359
1333
/*
@@ -1422,29 +1396,26 @@ static void
1422
1396
process_incompat_polymorphics (DbInfo * dbinfo , PGresult * res , void * arg )
1423
1397
{
1424
1398
UpgradeTaskReport * report = (UpgradeTaskReport * ) arg ;
1425
- bool db_used = false;
1426
1399
int ntups = PQntuples (res );
1427
1400
int i_objkind = PQfnumber (res , "objkind" );
1428
1401
int i_objname = PQfnumber (res , "objname" );
1429
1402
1430
1403
AssertVariableIsOfType (& process_incompat_polymorphics ,
1431
1404
UpgradeTaskProcessCB );
1432
1405
1433
- for (int rowno = 0 ; rowno < ntups ; rowno ++ )
1434
- {
1435
- if (report -> file == NULL &&
1436
- (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1437
- pg_fatal ("could not open file \"%s\": %m" , report -> path );
1438
- if (!db_used )
1439
- {
1440
- fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1441
- db_used = true;
1442
- }
1406
+ if (ntups == 0 )
1407
+ return ;
1408
+
1409
+ if (report -> file == NULL &&
1410
+ (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1411
+ pg_fatal ("could not open file \"%s\": %m" , report -> path );
1443
1412
1413
+ fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1414
+
1415
+ for (int rowno = 0 ; rowno < ntups ; rowno ++ )
1444
1416
fprintf (report -> file , " %s: %s\n" ,
1445
1417
PQgetvalue (res , rowno , i_objkind ),
1446
1418
PQgetvalue (res , rowno , i_objname ));
1447
- }
1448
1419
}
1449
1420
1450
1421
/*
@@ -1558,30 +1529,25 @@ static void
1558
1529
process_with_oids_check (DbInfo * dbinfo , PGresult * res , void * arg )
1559
1530
{
1560
1531
UpgradeTaskReport * report = (UpgradeTaskReport * ) arg ;
1561
- bool db_used = false;
1562
1532
int ntups = PQntuples (res );
1563
1533
int i_nspname = PQfnumber (res , "nspname" );
1564
1534
int i_relname = PQfnumber (res , "relname" );
1565
1535
1566
1536
AssertVariableIsOfType (& process_with_oids_check , UpgradeTaskProcessCB );
1567
1537
1568
- if (! ntups )
1538
+ if (ntups == 0 )
1569
1539
return ;
1570
1540
1541
+ if (report -> file == NULL &&
1542
+ (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1543
+ pg_fatal ("could not open file \"%s\": %m" , report -> path );
1544
+
1545
+ fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1546
+
1571
1547
for (int rowno = 0 ; rowno < ntups ; rowno ++ )
1572
- {
1573
- if (report -> file == NULL &&
1574
- (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1575
- pg_fatal ("could not open file \"%s\": %m" , report -> path );
1576
- if (!db_used )
1577
- {
1578
- fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1579
- db_used = true;
1580
- }
1581
1548
fprintf (report -> file , " %s.%s\n" ,
1582
1549
PQgetvalue (res , rowno , i_nspname ),
1583
1550
PQgetvalue (res , rowno , i_relname ));
1584
- }
1585
1551
}
1586
1552
1587
1553
/*
@@ -1693,7 +1659,6 @@ static void
1693
1659
process_user_defined_encoding_conversions (DbInfo * dbinfo , PGresult * res , void * arg )
1694
1660
{
1695
1661
UpgradeTaskReport * report = (UpgradeTaskReport * ) arg ;
1696
- bool db_used = false;
1697
1662
int ntups = PQntuples (res );
1698
1663
int i_conoid = PQfnumber (res , "conoid" );
1699
1664
int i_conname = PQfnumber (res , "conname" );
@@ -1702,24 +1667,20 @@ process_user_defined_encoding_conversions(DbInfo *dbinfo, PGresult *res, void *a
1702
1667
AssertVariableIsOfType (& process_user_defined_encoding_conversions ,
1703
1668
UpgradeTaskProcessCB );
1704
1669
1705
- if (! ntups )
1670
+ if (ntups == 0 )
1706
1671
return ;
1707
1672
1673
+ if (report -> file == NULL &&
1674
+ (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1675
+ pg_fatal ("could not open file \"%s\": %m" , report -> path );
1676
+
1677
+ fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1678
+
1708
1679
for (int rowno = 0 ; rowno < ntups ; rowno ++ )
1709
- {
1710
- if (report -> file == NULL &&
1711
- (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1712
- pg_fatal ("could not open file \"%s\": %m" , report -> path );
1713
- if (!db_used )
1714
- {
1715
- fprintf (report -> file , "In database: %s\n" , dbinfo -> db_name );
1716
- db_used = true;
1717
- }
1718
1680
fprintf (report -> file , " (oid=%s) %s.%s\n" ,
1719
1681
PQgetvalue (res , rowno , i_conoid ),
1720
1682
PQgetvalue (res , rowno , i_nspname ),
1721
1683
PQgetvalue (res , rowno , i_conname ));
1722
- }
1723
1684
}
1724
1685
1725
1686
/*
@@ -1971,27 +1932,28 @@ static void
1971
1932
process_old_sub_state_check (DbInfo * dbinfo , PGresult * res , void * arg )
1972
1933
{
1973
1934
UpgradeTaskReport * report = (UpgradeTaskReport * ) arg ;
1974
- int ntup = PQntuples (res );
1935
+ int ntups = PQntuples (res );
1975
1936
int i_srsubstate = PQfnumber (res , "srsubstate" );
1976
1937
int i_subname = PQfnumber (res , "subname" );
1977
1938
int i_nspname = PQfnumber (res , "nspname" );
1978
1939
int i_relname = PQfnumber (res , "relname" );
1979
1940
1980
1941
AssertVariableIsOfType (& process_old_sub_state_check , UpgradeTaskProcessCB );
1981
1942
1982
- for (int i = 0 ; i < ntup ; i ++ )
1983
- {
1984
- if (report -> file == NULL &&
1985
- (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1986
- pg_fatal ("could not open file \"%s\": %m" , report -> path );
1943
+ if (ntups == 0 )
1944
+ return ;
1987
1945
1946
+ if (report -> file == NULL &&
1947
+ (report -> file = fopen_priv (report -> path , "w" )) == NULL )
1948
+ pg_fatal ("could not open file \"%s\": %m" , report -> path );
1949
+
1950
+ for (int i = 0 ; i < ntups ; i ++ )
1988
1951
fprintf (report -> file , "The table sync state \"%s\" is not allowed for database:\"%s\" subscription:\"%s\" schema:\"%s\" relation:\"%s\"\n" ,
1989
1952
PQgetvalue (res , i , i_srsubstate ),
1990
1953
dbinfo -> db_name ,
1991
1954
PQgetvalue (res , i , i_subname ),
1992
1955
PQgetvalue (res , i , i_nspname ),
1993
1956
PQgetvalue (res , i , i_relname ));
1994
- }
1995
1957
}
1996
1958
1997
1959
/*
0 commit comments