From: wessels <> Date: Wed, 15 Jul 1998 02:54:53 +0000 (+0000) Subject: Added time_t StoreEntry->refresh for cache digests. X-Git-Tag: SQUID_3_0_PRE1~3094 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6fd3381ce2715be4fde056819d20cf0756a1510;p=thirdparty%2Fsquid.git Added time_t StoreEntry->refresh for cache digests. Don't need to compile a lot of the store_digest code when USE_CACHE_DIGESTS is not set --- diff --git a/src/protos.h b/src/protos.h index 7c108ff3c5..33f950c0ff 100644 --- a/src/protos.h +++ b/src/protos.h @@ -782,7 +782,6 @@ extern EVH storeDirClean; extern void storeDigestInit(); extern void storeDigestNoteStoreReady(); extern void storeDigestScheduleRebuild(); -extern void storeDigestAdd(const StoreEntry * entry); extern void storeDigestDel(const StoreEntry * entry); extern void storeDigestReport(); diff --git a/src/store.cc b/src/store.cc index 5df41faabf..2115b40195 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.425 1998/07/07 02:54:17 wessels Exp $ + * $Id: store.cc,v 1.426 1998/07/14 20:54:54 wessels Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -988,7 +988,9 @@ storeTimestampsSet(StoreEntry * entry) if (entry->lastmod < 0) entry->lastmod = served_date; entry->timestamp = served_date; - +#if USE_CACHE_DIGESTS + entry->refresh = refreshWhen(entry); +#endif } void diff --git a/src/store_digest.cc b/src/store_digest.cc index 2d41cb46eb..e50b3a453c 100644 --- a/src/store_digest.cc +++ b/src/store_digest.cc @@ -1,5 +1,5 @@ /* - * $Id: store_digest.cc,v 1.20 1998/06/05 22:37:45 rousskov Exp $ + * $Id: store_digest.cc,v 1.21 1998/07/14 20:54:56 wessels Exp $ * * DEBUG: section 71 Store Digest Manager * AUTHOR: Alex Rousskov @@ -37,7 +37,11 @@ #include "squid.h" -/* local types */ +#if USE_CACHE_DIGESTS + +/* + * local types + */ typedef struct { StoreDigestCBlock cblock; @@ -79,44 +83,100 @@ static StoreDigestStats sd_stats; /* local prototypes */ static void storeDigestRebuildStart(void *datanotused); -static void storeDigestRebuildResume(); -static void storeDigestRebuildFinish(); +static void storeDigestRebuildResume(void); +static void storeDigestRebuildFinish(void); static void storeDigestRebuildStep(void *datanotused); -static void storeDigestRewriteStart(); -static void storeDigestRewriteResume(); +static void storeDigestRewriteStart(void *); +static void storeDigestRewriteResume(void); static void storeDigestRewriteFinish(StoreEntry * e); static EVH storeDigestSwapOutStep; static void storeDigestCBlockSwapOut(StoreEntry * e); -static int storeDigestCalcCap(); -static int storeDigestResize(); +static int storeDigestCalcCap(void); +static int storeDigestResize(void); +static void storeDigestAdd(const StoreEntry *); +#endif /* USE_CACHE_DIGESTS */ + +/* + * PUBLIC FUNCTIONS + */ void -storeDigestInit() +storeDigestInit(void) { #if USE_CACHE_DIGESTS const int cap = storeDigestCalcCap(); store_digest = cacheDigestCreate(cap, StoreDigestBitsPerEntry); debug(71, 1) ("Local cache digest enabled; rebuild/rewrite every %d/%d sec\n", StoreDigestRebuildPeriod, StoreDigestRewritePeriod); -#else - store_digest = NULL; - debug(71, 1) ("Local cache digest is 'off'\n"); -#endif memset(&sd_state, 0, sizeof(sd_state)); cachemgrRegister("store_digest", "Store Digest", storeDigestReport, 0); +#else + store_digest = NULL; + debug(71, 3) ("Local cache digest is 'off'\n"); +#endif } /* called when store_rebuild completes */ void -storeDigestNoteStoreReady() +storeDigestNoteStoreReady(void) { +#if USE_CACHE_DIGESTS storeDigestRebuildStart(NULL); storeDigestRewriteStart(NULL); +#endif +} + +void +storeDigestDel(const StoreEntry * entry) +{ +#if USE_CACHE_DIGESTS + assert(entry && store_digest); + debug(71, 6) ("storeDigestDel: checking entry, key: %s\n", + storeKeyText(entry->key)); + if (!EBIT_TEST(entry->flag, KEY_PRIVATE)) { + if (!cacheDigestTest(store_digest, entry->key)) { + sd_stats.del_lost_count++; + debug(71, 6) ("storeDigestDel: lost entry, key: %s url: %s\n", + storeKeyText(entry->key), storeUrl(entry)); + } else { + sd_stats.del_count++; + cacheDigestDel(store_digest, entry->key); + debug(71, 6) ("storeDigestDel: deled entry, key: %s\n", + storeKeyText(entry->key)); + } + } +#endif } void +storeDigestReport(StoreEntry * e) +{ +#if USE_CACHE_DIGESTS + if (store_digest) { + cacheDigestReport(store_digest, "store", e); + storeAppendPrintf(e, "\t added: %d rejected: %d ( %.2f %%) del-ed: %d\n", + sd_stats.add_count, + sd_stats.rej_count, + xpercent(sd_stats.rej_count, sd_stats.rej_count + sd_stats.add_count), + sd_stats.del_count); + storeAppendPrintf(e, "\t collisions: on add: %.2f %% on rej: %.2f %%\n", + xpercent(sd_stats.add_coll_count, sd_stats.add_count), + xpercent(sd_stats.rej_coll_count, sd_stats.rej_count)); + } else { + storeAppendPrintf(e, "store digest: disabled.\n"); + } +#endif +} + +/* + * LOCAL FUNCTIONS + */ + +#if USE_CACHE_DIGESTS + +static void storeDigestAdd(const StoreEntry * entry) { int good_entry = 0; @@ -125,12 +185,11 @@ storeDigestAdd(const StoreEntry * entry) storeKeyText(entry->key)); /* only public entries are digested */ if (!EBIT_TEST(entry->flag, KEY_PRIVATE)) { - const time_t expires = refreshWhen(entry); debug(71, 6) ("storeDigestAdd: entry expires in %d secs\n", - (int) (expires - squid_curtime)); + (int) (entry->refresh - squid_curtime)); /* if expires too soon, ignore */ /* Note: We should use the time of the next rebuild, not cur_time @?@ */ - if (expires <= squid_curtime + StoreDigestRebuildPeriod) { + if (entry->refresh <= squid_curtime + StoreDigestRebuildPeriod) { debug(71, 6) ("storeDigestAdd: entry expires too early, ignoring\n"); } else { good_entry = 1; @@ -150,26 +209,6 @@ storeDigestAdd(const StoreEntry * entry) } } -void -storeDigestDel(const StoreEntry * entry) -{ - assert(entry && store_digest); - debug(71, 6) ("storeDigestDel: checking entry, key: %s\n", - storeKeyText(entry->key)); - if (!EBIT_TEST(entry->flag, KEY_PRIVATE)) { - if (!cacheDigestTest(store_digest, entry->key)) { - sd_stats.del_lost_count++; - debug(71, 6) ("storeDigestDel: lost entry, key: %s url: %s\n", - storeKeyText(entry->key), storeUrl(entry)); - } else { - sd_stats.del_count++; - cacheDigestDel(store_digest, entry->key); - debug(71, 6) ("storeDigestDel: deled entry, key: %s\n", - storeKeyText(entry->key)); - } - } -} - /* rebuilds digest from scratch */ static void storeDigestRebuildStart(void *datanotused) @@ -191,7 +230,7 @@ storeDigestRebuildStart(void *datanotused) /* called be Rewrite to push Rebuild forward */ static void -storeDigestRebuildResume() +storeDigestRebuildResume(void) { assert(sd_state.rebuild_lock); assert(!sd_state.rewrite_lock); @@ -205,7 +244,7 @@ storeDigestRebuildResume() /* finishes swap out sequence for the digest; schedules next rebuild */ static void -storeDigestRebuildFinish() +storeDigestRebuildFinish(void) { assert(sd_state.rebuild_lock); sd_state.rebuild_lock = 0; @@ -275,7 +314,7 @@ storeDigestRewriteStart(void *datanotused) } static void -storeDigestRewriteResume() +storeDigestRewriteResume(void) { StoreEntry *e = sd_state.rewrite_lock; @@ -363,7 +402,7 @@ storeDigestCBlockSwapOut(StoreEntry * e) /* calculates digest capacity */ static int -storeDigestCalcCap() +storeDigestCalcCap(void) { /* * To-Do: Bloom proved that the optimal filter utilization is 50% (half of @@ -387,7 +426,7 @@ storeDigestCalcCap() /* returns true if we actually resized the digest */ static int -storeDigestResize() +storeDigestResize(void) { const int cap = storeDigestCalcCap(); int diff; @@ -407,20 +446,4 @@ storeDigestResize() } } -void -storeDigestReport(StoreEntry * e) -{ - if (store_digest) { - cacheDigestReport(store_digest, "store", e); - storeAppendPrintf(e, "\t added: %d rejected: %d ( %.2f %%) del-ed: %d\n", - sd_stats.add_count, - sd_stats.rej_count, - xpercent(sd_stats.rej_count, sd_stats.rej_count + sd_stats.add_count), - sd_stats.del_count); - storeAppendPrintf(e, "\t collisions: on add: %.2f %% on rej: %.2f %%\n", - xpercent(sd_stats.add_coll_count, sd_stats.add_count), - xpercent(sd_stats.rej_coll_count, sd_stats.rej_count)); - } else { - storeAppendPrintf(e, "store digest: disabled.\n"); - } -} +#endif /* USE_CACHE_DIGESTS */ diff --git a/src/structs.h b/src/structs.h index 3cea6a859c..c9461c47cb 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1093,6 +1093,9 @@ struct _StoreEntry { time_t lastref; time_t expires; time_t lastmod; +#if USE_CACHE_DIGESTS + time_t refresh; +#endif size_t swap_file_sz; u_short refcount; u_short flag;