summaryrefslogtreecommitdiffstats
path: root/src/lib/kdb
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2013-01-22 17:42:37 -0500
committerGreg Hudson <ghudson@mit.edu>2013-01-22 17:49:50 -0500
commit7665c0677b59574c2c7ccd016221f8f4beafd279 (patch)
treed1ec1717f811370bc9e0fdd0262ea7086dfd0055 /src/lib/kdb
parent4b3937182b75e08eaf8f259828b018a2b6d2c111 (diff)
downloadkrb5-7665c0677b59574c2c7ccd016221f8f4beafd279.tar.gz
krb5-7665c0677b59574c2c7ccd016221f8f4beafd279.tar.xz
krb5-7665c0677b59574c2c7ccd016221f8f4beafd279.zip
Fix iprop log reinitialization
If the master iprop log is reinitialized to serial number 0, slaves will need to take a full dump--but after that happens, we need to know whether the slave has taken that full dump, we we don't offering full dumps indefinitely. So, record a timestamp in kdb_last_time when we reinitialize the log header, and compare the slave timestamp to kdb_last_time whenever it has the current serial number, even if it's 0. Test this by performing a propagation with sno 0 in t_iprop.py and detecting whether kpropd gets a second UPDATE_FULL_RESYNC_NEEDED response from kadmind. ticket: 7550 (new)
Diffstat (limited to 'src/lib/kdb')
-rw-r--r--src/lib/kdb/kdb_log.c53
-rw-r--r--src/lib/kdb/libkdb5.exports1
2 files changed, 41 insertions, 13 deletions
diff --git a/src/lib/kdb/kdb_log.c b/src/lib/kdb/kdb_log.c
index f70d3fed3b..017c41ad14 100644
--- a/src/lib/kdb/kdb_log.c
+++ b/src/lib/kdb/kdb_log.c
@@ -36,6 +36,22 @@ static int pagesize = 0;
static int extend_file_to(int fd, unsigned int new_size);
+static inline krb5_boolean
+time_equal(const kdbe_time_t *a, const kdbe_time_t *b)
+{
+ return a->seconds == b->seconds && a->useconds == b->useconds;
+}
+
+static void
+time_current(kdbe_time_t *out)
+{
+ struct timeval timestamp;
+
+ (void)gettimeofday(&timestamp, NULL);
+ out->seconds = timestamp.tv_sec;
+ out->useconds = timestamp.tv_usec;
+}
+
krb5_error_code
ulog_lock(krb5_context ctx, int mode)
{
@@ -135,7 +151,6 @@ ulog_add_update(krb5_context context, kdb_incr_update_t *upd)
{
XDR xdrs;
kdbe_time_t ktime;
- struct timeval timestamp;
kdb_ent_header_t *indx_log;
unsigned int i, recsize;
unsigned long upd_size;
@@ -153,9 +168,7 @@ ulog_add_update(krb5_context context, kdb_incr_update_t *upd)
if (upd == NULL)
return KRB5_LOG_ERROR;
- (void)gettimeofday(&timestamp, NULL);
- ktime.seconds = timestamp.tv_sec;
- ktime.useconds = timestamp.tv_usec;
+ time_current(&ktime);
upd_size = xdr_sizeof((xdrproc_t)xdr_kdb_incr_update_t, upd);
@@ -452,6 +465,19 @@ ulog_reset(kdb_hlog_t *ulog)
ulog->db_version_num = KDB_VERSION;
ulog->kdb_state = KDB_STABLE;
ulog->kdb_block = ULOG_BLOCK;
+ time_current(&ulog->kdb_last_time);
+}
+
+/* Reinitialize the log header. Locking is the caller's responsibility. */
+void
+ulog_init_header(krb5_context context)
+{
+ kdb_log_context *log_ctx;
+ kdb_hlog_t *ulog;
+
+ INIT_ULOG(context);
+ ulog_reset(ulog);
+ ulog_sync_header(ulog);
}
/*
@@ -669,10 +695,18 @@ ulog_get_entries(krb5_context context, kdb_last_t last,
return retval;
}
+ /* If we have the same sno and timestamp, return a nil update. If a
+ * different timestamp, the sno was reused and we need a full resync. */
+ if (last.last_sno == ulog->kdb_last_sno) {
+ ulog_handle->ret = time_equal(&last.last_time, &ulog->kdb_last_time) ?
+ UPDATE_NIL : UPDATE_FULL_RESYNC_NEEDED;
+ goto cleanup;
+ }
+
/* We may have overflowed the update log or shrunk the log, or the client
* may have created its ulog. */
if (last.last_sno > ulog->kdb_last_sno ||
- last.last_sno < ulog->kdb_first_sno || last.last_sno == 0) {
+ last.last_sno < ulog->kdb_first_sno) {
ulog_handle->lastentry.last_sno = ulog->kdb_last_sno;
ulog_handle->ret = UPDATE_FULL_RESYNC_NEEDED;
goto cleanup;
@@ -682,20 +716,13 @@ ulog_get_entries(krb5_context context, kdb_last_t last,
indx = (sno - 1) % ulogentries;
indx_log = (kdb_ent_header_t *)INDEX(ulog, indx);
- if (indx_log->kdb_time.seconds != last.last_time.seconds ||
- indx_log->kdb_time.useconds != last.last_time.useconds) {
+ if (!time_equal(&indx_log->kdb_time, &last.last_time)) {
/* We have time stamp mismatch or we no longer have the slave's last
* sno, so we brute force it. */
ulog_handle->ret = UPDATE_FULL_RESYNC_NEEDED;
goto cleanup;
}
- /* If we have the same sno we return success. */
- if (last.last_sno == ulog->kdb_last_sno) {
- ulog_handle->ret = UPDATE_NIL;
- goto cleanup;
- }
-
count = ulog->kdb_last_sno - sno;
upd = calloc(count, sizeof(kdb_incr_update_t));
if (upd == NULL) {
diff --git a/src/lib/kdb/libkdb5.exports b/src/lib/kdb/libkdb5.exports
index 43a361d0c4..7f83ed2a9e 100644
--- a/src/lib/kdb/libkdb5.exports
+++ b/src/lib/kdb/libkdb5.exports
@@ -85,6 +85,7 @@ krb5_db_delete_policy
krb5_db_free_policy
krb5_def_store_mkey_list
krb5_db_promote
+ulog_init_header
ulog_map
ulog_set_role
ulog_free_entries