Consolidate gencache also every 100 writes in a single process
authorVolker Lendecke <vl@samba.org>
Tue, 14 Jul 2009 16:31:28 +0000 (18:31 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 15 Jul 2009 08:55:20 +0000 (10:55 +0200)
source3/lib/gencache.c

index 6496ad3ed67ca53d3d2164a2ac5e3bd3fe4965cd..ee1f4b70b3fe89d8a9d55daf2e205adc6513dafb 100644 (file)
@@ -121,6 +121,7 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
        TDB_DATA databuf;
        char* val;
        time_t last_stabilize;
+       static int writecount;
 
        if (tdb_data_cmp(string_term_tdb_data(keystr),
                         last_stabilize_key()) == 0) {
@@ -162,6 +163,18 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
                return false;
        }
 
+       /*
+        * Every 100 writes within a single process, stabilize the cache with
+        * a transaction. This is done to prevent a single transaction to
+        * become huge and chew lots of memory.
+        */
+       writecount += 1;
+       if (writecount > lp_parm_int(-1, "gencache", "stabilize_count", 100)) {
+               gencache_stabilize();
+               writecount = 0;
+               goto done;
+       }
+
        /*
         * Every 5 minutes, call gencache_stabilize() to not let grow
         * gencache_notrans.tdb too large.
@@ -180,6 +193,7 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
                gencache_stabilize();
        }
 
+done:
        return ret == 0;
 }