comparison src/doveadm/dsync/dsync-brain.c @ 22716:6287c6d66f56

dsync: Add debug logging for .dovecot-sync.lock locking/unlocking
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 28 Dec 2017 10:27:27 +0200
parents 20415dd0b85a
children 02aed723d139
comparison
equal deleted inserted replaced
22715:20415dd0b85a 22716:6287c6d66f56
374 pool_unref(&brain->dsync_box_pool); 374 pool_unref(&brain->dsync_box_pool);
375 375
376 if (brain->lock_fd != -1) { 376 if (brain->lock_fd != -1) {
377 /* unlink the lock file before it gets unlocked */ 377 /* unlink the lock file before it gets unlocked */
378 i_unlink(brain->lock_path); 378 i_unlink(brain->lock_path);
379 if (brain->debug) {
380 i_debug("brain %c: Unlocked %s",
381 brain->master_brain ? 'M' : 'S',
382 brain->lock_path);
383 }
379 file_lock_free(&brain->lock); 384 file_lock_free(&brain->lock);
380 i_close_fd(&brain->lock_fd); 385 i_close_fd(&brain->lock_fd);
381 } 386 }
382 387
383 ret = brain->failed ? -1 : 0; 388 ret = brain->failed ? -1 : 0;
394 { 399 {
395 const struct file_create_settings lock_set = { 400 const struct file_create_settings lock_set = {
396 .lock_timeout_secs = brain->lock_timeout, 401 .lock_timeout_secs = brain->lock_timeout,
397 .lock_method = FILE_LOCK_METHOD_FCNTL, 402 .lock_method = FILE_LOCK_METHOD_FCNTL,
398 }; 403 };
399 const char *home, *error; 404 const char *home, *error, *local_hostname = my_hostdomain();
400 bool created; 405 bool created;
401 int ret; 406 int ret;
402 407
403 if ((ret = strcmp(remote_hostname, my_hostdomain())) < 0) { 408 if ((ret = strcmp(remote_hostname, local_hostname)) < 0) {
404 /* locking done by remote */ 409 /* locking done by remote */
410 if (brain->debug) {
411 i_debug("brain %c: Locking done by remote "
412 "(local hostname=%s, remote hostname=%s)",
413 brain->master_brain ? 'M' : 'S',
414 local_hostname, remote_hostname);
415 }
405 return 0; 416 return 0;
406 } 417 }
407 if (ret == 0 && !brain->master_brain) { 418 if (ret == 0 && !brain->master_brain) {
408 /* running dsync within the same server. 419 /* running dsync within the same server.
409 locking done by master brain. */ 420 locking done by master brain. */
421 if (brain->debug) {
422 i_debug("brain %c: Locking done by local master-brain "
423 "(local hostname=%s, remote hostname=%s)",
424 brain->master_brain ? 'M' : 'S',
425 local_hostname, remote_hostname);
426 }
410 return 0; 427 return 0;
411 } 428 }
412 429
413 if ((ret = mail_user_get_home(brain->user, &home)) < 0) { 430 if ((ret = mail_user_get_home(brain->user, &home)) < 0) {
414 i_error("Couldn't look up user's home dir"); 431 i_error("Couldn't look up user's home dir");
425 "/"DSYNC_LOCK_FILENAME, NULL); 442 "/"DSYNC_LOCK_FILENAME, NULL);
426 brain->lock_fd = file_create_locked(brain->lock_path, &lock_set, 443 brain->lock_fd = file_create_locked(brain->lock_path, &lock_set,
427 &brain->lock, &created, &error); 444 &brain->lock, &created, &error);
428 if (brain->lock_fd == -1) 445 if (brain->lock_fd == -1)
429 i_error("Couldn't lock %s: %s", brain->lock_path, error); 446 i_error("Couldn't lock %s: %s", brain->lock_path, error);
447 else if (brain->debug) {
448 i_debug("brain %c: Locking done locally in %s "
449 "(local hostname=%s, remote hostname=%s)",
450 brain->master_brain ? 'M' : 'S',
451 brain->lock_path, local_hostname, remote_hostname);
452 }
430 if (brain->verbose_proctitle) 453 if (brain->verbose_proctitle)
431 process_title_set(dsync_brain_get_proctitle(brain)); 454 process_title_set(dsync_brain_get_proctitle(brain));
432 return brain->lock_fd == -1 ? -1 : 0; 455 return brain->lock_fd == -1 ? -1 : 0;
433 } 456 }
434 457