@@ -52,11 +52,16 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads)
52
52
do_catchup_instance (source_pgdata , dest_pgdata , source_conn , & source_node_info ,
53
53
no_sync , backup_logs , dest_pgdata_is_empty );
54
54
55
+ //REVIEW: Are we going to do that before release?
55
56
/* TODO: show the amount of transfered data in bytes and calculate incremental ratio */
56
57
57
58
return 0 ;
58
59
}
59
60
61
+ //REVIEW Please add a comment to this function.
62
+ //Besides, the name of this function looks strange to me.
63
+ //Maybe catchup_init_state() or catchup_setup() will do better?
64
+ //I'd also suggest to wrap all these fields into some CatchupState, but it isn't urgent.
60
65
static PGconn *
61
66
catchup_collect_info (PGNodeInfo * source_node_info , const char * source_pgdata , const char * dest_pgdata )
62
67
{
@@ -70,12 +75,14 @@ catchup_collect_info(PGNodeInfo *source_node_info, const char *source_pgdata, co
70
75
current .start_time = time (NULL );
71
76
72
77
StrNCpy (current .program_version , PROGRAM_VERSION , sizeof (current .program_version ));
78
+ //REVIEW I guess these are some copy-paste leftovers. Let's clean them.
73
79
//current.compress_alg = instance_config.compress_alg;
74
80
//current.compress_level = instance_config.compress_level;
75
81
76
82
/* Do some compatibility checks and fill basic info about PG instance */
77
83
source_conn = pgdata_basic_setup (instance_config .conn_opt , source_node_info );
78
84
85
+ //REVIEW Please adjust the comment. Do we need this code for catchup at all?
79
86
/* below perform checks specific for backup command */
80
87
#if PG_VERSION_NUM >= 110000
81
88
if (!RetrieveWalSegSize (source_conn ))
@@ -106,10 +113,12 @@ catchup_collect_info(PGNodeInfo *source_node_info, const char *source_pgdata, co
106
113
return source_conn ;
107
114
}
108
115
116
+ //REVIEW Please add a comment to this function.
109
117
static void
110
118
catchup_preflight_checks (PGNodeInfo * source_node_info , PGconn * source_conn ,
111
119
const char * source_pgdata , const char * dest_pgdata , bool dest_pgdata_is_empty )
112
120
{
121
+ //REVIEW Let's fix it before release.
113
122
// TODO: add sanity check that source PGDATA is not empty
114
123
115
124
/* Check that connected PG instance and source PGDATA are the same */
@@ -135,6 +144,7 @@ catchup_preflight_checks(PGNodeInfo *source_node_info, PGconn *source_conn,
135
144
if (current .from_replica && exclusive_backup )
136
145
elog (ERROR , "Catchup from standby is available only for PG >= 9.6" );
137
146
147
+ //REVIEW FIXME Let's fix it before release. This one seems like a potential bug.
138
148
// TODO check if it is local catchup and source contain tablespaces
139
149
}
140
150
@@ -154,15 +164,18 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
154
164
RedoParams dest_redo = { 0 , InvalidXLogRecPtr , 0 };
155
165
pgFile * source_pg_control_file = NULL ;
156
166
167
+ //REVIEW please adjust this comment.
157
168
/* arrays with meta info for multi threaded backup */
158
169
pthread_t * threads ;
159
170
catchup_thread_runner_arg * threads_args ;
160
171
bool catchup_isok = true;
161
172
162
173
parray * source_filelist = NULL ;
163
174
parray * dest_filelist = NULL ;
175
+ //REVIEW We don't handle external_dirs in catchup, do we? Let's clean this up.
164
176
parray * external_dirs = NULL ;
165
177
178
+ //REVIEW FIXME Let's fix it before release. It can cause some obscure bugs.
166
179
/* TODO: in case of timeline mistmatch, check that source PG timeline descending from dest PG timeline */
167
180
parray * tli_list = NULL ;
168
181
@@ -172,6 +185,8 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
172
185
char pretty_bytes [20 ];
173
186
174
187
PGStopBackupResult stop_backup_result ;
188
+ //REVIEW Is it relevant to catchup? I suppose it isn't, since catchup is a new code.
189
+ //If we do need it, please write a comment explaining that.
175
190
/* kludge against some old bug in archive_timeout. TODO: remove in 3.0.0 */
176
191
int timeout = (instance_config .archive_timeout > 0 ) ?
177
192
instance_config .archive_timeout : ARCHIVE_TIMEOUT_DEFAULT ;
@@ -184,10 +199,14 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
184
199
strncat (label , " with pg_probackup" , lengthof (label ) -
185
200
strlen (" with pg_probackup" ));
186
201
202
+ //REVIEW FIXME Let' do that.
203
+
187
204
/* Call pg_start_backup function in PostgreSQL connect */
188
205
pg_start_backup (label , smooth_checkpoint , & current , source_node_info , source_conn );
189
206
elog (LOG , "pg_start_backup START LSN %X/%X" , (uint32 ) (current .start_lsn >> 32 ), (uint32 ) (current .start_lsn ));
190
207
208
+ //REVIEW I wonder, if we can move this piece above and call before pg_start backup()?
209
+ //It seems to be a part of setup phase.
191
210
if (!dest_pgdata_is_empty &&
192
211
(current .backup_mode == BACKUP_MODE_DIFF_PTRACK ||
193
212
current .backup_mode == BACKUP_MODE_DIFF_DELTA ))
@@ -201,6 +220,8 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
201
220
elog (INFO , "syncLSN = %X/%X" , (uint32 ) (dest_redo .lsn >> 32 ), (uint32 ) dest_redo .lsn );
202
221
}
203
222
223
+ //REVIEW I wonder, if we can move this piece above and call before pg_start backup()?
224
+ //It seems to be a part of setup phase.
204
225
/*
205
226
* TODO: move to separate function to use in both backup.c and catchup.c
206
227
*/
@@ -234,6 +255,7 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
234
255
current .start_lsn , current .tli );
235
256
}
236
257
258
+ //REVIEW please adjust the comment.
237
259
/* initialize backup list */
238
260
source_filelist = parray_new ();
239
261
@@ -244,12 +266,15 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
244
266
else
245
267
dir_list_file (source_filelist , source_pgdata ,
246
268
true, true, false, backup_logs , true, 0 , FIO_LOCAL_HOST );
269
+
270
+ //REVIEW FIXME. Let's fix that before release.
247
271
// TODO filter pg_xlog/wal?
248
272
// TODO what if wal is not a dir (symlink to a dir)?
249
273
250
274
/* close ssh session in main thread */
251
275
fio_disconnect ();
252
276
277
+ //REVIEW Do we want to do similar calculation for dest?
253
278
current .pgdata_bytes += calculate_datasize_of_filelist (source_filelist );
254
279
pretty_size (current .pgdata_bytes , pretty_bytes , lengthof (pretty_bytes ));
255
280
elog (INFO , "Source PGDATA size: %s" , pretty_bytes );
@@ -267,12 +292,14 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
267
292
*/
268
293
parray_qsort (source_filelist , pgFileCompareRelPathWithExternal );
269
294
295
+ //REVIEW Please adjust the comment.
270
296
/* Extract information about files in source_filelist parsing their names:*/
271
297
parse_filelist_filenames (source_filelist , source_pgdata );
272
298
273
299
elog (LOG , "Start LSN (source): %X/%X, TLI: %X" ,
274
300
(uint32 ) (current .start_lsn >> 32 ), (uint32 ) (current .start_lsn ),
275
301
current .tli );
302
+ //REVIEW FIXME Huh? Don't we check TLI at all?
276
303
/* TODO проверить, нужна ли проверка TLI */
277
304
if (current .backup_mode != BACKUP_MODE_FULL )
278
305
elog (LOG , "LSN in destination: %X/%X, TLI: %X" ,
@@ -339,11 +366,14 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
339
366
char to_path [MAXPGPATH ];
340
367
341
368
// perform additional check that this is actually synlink?
369
+ //REVIEW Why is this code block separated?
342
370
{ /* get full symlink path and map this path to new location */
343
371
char source_full_path [MAXPGPATH ];
344
372
char symlink_content [MAXPGPATH ];
345
373
join_path_components (source_full_path , source_pgdata , file -> rel_path );
346
374
fio_readlink (source_full_path , symlink_content , sizeof (symlink_content ), FIO_DB_HOST );
375
+ //REVIEW What if we won't find mapping for this tablespace?
376
+ //I'd expect a failure. Otherwise, we may spoil source database data.
347
377
linked_path = leaked_abstraction_get_tablespace_mapping (symlink_content );
348
378
// TODO: check that linked_path != symlink_content in case of local catchup?
349
379
elog (WARNING , "Map tablespace full_path: \"%s\" old_symlink_content: \"%s\" old_symlink_content: \"%s\"\n" ,
@@ -361,6 +391,8 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
361
391
elog (VERBOSE , "Create directory \"%s\" and symbolic link \"%s\"" ,
362
392
linked_path , to_path );
363
393
394
+ //REVIEW Handle return value here.
395
+ //We should not proceed if failed to create dir.
364
396
/* create tablespace directory */
365
397
fio_mkdir (linked_path , DIR_PERMISSION , FIO_BACKUP_HOST );
366
398
@@ -403,6 +435,8 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
403
435
bool redundant = true;
404
436
pgFile * file = (pgFile * ) parray_get (dest_filelist , i );
405
437
438
+ //REVIEW Can we maybe optimize it and use some merge-like algorithm
439
+ //instead of bsearch for each file? Of course it isn't an urgent fix.
406
440
if (parray_bsearch (source_filelist , file , pgFileCompareRelPathWithExternal ))
407
441
redundant = false;
408
442
@@ -411,6 +445,7 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
411
445
pg_strcasecmp (file -> name , RELMAPPER_FILENAME ) == 0 )
412
446
redundant = true;
413
447
448
+ //REVIEW This check seems unneded. Anyway we delete only redundant stuff below.
414
449
/* do not delete the useful internal directories */
415
450
if (S_ISDIR (file -> mode ) && !redundant )
416
451
continue ;
@@ -433,12 +468,16 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
433
468
}
434
469
}
435
470
471
+ //REVIEW Hmm. Why do we need this at all?
472
+ //I'd expect that we init pgfile with unset lock...
473
+ //Not related to this patch, though.
436
474
/* clear file locks */
437
475
pfilearray_clear_locks (source_filelist );
438
476
439
477
/* Sort by size for load balancing */
440
478
parray_qsort (source_filelist , pgFileCompareSize );
441
479
480
+ //REVIEW. This comment looks a bit misleading, since all theads share same filelist.
442
481
/* init thread args with own file lists */
443
482
threads = (pthread_t * ) palloc (sizeof (pthread_t ) * num_threads );
444
483
threads_args = (catchup_thread_runner_arg * ) palloc (sizeof (catchup_thread_runner_arg ) * num_threads );
@@ -499,9 +538,12 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
499
538
elog (ERROR , "Data files transferring failed, time elapsed: %s" ,
500
539
pretty_time );
501
540
541
+ //REVIEW The comment looks unrelated to the function. Do I miss something?
502
542
/* Notify end of backup */
503
543
pg_silent_client_messages (source_conn );
504
544
545
+ //REVIEW. Do we want to support pg 9.5? I suppose we never test it...
546
+ //Maybe check it and error out early?
505
547
/* Create restore point
506
548
* Only if backup is from master.
507
549
* For PG 9.5 create restore point only if pguser is superuser.
@@ -545,14 +587,17 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
545
587
stop_backup_result .tablespace_map_content_len = 0 ;
546
588
}
547
589
590
+ //REVIEW We don't pass a filelist. Please adjust the comment.
548
591
/* This function will also add list of xlog files
549
592
* to the passed filelist */
550
593
if (wait_WAL_streaming_end (NULL ))
551
594
elog (ERROR , "WAL streaming failed" );
552
595
596
+ //REVIEW Please add a comment about these lsns. It is a crutial part of the algorithm.
553
597
current .recovery_xid = stop_backup_result .snapshot_xid ;
554
598
555
599
elog (LOG , "Getting the Recovery Time from WAL" );
600
+
556
601
/* iterate over WAL from stop_backup lsn to start_backup lsn */
557
602
if (!read_recovery_info (dest_xlog_path , current .tli ,
558
603
instance_config .xlog_seg_size ,
@@ -566,6 +611,7 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
566
611
/* Cleanup */
567
612
pg_free (query_text );
568
613
614
+ //REVIEW Please adjust the comment.
569
615
/* In case of backup from replica >= 9.6 we must fix minRecPoint,
570
616
* First we must find pg_control in source_filelist.
571
617
*/
@@ -601,6 +647,7 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
601
647
/* construct fullpath */
602
648
if (file -> external_dir_num == 0 )
603
649
join_path_components (to_fullpath , dest_pgdata , file -> rel_path );
650
+ //REVIEW Let's clean this.
604
651
/* TODO разобраться с external */
605
652
/*else
606
653
{
@@ -638,6 +685,7 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
638
685
parray_walk (source_filelist , pgFileFree );
639
686
parray_free (source_filelist );
640
687
pgFileFree (source_pg_control_file );
688
+ //REVIEW Huh?
641
689
// где закрывается conn?
642
690
}
643
691
@@ -682,6 +730,7 @@ catchup_thread_runner(void *arg)
682
730
join_path_components (from_fullpath , arguments -> from_root , file -> rel_path );
683
731
join_path_components (to_fullpath , arguments -> to_root , file -> rel_path );
684
732
}
733
+ //REVIEW Let's clean this.
685
734
/*else
686
735
{
687
736
char external_dst[MAXPGPATH];
0 commit comments