vacuum: Only run full vacuumig (db traverse) every VacuumFastPathCount times.
authorMichael Adam <obnox@samba.org>
Mon, 20 Dec 2010 17:03:38 +0000 (18:03 +0100)
committerMichael Adam <obnox@samba.org>
Wed, 9 Mar 2011 23:37:02 +0000 (00:37 +0100)
server/ctdb_vacuum.c

index b6fff1e3405af4b3ce0f011a79a587202676b470..28d9a9361761629f875b6afc8111c6cb2c997dde 100644 (file)
@@ -375,7 +375,9 @@ done:
  * records on the other nodes
  * this executes in the child context
  */
-static int ctdb_vacuum_db(struct ctdb_db_context *ctdb_db, struct vacuum_data *vdata)
+static int ctdb_vacuum_db(struct ctdb_db_context *ctdb_db,
+                         struct vacuum_data *vdata,
+                         bool full_vacuum_run)
 {
        struct ctdb_context *ctdb = ctdb_db->ctdb;
        const char *name = ctdb_db->db_name;
@@ -417,11 +419,19 @@ static int ctdb_vacuum_db(struct ctdb_db_context *ctdb_db, struct vacuum_data *v
         */
        trbt_traversearray32(ctdb_db->delete_queue, 1, delete_queue_traverse, vdata);
 
-       /* read-only traverse, looking for records that might be able to be vacuumed */
-       if (tdb_traverse_read(ctdb_db->ltdb->tdb, vacuum_traverse, vdata) == -1 ||
-           vdata->traverse_error) {
-               DEBUG(DEBUG_ERR,(__location__ " Traverse error in vacuuming '%s'\n", name));
-               return -1;              
+       /*
+        * read-only traverse of the database, looking for records that
+        * might be able to be vacuumed.
+        *
+        * This is not done each time but only every tunable
+        * VacuumFastPathCount times.
+        */
+       if (full_vacuum_run) {
+               ret = tdb_traverse_read(ctdb_db->ltdb->tdb, vacuum_traverse, vdata);
+               if (ret == -1 || vdata->traverse_error) {
+                       DEBUG(DEBUG_ERR,(__location__ " Traverse error in vacuuming '%s'\n", name));
+                       return -1;
+               }
        }
 
        /*
@@ -802,7 +812,8 @@ static int update_tuning_db(struct ctdb_db_context *ctdb_db, struct vacuum_data
  * called from the child context
  */
 static int ctdb_vacuum_and_repack_db(struct ctdb_db_context *ctdb_db,
-                                    TALLOC_CTX *mem_ctx)
+                                    TALLOC_CTX *mem_ctx,
+                                    bool full_vacuum_run)
 {
        uint32_t repack_limit = ctdb_db->ctdb->tunable.repack_limit;
        uint32_t vacuum_limit = ctdb_db->ctdb->tunable.vacuum_limit;
@@ -838,7 +849,7 @@ static int ctdb_vacuum_and_repack_db(struct ctdb_db_context *ctdb_db,
        /*
         * gather all records that can be deleted in vdata
         */
-       if (ctdb_vacuum_db(ctdb_db, vdata) != 0) {
+       if (ctdb_vacuum_db(ctdb_db, vdata, full_vacuum_run) != 0) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to vacuum '%s'\n", name));
        }
 
@@ -1046,6 +1057,7 @@ ctdb_vacuum_event(struct event_context *ev, struct timed_event *te,
 
        if (child_ctx->child_pid == 0) {
                char cc = 0;
+               bool full_vacuum_run = false;
                close(child_ctx->fd[0]);
 
                DEBUG(DEBUG_INFO,("Vacuuming child process %d for db %s started\n", getpid(), ctdb_db->db_name));
@@ -1058,7 +1070,11 @@ ctdb_vacuum_event(struct event_context *ev, struct timed_event *te,
                /* 
                 * repack the db
                 */
-               cc = ctdb_vacuum_and_repack_db(ctdb_db, child_ctx);
+               if (vacuum_handle->fast_path_count == 0) {
+                       full_vacuum_run = true;
+               }
+               cc = ctdb_vacuum_and_repack_db(ctdb_db, child_ctx,
+                                              full_vacuum_run);
 
                write(child_ctx->fd[1], &cc, 1);
                _exit(0);