#8 Two instances of updatedb

closed
nobody
None
5
2007-08-15
2007-06-01
No

Gentoo users have reported problems when 'rlocate -u' is run by two independent cron jobs at the same time.
While this is not supposed to happen to the cron daemon, I believe it should still also be prevented by rlocate itself.
When trying to reproduce this behavior, I came across this error:

updatedb: rlocate_end_updatedb: unlink: can't unlink /var/lib/rlocate/rlocate.db.diff.tmp: No such file or directory
updatedb: fatal error: create_db(): rename(): Could not rename '/var/lib/rlocate/rlocate.db.stf' to '/var/lib/rlocate/rlocate.db': No such file or directory

This is different to the description at
http://bugs.gentoo.org/show_bug.cgi?id=151856
but might still be a problem.

Discussion

  • Nobody/Anonymous

    Logged In: NO

    With a clean cron setup, this problem is -almost- gone:

    === Quote: ===
    Yes, I did encounter it once or twice after I cleaned my cron setup. But it's not regularly and not that often than it was before. I think I shut down my computer during a running updatedb so that it couldn't finish correctly and delete the temp file.
    Maybe there could be really a bug in rlocate that it doesn't delete the temp file when it gets a kill signal. But I'm not sure.
    ==============

    I think what needs to be done here are two steps:
    1. Make updatedb aware of other instances, so it will only run once at a time.
    2. If a stale .db.stf file is found, it should simply be deleted, as there is no process using it.

     
  • Rudi Lippert

    Rudi Lippert - 2007-06-06

    Logged In: YES
    user_id=946705
    Originator: YES

    Here is some pseudo-code that would probably do the trick (to use at the start of updatedb):

    if (file_exists(UPDATEDB_PID)) {
    int upid = readfrom(UPDATEDB_PID);
    if (process_exists(upid)) {
    return 1; // Another instance of updatedb is still running
    }
    if (file_exists(STFFILE)) {
    unlink(STFFILE);
    }
    unlink(UPDATEDB_PID);
    write_own_pid_to(UPDATEDB_PID);
    // And now go ahead
    }

    The pid file should of course be deleted after a clean run of updatedb.
    Also, maybe updatedb could clean up the pid file and the stf on SIGTERM as well.

    Any chance this could get into 0.5.6?

     
  • Rasto Levrinc

    Rasto Levrinc - 2007-06-12

    Logged In: YES
    user_id=1203732
    Originator: NO

    Yes, I plan to fix it, although it's complicated by the fact, that there can be more instances of updatedb running at the same time, if they use different databases. This is useful for example when using rlocate with nfs. So the pseudo-code from lyrikpage wouldn't do the trick.

     
  • Rasto Levrinc

    Rasto Levrinc - 2007-08-15

    Logged In: YES
    user_id=1203732
    Originator: NO

    fixed in 0.5.6

     
  • Rasto Levrinc

    Rasto Levrinc - 2007-08-15
    • status: open --> closed
     

Log in to post a comment.