s3-brlock: add a minimim retry time for pending blocking locks
authorAndrew Tridgell <tridge@samba.org>
Sat, 6 Feb 2010 04:59:43 +0000 (20:59 -0800)
committerJeremy Allison <jra@samba.org>
Sat, 6 Feb 2010 06:17:17 +0000 (22:17 -0800)
When we are waiting on a pending byte range lock, another smbd might
exit uncleanly, and therefore not notify us of the removal of the
lock, and thus not trigger the lock to be retried.

We coped with this up to now by adding a message_send_all() in the
SIGCHLD and cluster reconfigure handlers to send a MSG_SMB_UNLOCK to
all smbd processes. That would generate O(N^2) work when a large
number of clients disconnected at once (such as on a network outage),
which could leave the whole system unusable for a very long time (many
minutes, or even longer).

By adding a minimum re-check time for pending byte range locks we
avoid this problem by ensuring that pending locks are retried at a
more regular interval.

source3/smbd/blocking.c

index deb7f8f221d26acd20cc2c5cba4eb696bce1c5a6..6c7c167ab577d9f8804b48ce236b5ece6ec4ac9e 100644 (file)
@@ -72,6 +72,7 @@ static bool recalc_brl_timeout(void)
 {
        struct blocking_lock_record *blr;
        struct timeval next_timeout;
+       int max_brl_timeout = lp_parm_int(-1, "brl", "recalctime", 5);
 
        TALLOC_FREE(brl_timeout);
 
@@ -100,6 +101,25 @@ static bool recalc_brl_timeout(void)
                return True;
        }
 
+       /* 
+        to account for unclean shutdowns by clients we need a
+        maximum timeout that we use for checking pending locks. If
+        we have any pending locks at all, then check if the pending
+        lock can continue at least every brl:recalctime seconds
+        (default 5 seconds).
+
+        This saves us needing to do a message_send_all() in the
+        SIGCHLD handler in the parent daemon. That
+        message_send_all() caused O(n^2) work to be done when IP
+        failovers happened in clustered Samba, which could make the
+        entire system unusable for many minutes.
+       */
+
+       if (max_brl_timeout > 0) {
+               struct timeval min_to = timeval_current_ofs(max_brl_timeout, 0);
+               next_timeout = timeval_min(&next_timeout, &min_to);             
+       }
+
        if (DEBUGLVL(10)) {
                struct timeval cur, from_now;