ctdb_conn: Log long fetch_lock calls
authorVolker Lendecke <vl@samba.org>
Fri, 1 Feb 2013 11:49:52 +0000 (12:49 +0100)
committerVolker Lendecke <vl@samba.org>
Thu, 16 Jan 2014 08:18:45 +0000 (09:18 +0100)
With this patch, the number of fetch_lock attempts before dbwrap_ctdb
logs that it took x attempts to get a record is configurable with

net conf setparm global ctdb:migrate_attempts 10

This patch also adds

net conf setparm global ctdb:migrate_duration 5000

to trigger the same log message if it took longer than x milliseconds
to retrieve a record.

Reviewed-by: Christof Schmitt <cs@samba.org>
Signed-off-by: Volker Lendecke <vl@samba.org>
source3/lib/dbwrap/dbwrap_ctdb.c

index 5a473f98afe46a89616d82d6e47574b33cf7f8c1..fa2246b2a9db244cc0ec57daa272081fe7816c16 100644 (file)
@@ -1017,7 +1017,9 @@ static struct db_record *fetch_locked_internal(struct db_ctdb_ctx *ctx,
        struct db_ctdb_rec *crec;
        NTSTATUS status;
        TDB_DATA ctdb_data;
-       int migrate_attempts = 0;
+       int migrate_attempts;
+       struct timeval migrate_start;
+       int duration_msecs;
        int lockret;
 
        if (!(result = talloc(mem_ctx, struct db_record))) {
@@ -1044,6 +1046,9 @@ static struct db_record *fetch_locked_internal(struct db_ctdb_ctx *ctx,
                return NULL;
        }
 
+       migrate_attempts = 0;
+       GetTimeOfDay(&migrate_start);
+
        /*
         * Do a blocking lock on the record
         */
@@ -1110,13 +1115,26 @@ again:
                goto again;
        }
 
-       if (migrate_attempts > 10) {
+       {
+               double duration;
+               duration = timeval_elapsed(&migrate_start);
+
+               /*
+                * Convert the duration to milliseconds to avoid a
+                * floating-point division of
+                * lp_parm_int("migrate_duration") by 1000.
+                */
+               duration_msecs = duration * 1000;
+       }
+
+       if ((migrate_attempts > lp_parm_int(-1, "ctdb", "migrate_attempts", 10)) ||
+           (duration_msecs > lp_parm_int(-1, "ctdb", "migrate_duration", 5000))) {
                DEBUG(0, ("db_ctdb_fetch_locked for %s key %s needed %d "
-                         "attempts\n", tdb_name(ctx->wtdb->tdb),
+                         "attempts, %d milliseconds\n", tdb_name(ctx->wtdb->tdb),
                          hex_encode_talloc(talloc_tos(),
                                            (unsigned char *)key.dptr,
                                            key.dsize),
-                         migrate_attempts));
+                         migrate_attempts, duration_msecs));
        }
 
        GetTimeOfDay(&crec->lock_time);