]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Alex Rousskov <rousskov@measurement-factory.com>
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 3 Sep 2009 12:57:49 +0000 (00:57 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 3 Sep 2009 12:57:49 +0000 (00:57 +1200)
Fixed entry size calculation for the max-size cache_dir selection algorithms.

There were two sides of this bug:

In src/store_swapout.cc, we must create metadata earlier because
storeCreate() needs swap_hdr_sz. With swap_hdr_sz unknown at the time of
storeCreate(), the SwapDir selection algorithms may select SwapDirs that
should not really take the entry as the real storage size (with the
metadata swap_hdr_sz) would exceed the store slot size.

In src/store_dir.cc, we must add the metadata size before looking for
cache_dirs that accept objsize. Only the "new"
storeDirSelectSwapDirRoundRobin selection scheme was affected.

src/store_dir.cc
src/store_swapout.cc

index e3b7ae3e80b6b79c619bdb15717c235aca8f85d3..087c7e2416299b9b1dbcb5ad3d51ae7e04d9a65b 100644 (file)
@@ -189,6 +189,10 @@ storeDirSelectSwapDirRoundRobin(const StoreEntry * e)
     int load;
     RefCount<SwapDir> sd;
 
+    ssize_t objsize = e->objectLen();
+    if (objsize != -1)
+        objsize += e->mem_obj->swap_hdr_sz;
+
     for (i = 0; i <= Config.cacheSwap.n_configured; i++) {
         if (++dirn >= Config.cacheSwap.n_configured)
             dirn = 0;
@@ -201,7 +205,7 @@ storeDirSelectSwapDirRoundRobin(const StoreEntry * e)
         if (sd->cur_size > sd->max_size)
             continue;
 
-        if (!sd->objectSizeIsAcceptable(e->objectLen()))
+        if (!sd->objectSizeIsAcceptable(objsize))
             continue;
 
         /* check for error or overload condition */
index 75ccf07693bf37492d0091a482775c07de527291..3ba12d7de1b4de6689c5446bc5dedb3338a69aa5 100644 (file)
@@ -63,6 +63,15 @@ storeSwapOutStart(StoreEntry * e)
     /* If we start swapping out objects with OutOfBand Metadata,
      * then this code needs changing
      */
+
+    /* TODO: make some sort of data,size refcounted immutable buffer
+     * and stop fooling ourselves with "const char*" buffers.
+     */
+
+    // Create metadata now, possibly in vain: storeCreate needs swap_hdr_sz.
+    const char *buf = e->getSerialisedMetaData ();
+    assert(buf);
+
     /* Create the swap file */
     generic_cbdata *c = new generic_cbdata(e);
     sio = storeCreate(e, storeSwapOutFileNotify, storeSwapOutFileClosed, c);
@@ -70,6 +79,7 @@ storeSwapOutStart(StoreEntry * e)
     if (sio == NULL) {
         e->swap_status = SWAPOUT_NONE;
         delete c;
+        xfree((char*)buf);
         storeLog(STORE_LOG_SWAPOUTFAIL, e);
         return;
     }
@@ -87,16 +97,6 @@ storeSwapOutStart(StoreEntry * e)
     e->swap_dirn = mem->swapout.sio->swap_dirn;
 
     /* write out the swap metadata */
-    /* TODO: make some sort of data,size refcounted immutable buffer
-     * for use by this sort of function.
-     */
-    char const *buf = e->getSerialisedMetaData ();
-
-    /* If we start swapping out with out of band metadata, this assert
-     * will catch it - this code needs to be adjusted if that happens
-     */
-    assert (buf);
-
     storeIOWrite(mem->swapout.sio, buf, mem->swap_hdr_sz, 0, xfree);
 }