ldb_tdb: Print progress messages on re-index
authorAndrew Bartlett <abartlet@samba.org>
Mon, 11 Sep 2017 01:16:31 +0000 (13:16 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:24 +0000 (21:20 +0200)
A re-index of 10,000 entries is slow enough and rare enought that we can
justify the message being at LDB_DEBUG_WARNING as otherwise the administrator
will be sure the "lockup" was one.

The default for ldb is to print LDB_DEBUG_WARNING in comand-line tools
and the default for Samba is to log it at level 2.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_index.c

index fb31ba509e0a358de819cbb1fc8e5a982eb53362..621d819ae8e95d5fe4fffca90f307defd60fa671 100644 (file)
@@ -2264,6 +2264,7 @@ static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, vo
 struct ltdb_reindex_context {
        struct ldb_module *module;
        int error;
+       uint32_t count;
 };
 
 /*
@@ -2368,6 +2369,13 @@ static int re_key(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *st
 
        talloc_free(msg);
 
+       ctx->count++;
+       if (ctx->count % 10000 == 0) {
+               ldb_debug(ldb, LDB_DEBUG_WARNING,
+                         "Reindexing: re-keyed %u records so far",
+                         ctx->count);
+       }
+
        return 0;
 }
 
@@ -2449,6 +2457,13 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *
 
        talloc_free(msg);
 
+       ctx->count++;
+       if (ctx->count % 10000 == 0) {
+               ldb_debug(ldb, LDB_DEBUG_WARNING,
+                         "Reindexing: re-indexed %u records so far",
+                         ctx->count);
+       }
+
        return 0;
 }
 
@@ -2498,6 +2513,7 @@ int ltdb_reindex(struct ldb_module *module)
 
        ctx.module = module;
        ctx.error = 0;
+       ctx.count = 0;
 
        /* now traverse adding any indexes for normal LDB records */
        ret = tdb_traverse(ltdb->tdb, re_key, &ctx);
@@ -2515,6 +2531,7 @@ int ltdb_reindex(struct ldb_module *module)
        }
 
        ctx.error = 0;
+       ctx.count = 0;
 
        /* now traverse adding any indexes for normal LDB records */
        ret = tdb_traverse(ltdb->tdb, re_index, &ctx);
@@ -2531,5 +2548,11 @@ int ltdb_reindex(struct ldb_module *module)
                return ctx.error;
        }
 
+       if (ctx.count > 10000) {
+               ldb_debug(ldb_module_get_ctx(module),
+                         LDB_DEBUG_WARNING, "Reindexing: re_index successful on %s, "
+                         "final index write-out will be in transaction commit",
+                         tdb_name(ltdb->tdb));
+       }
        return LDB_SUCCESS;
 }