@@ -126,9 +126,6 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
126
126
/* Initialize size summary */
127
127
current .data_bytes = 0 ;
128
128
129
- /* do some checks on the node */
130
- sanityChecks ();
131
-
132
129
/*
133
130
* Obtain current timeline by scanning control file, theh LSN
134
131
* obtained at output of pg_start_backup or pg_stop_backup does
@@ -152,11 +149,9 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
152
149
if (current .backup_mode == BACKUP_MODE_DIFF_PAGE ||
153
150
current .backup_mode == BACKUP_MODE_DIFF_PTRACK )
154
151
{
155
- pgBackup * prev_backup ;
156
-
157
152
prev_backup = catalog_get_last_data_backup (backup_list , current .tli );
158
153
if (prev_backup == NULL )
159
- elog (ERROR , "Timeline has changed since last full backup."
154
+ elog (ERROR , "Timeline has changed since last full backup. "
160
155
"Create new full backup before an incremental one." );
161
156
}
162
157
@@ -233,8 +228,7 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
233
228
if (current .backup_mode == BACKUP_MODE_DIFF_PAGE ||
234
229
current .backup_mode == BACKUP_MODE_DIFF_PTRACK )
235
230
{
236
- /* find last completed database backup */
237
- prev_backup = catalog_get_last_data_backup (backup_list , current .tli );
231
+ Assert (prev_backup );
238
232
pgBackupGetPath (prev_backup , prev_file_txt , lengthof (prev_file_txt ),
239
233
DATABASE_FILE_LIST );
240
234
prev_files = dir_read_file_list (pgdata , prev_file_txt );
@@ -1337,21 +1331,21 @@ backup_files(void *arg)
1337
1331
static void
1338
1332
add_files (parray * files , const char * root , bool add_root , bool is_pgdata )
1339
1333
{
1340
- parray * list_file ;
1341
- int i ;
1334
+ parray * list_file ;
1335
+ size_t i ;
1342
1336
1343
1337
list_file = parray_new ();
1344
1338
1345
1339
/* list files with the logical path. omit $PGDATA */
1346
1340
dir_list_file (list_file , root , true, true, add_root );
1347
1341
1348
1342
/* mark files that are possible datafile as 'datafile' */
1349
- for (i = 0 ; i < ( int ) parray_num (list_file ); i ++ )
1343
+ for (i = 0 ; i < parray_num (list_file ); i ++ )
1350
1344
{
1351
- pgFile * file = (pgFile * ) parray_get (list_file , i );
1352
- char * relative ;
1353
- char * fname ;
1354
- int path_len ;
1345
+ pgFile * file = (pgFile * ) parray_get (list_file , i );
1346
+ char * relative ;
1347
+ char * fname ;
1348
+ size_t path_len ;
1355
1349
1356
1350
/* data file must be a regular file */
1357
1351
if (!S_ISREG (file -> mode ))
@@ -1367,6 +1361,10 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
1367
1361
1368
1362
/* Get file name from path */
1369
1363
fname = last_dir_separator (relative );
1364
+ if (fname == NULL )
1365
+ fname = relative ;
1366
+ else
1367
+ fname ++ ;
1370
1368
1371
1369
/* Remove temp tables from the list */
1372
1370
if (fname [0 ] == 't' && isdigit (fname [1 ]))
@@ -1379,32 +1377,41 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
1379
1377
1380
1378
path_len = strlen (file -> path );
1381
1379
/* Get link ptrack file to relations files */
1382
- if (path_len > 6 && strncmp (file -> path + (path_len - 6 ), "ptrack" , 6 ) == 0 )
1380
+ if (path_len > 6 &&
1381
+ strncmp (file -> path + (path_len - 6 ), "ptrack" , 6 ) == 0 )
1383
1382
{
1384
- pgFile * search_file ;
1385
- pgFile * * pre_search_file ;
1386
- int segno = 0 ;
1387
- while (true) {
1388
- pgFile tmp_file ;
1383
+ pgFile * search_file ;
1384
+ pgFile * * pre_search_file ;
1385
+ int segno = 0 ;
1386
+
1387
+ while (true)
1388
+ {
1389
+ pgFile tmp_file ;
1390
+
1389
1391
tmp_file .path = pg_strdup (file -> path );
1390
1392
1391
1393
/* Segno fits into 6 digits since it is not more than 4000 */
1392
1394
if (segno > 0 )
1393
- sprintf (tmp_file .path + path_len - 7 , ".%d" , segno );
1395
+ sprintf (tmp_file .path + path_len - 7 , ".%d" , segno );
1394
1396
else
1395
- tmp_file .path [path_len - 7 ] = '\0' ;
1397
+ tmp_file .path [path_len - 7 ] = '\0' ;
1396
1398
1397
- pre_search_file = (pgFile * * ) parray_bsearch (list_file , & tmp_file , pgFileComparePath );
1399
+ pre_search_file = (pgFile * * ) parray_bsearch (list_file ,
1400
+ & tmp_file ,
1401
+ pgFileComparePath );
1398
1402
1399
1403
if (pre_search_file != NULL )
1400
1404
{
1401
1405
search_file = * pre_search_file ;
1402
1406
search_file -> ptrack_path = pg_strdup (file -> path );
1403
1407
search_file -> segno = segno ;
1404
- } else {
1408
+ }
1409
+ else
1410
+ {
1405
1411
pg_free (tmp_file .path );
1406
1412
break ;
1407
1413
}
1414
+
1408
1415
pg_free (tmp_file .path );
1409
1416
segno ++ ;
1410
1417
}
@@ -1413,63 +1420,24 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
1413
1420
pgFileFree (file );
1414
1421
parray_remove (list_file , i );
1415
1422
i -- ;
1416
- continue ;
1417
1423
}
1418
-
1419
1424
/* compress map file it is not data file */
1420
- if (path_len > 4 && strncmp (file -> path + (path_len - 4 ), ".cfm" , 4 ) == 0 )
1421
- continue ;
1422
-
1423
- /* name of data file start with digit */
1424
- if (fname == NULL )
1425
- fname = relative ;
1426
- else
1427
- fname ++ ;
1428
- if (!isdigit (fname [0 ]))
1429
- continue ;
1430
-
1431
- file -> is_datafile = true;
1425
+ else if (path_len > 4 &&
1426
+ strncmp (file -> path + (path_len - 4 ), ".cfm" , 4 ) == 0 )
1432
1427
{
1433
- int find_dot ;
1434
- int check_digit ;
1435
- char * text_segno ;
1436
- for (find_dot = path_len - 1 ; file -> path [find_dot ] != '.' && find_dot >= 0 ; find_dot -- );
1437
- if (find_dot <= 0 )
1438
- continue ;
1439
-
1440
- text_segno = file -> path + find_dot + 1 ;
1441
- for (check_digit = 0 ; text_segno [check_digit ] != '\0' ; check_digit ++ )
1442
- if (!isdigit (text_segno [check_digit ]))
1443
- {
1444
- check_digit = -1 ;
1445
- break ;
1446
- }
1447
-
1448
- if (check_digit == -1 )
1449
- continue ;
1450
-
1451
- file -> segno = (int ) strtol (text_segno , NULL , 10 );
1452
- }
1453
- }
1428
+ pgFile * * pre_search_file ;
1429
+ pgFile tmp_file ;
1454
1430
1455
- /* mark cfs relations as not data */
1456
- for (i = 0 ; i < (int ) parray_num (list_file ); i ++ )
1457
- {
1458
- pgFile * file = (pgFile * ) parray_get (list_file , i );
1459
- int path_len = (int ) strlen (file -> path );
1460
-
1461
- if (path_len > 4 && strncmp (file -> path + (path_len - 4 ), ".cfm" , 4 ) == 0 )
1462
- {
1463
- pgFile * * pre_search_file ;
1464
- pgFile tmp_file ;
1465
1431
tmp_file .path = pg_strdup (file -> path );
1466
- tmp_file .path [path_len - 4 ] = '\0' ;
1432
+ tmp_file .path [path_len - 4 ] = '\0' ;
1467
1433
pre_search_file = (pgFile * * ) parray_bsearch (list_file ,
1468
- & tmp_file , pgFileComparePath );
1434
+ & tmp_file ,
1435
+ pgFileComparePath );
1469
1436
if (pre_search_file != NULL )
1470
1437
{
1471
- FileMap * map ;
1472
- int md = open (file -> path , O_RDWR |PG_BINARY , 0 );
1438
+ FileMap * map ;
1439
+ int md = open (file -> path , O_RDWR |PG_BINARY , 0 );
1440
+
1473
1441
if (md < 0 )
1474
1442
elog (ERROR , "add_files(). cannot open cfm file '%s'" , file -> path );
1475
1443
@@ -1485,16 +1453,51 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
1485
1453
(* pre_search_file )-> is_datafile = false;
1486
1454
1487
1455
if (cfs_munmap (map ) < 0 )
1488
- elog (LOG , "add_files(). CFS failed to unmap file %s: %m" , file -> path );
1456
+ elog (LOG , "add_files(). CFS failed to unmap file %s: %m" ,
1457
+ file -> path );
1489
1458
if (close (md ) < 0 )
1490
- elog (LOG , "add_files(). CFS failed to close file %s: %m" , file -> path );
1459
+ elog (LOG , "add_files(). CFS failed to close file %s: %m" ,
1460
+ file -> path );
1491
1461
}
1492
1462
else
1493
- elog (ERROR , "corresponding segment '%s' is not found" , tmp_file .path );
1463
+ elog (ERROR , "corresponding segment '%s' is not found" ,
1464
+ tmp_file .path );
1494
1465
1495
1466
pg_free (tmp_file .path );
1496
1467
}
1468
+ /* name of data file start with digit */
1469
+ else if (isdigit (fname [0 ]))
1470
+ {
1471
+ int find_dot ;
1472
+ int check_digit ;
1473
+ char * text_segno ;
1474
+
1475
+ file -> is_datafile = true;
1476
+
1477
+ /*
1478
+ * Find segment number.
1479
+ */
1480
+
1481
+ for (find_dot = (int ) path_len - 1 ;
1482
+ file -> path [find_dot ] != '.' && find_dot >= 0 ;
1483
+ find_dot -- );
1484
+ /* There is not segment number */
1485
+ if (find_dot <= 0 )
1486
+ continue ;
1487
+
1488
+ text_segno = file -> path + find_dot + 1 ;
1489
+ for (check_digit = 0 ; text_segno [check_digit ] != '\0' ; check_digit ++ )
1490
+ if (!isdigit (text_segno [check_digit ]))
1491
+ {
1492
+ check_digit = -1 ;
1493
+ break ;
1494
+ }
1495
+
1496
+ if (check_digit != -1 )
1497
+ file -> segno = (int ) strtol (text_segno , NULL , 10 );
1498
+ }
1497
1499
}
1500
+
1498
1501
parray_concat (files , list_file );
1499
1502
}
1500
1503
0 commit comments