@@ -166,6 +166,9 @@ write_backup_status(pgBackup *backup, BackupStatus status,
166
166
*
167
167
* TODO: lock-timeout as parameter
168
168
* TODO: we must think about more fine grain unlock mechanism - separate unlock_backup() function.
169
+ * TODO: more accurate naming
170
+ * -> exclusive lock -> acquire HW_LATCH and wait until all LW_LATCH`es are clear
171
+ * -> shared lock -> acquire HW_LATCH, acquire LW_LATCH, release HW_LATCH
169
172
*/
170
173
bool
171
174
lock_backup (pgBackup * backup , bool strict , bool exclusive )
@@ -264,45 +267,13 @@ lock_backup_exclusive(pgBackup *backup, bool strict)
264
267
int empty_tries = LOCK_STALE_TIMEOUT ;
265
268
int len ;
266
269
int encoded_pid ;
267
- pid_t my_p_pid ;
268
270
269
271
join_path_components (lock_file , backup -> root_dir , BACKUP_LOCK_FILE );
270
272
271
- /*
272
- * TODO: is this stuff with ppid below is relevant for us ?
273
- *
274
- * If the PID in the lockfile is our own PID or our parent's or
275
- * grandparent's PID, then the file must be stale (probably left over from
276
- * a previous system boot cycle). We need to check this because of the
277
- * likelihood that a reboot will assign exactly the same PID as we had in
278
- * the previous reboot, or one that's only one or two counts larger and
279
- * hence the lockfile's PID now refers to an ancestor shell process. We
280
- * allow pg_ctl to pass down its parent shell PID (our grandparent PID)
281
- * via the environment variable PG_GRANDPARENT_PID; this is so that
282
- * launching the postmaster via pg_ctl can be just as reliable as
283
- * launching it directly. There is no provision for detecting
284
- * further-removed ancestor processes, but if the init script is written
285
- * carefully then all but the immediate parent shell will be root-owned
286
- * processes and so the kill test will fail with EPERM. Note that we
287
- * cannot get a false negative this way, because an existing postmaster
288
- * would surely never launch a competing postmaster or pg_ctl process
289
- * directly.
290
- */
291
- #ifndef WIN32
292
- my_p_pid = getppid ();
293
- #else
294
-
295
- /*
296
- * Windows hasn't got getppid(), but doesn't need it since it's not using
297
- * real kill() either...
298
- */
299
- my_p_pid = 0 ;
300
- #endif
301
-
302
273
/*
303
274
* We need a loop here because of race conditions. But don't loop forever
304
275
* (for example, a non-writable $backup_instance_path directory might cause a failure
305
- * that won't go away). 100 tries seems like plenty.
276
+ * that won't go away).
306
277
*/
307
278
do
308
279
{
@@ -396,14 +367,12 @@ lock_backup_exclusive(pgBackup *backup, bool strict)
396
367
397
368
/*
398
369
* Check to see if the other process still exists
399
- *
400
- * Per discussion above, my_pid, my_p_pid can be
401
- * ignored as false matches.
402
- *
403
370
* Normally kill() will fail with ESRCH if the given PID doesn't
404
371
* exist.
405
372
*/
406
- if (encoded_pid != my_pid && encoded_pid != my_p_pid )
373
+ if (encoded_pid == my_pid )
374
+ return 0 ;
375
+ else
407
376
{
408
377
if (kill (encoded_pid , 0 ) == 0 )
409
378
{
@@ -508,6 +477,10 @@ lock_backup_exclusive(pgBackup *backup, bool strict)
508
477
lock_file , strerror (save_errno ));
509
478
}
510
479
480
+ // elog(LOG, "Acquired exclusive lock for backup %s after %ds",
481
+ // base36enc(backup->start_time),
482
+ // LOCK_TIMEOUT - ntries + LOCK_STALE_TIMEOUT - empty_tries);
483
+
511
484
return 0 ;
512
485
}
513
486
0 commit comments