krb5 commit [krb5-1.12]: Reinitialize ulog when wrapping serial number

Tom Yu tlyu at MIT.EDU
Thu Jun 26 16:06:34 EDT 2014


https://github.com/krb5/krb5/commit/fb5b9d2359f9820fd2c6f08a50472a921d9ca8de
commit fb5b9d2359f9820fd2c6f08a50472a921d9ca8de
Author: Greg Hudson <ghudson at mit.edu>
Date:   Tue Jan 21 10:58:04 2014 -0500

    Reinitialize ulog when wrapping serial number
    
    When we wrap the serial number, reinitialize the ulog so that kdb_num
    starts counting from 1, instead of leaving the ulog in a weird state
    where kdb_num == ulogentries but kdb_last_sno == 1 and the serial
    numbers in the circular array aren't necessarily contiguous.
    
    (cherry picked from commit 3c147860df11d8ef24dabf07d32f36915f3b640c)
    
    ticket: 7839
    version_fixed: 1.12.2
    status: resolved

 src/lib/kdb/kdb_log.c |   21 ++++++++-------------
 1 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/lib/kdb/kdb_log.c b/src/lib/kdb/kdb_log.c
index d8d338c..21cb09d 100644
--- a/src/lib/kdb/kdb_log.c
+++ b/src/lib/kdb/kdb_log.c
@@ -35,6 +35,7 @@ static int pagesize = 0;
     assert(ulog != NULL)
 
 static int extend_file_to(int fd, unsigned int new_size);
+static void ulog_reset(kdb_hlog_t *ulog);
 
 static inline krb5_boolean
 time_equal(const kdbe_time_t *a, const kdbe_time_t *b)
@@ -180,19 +181,13 @@ ulog_add_update(krb5_context context, kdb_incr_update_t *upd)
             return retval;
     }
 
-    cur_sno = ulog->kdb_last_sno;
-
-    /*
-     * If we need to, wrap our sno around to 1.  A slaves will do a full resync
-     * since its sno will be out of range of the ulog (or in extreme cases,
-     * its timestamp won't match).
-     */
-    if (cur_sno == (kdb_sno_t)-1)
-        cur_sno = 1;
-    else
-        cur_sno++;
+    /* If we have reached the last possible serial number, reinitialize the
+     * ulog and start over.  Slaves will do a full resync. */
+    if (ulog->kdb_last_sno == (kdb_sno_t)-1)
+        ulog_reset(ulog);
 
-    /* Squirrel this away for finish_update() to index. */
+    /* Get the next serial number and save it for finish_update() to index. */
+    cur_sno = ulog->kdb_last_sno + 1;
     upd->kdb_entry_sno = cur_sno;
 
     i = (cur_sno - 1) % ulogentries;
@@ -229,7 +224,7 @@ ulog_add_update(krb5_context context, kdb_incr_update_t *upd)
         ulog->kdb_first_sno = indx_log->kdb_entry_sno;
         ulog->kdb_first_time = indx_log->kdb_time;
     } else if (cur_sno == 1) {
-        /* This is the first update, or we wrapped. */
+        /* This is the first update. */
         ulog->kdb_first_sno = 1;
         ulog->kdb_first_time = indx_log->kdb_time;
     }


More information about the cvs-krb5 mailing list