From: wessels <> Date: Fri, 6 Sep 1996 01:02:51 +0000 (+0000) Subject: - added Config.expireAge and 'expire_age' to config; X-Git-Tag: SQUID_3_0_PRE1~5849 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79b5cc5fa55b7e1f9b5ed8ceeb68ed17ab8d97eb;p=thirdparty%2Fsquid.git - added Config.expireAge and 'expire_age' to config; - Replaced some parsing functions with parseMinutesLine() - Added StoreEntry flag bit ENTRY_NEGCACHED. - Added storeNegativeCache(). --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index eb3816c5d4..00d32c5340 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,5 +1,5 @@ /* - * $Id: cache_cf.cc,v 1.82 1996/09/04 23:42:01 wessels Exp $ + * $Id: cache_cf.cc,v 1.83 1996/09/05 19:02:51 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -125,6 +125,7 @@ struct SquidConfig Config; #define DefaultWaisRelayHost (char *)NULL #define DefaultWaisRelayPort 0 +#define DefaultExpireAge (86400 * 7) /* 1 week */ #define DefaultNegativeTtl (5 * 60) /* 5 min */ #define DefaultNegativeDnsTtl (2 * 60) /* 2 min */ #define DefaultPositiveDnsTtl (360 * 60) /* 6 hours */ @@ -217,7 +218,6 @@ static void parseAnnounceToLine _PARAMS((void)); static void parseAppendDomainLine _PARAMS((void)); static void parseCacheAnnounceLine _PARAMS((void)); static void parseCacheHostLine _PARAMS((void)); -static void parseCleanRateLine _PARAMS((void)); static void parseDebugOptionsLine _PARAMS((void)); static void parseDirLine _PARAMS((void)); static void parseDnsProgramLine _PARAMS((void)); @@ -239,23 +239,19 @@ static void parseHttpdAccelLine _PARAMS((void)); static void parseIPLine _PARAMS((ip_acl ** list)); static void parseIcpPortLine _PARAMS((void)); static void parseInsideFirewallLine _PARAMS((void)); -static void parseLifetimeLine _PARAMS((void)); static void parseLocalDomainFile _PARAMS((char *fname)); static void parseLocalDomainLine _PARAMS((void)); static void parseLogLine _PARAMS((void)); static void parseMemLine _PARAMS((void)); static void parseMgrLine _PARAMS((void)); -static void parseNegativeDnsLine _PARAMS((void)); -static void parseNegativeLine _PARAMS((void)); static void parsePidFilenameLine _PARAMS((void)); -static void parsePositiveDnsLine _PARAMS((void)); -static void parseReadTimeoutLine _PARAMS((void)); static void parseRequestSizeLine _PARAMS((void)); static void parseStoreLogLine _PARAMS((void)); static void parseSwapLine _PARAMS((void)); static void parseTTLPattern _PARAMS((int icase, int force)); static void parseVisibleHostnameLine _PARAMS((void)); static void parseWAISRelayLine _PARAMS((void)); +static void parseMinutesLine _PARAMS((int *)); void self_destruct() { @@ -632,52 +628,13 @@ static void parseQuickAbort() } } -static void parseNegativeLine() -{ - char *token; - int i; - GetInteger(i); - Config.negativeTtl = i * 60; -} - -static void parseNegativeDnsLine() -{ - char *token; - int i; - GetInteger(i); - Config.negativeDnsTtl = i * 60; -} - -static void parsePositiveDnsLine() -{ - char *token; - int i; - GetInteger(i); - Config.positiveDnsTtl = i * 60; -} - -static void parseReadTimeoutLine() -{ - char *token; - int i; - GetInteger(i); - Config.readTimeout = i * 60; -} - -static void parseLifetimeLine() -{ - char *token; - int i; - GetInteger(i); - Config.lifetimeDefault = i * 60; -} - -static void parseCleanRateLine() +static void parseMinutesLine(iptr) + int *iptr; { char *token; int i; GetInteger(i); - Config.cleanRate = i * 60; + *iptr = i * 60; } static void parseRequestSizeLine() @@ -1212,22 +1169,19 @@ int parseConfigFile(file_name) parseQuickAbort(); else if (!strcmp(token, "negative_ttl")) - parseNegativeLine(); - + parseMinutesLine(&Config.negativeTtl); else if (!strcmp(token, "negative_dns_ttl")) - parseNegativeDnsLine(); - + parseMinutesLine(&Config.negativeDnsTtl); else if (!strcmp(token, "positive_dns_ttl")) - parsePositiveDnsLine(); - + parseMinutesLine(&Config.positiveDnsTtl); else if (!strcmp(token, "read_timeout")) - parseReadTimeoutLine(); - + parseMinutesLine(&Config.readTimeout); else if (!strcmp(token, "clean_rate")) - parseCleanRateLine(); - + parseMinutesLine(&Config.cleanRate); else if (!strcmp(token, "client_lifetime")) - parseLifetimeLine(); + parseMinutesLine(&Config.lifetimeDefault); + else if (!strcmp(token, "expire_age")) + parseMinutesLine(&Config.expireAge); else if (!strcmp(token, "shutdown_lifetime")) parseIntegerValue(&Config.lifetimeShutdown); @@ -1485,6 +1439,7 @@ static void configSetFactoryDefaults() Config.Wais.relayHost = safe_xstrdup(DefaultWaisRelayHost); Config.Wais.relayPort = DefaultWaisRelayPort; + Config.expireAge = DefaultExpireAge; Config.negativeTtl = DefaultNegativeTtl; Config.negativeDnsTtl = DefaultNegativeDnsTtl; Config.positiveDnsTtl = DefaultPositiveDnsTtl; diff --git a/src/ftp.cc b/src/ftp.cc index ac6d6c645e..0d5b783695 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.52 1996/09/03 19:24:02 wessels Exp $ + * $Id: ftp.cc,v 1.53 1996/09/05 19:02:55 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -268,7 +268,7 @@ static void ftpProcessReplyHeader(data, buf, size) break; default: /* These can be negative cached, make key public */ - entry->expires = squid_curtime + Config.negativeTtl; + storeNegativeCache(entry); if (BIT_TEST(entry->flag, ENTRY_CACHABLE)) storeSetPublicKey(entry); break; @@ -356,7 +356,7 @@ int ftpReadReply(fd, data) * failed and arrange so the object gets ejected and * never gets to disk. */ debug(9, 1, "ftpReadReply: Purging '%s'\n", entry->url); - entry->expires = squid_curtime + Config.negativeTtl; + storeNegativeCache(entry); BIT_RESET(entry->flag, ENTRY_CACHABLE); storeReleaseRequest(entry); } else if (!(entry->flag & DELETE_BEHIND)) { diff --git a/src/http.cc b/src/http.cc index eea1320918..afb62e47f7 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,5 +1,5 @@ /* - * $Id: http.cc,v 1.71 1996/09/04 22:03:23 wessels Exp $ + * $Id: http.cc,v 1.72 1996/09/05 19:02:56 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -207,10 +207,9 @@ static void httpMakePrivate(entry) static void httpCacheNegatively(entry) StoreEntry *entry; { - entry->expires = squid_curtime + Config.negativeTtl; + storeNegativeCache(entry); if (BIT_TEST(entry->flag, ENTRY_CACHABLE)) storeSetPublicKey(entry); - /* XXX: mark object "not to store on disk"? */ } diff --git a/src/store.cc b/src/store.cc index abe8e3b5ba..bdf7760701 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,5 +1,5 @@ /* - * $Id: store.cc,v 1.97 1996/09/04 23:42:02 wessels Exp $ + * $Id: store.cc,v 1.98 1996/09/05 19:02:59 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -1440,7 +1440,7 @@ static int storeDoRebuildFromDisk(data) if (store_rebuilding != STORE_REBUILDING_FAST) { if (stat(swapfile, &sb) < 0) { - if (expires < squid_curtime) { + if (squid_curtime - expires > Config.expireAge) { debug(20, 3, "storeRebuildFromDisk: Expired: \n", url); if (opt_unlink_on_reload) safeunlink(swapfile, 1); @@ -1489,7 +1489,7 @@ static int storeDoRebuildFromDisk(data) data->objcount--; data->dupcount++; } - if (expires < squid_curtime) { + if (squid_curtime - expires > Config.expireAge) { debug(20, 3, "storeRebuildFromDisk: Expired: \n", url); if (opt_unlink_on_reload) safeunlink(swapfile, 1); @@ -1646,7 +1646,7 @@ static int storeCheckSwapable(e) StoreEntry *e; { - if (e->expires <= squid_curtime) { + if (squid_curtime - e->expires > Config.expireAge) { debug(20, 2, "storeCheckSwapable: NO: expires now\n"); } else if (e->method != METHOD_GET) { debug(20, 2, "storeCheckSwapable: NO: non-GET method\n"); @@ -1656,8 +1656,8 @@ static int storeCheckSwapable(e) debug(20, 2, "storeCheckSwapable: NO: release requested\n"); } else if (!storeEntryValidLength(e)) { debug(20, 2, "storeCheckSwapable: NO: wrong content-length\n"); - } else if (e->expires <= squid_curtime + Config.negativeTtl) { - debug(20, 2, "storeCheckSwapable: NO: expires soon\n"); + } else if (BIT_TEST(e->flag, ENTRY_NEGCACHED)) { + debug(20, 2, "storeCheckSwapable: NO: negative cached\n"); return 0; /* avoid release call below */ } else return 1; @@ -1706,7 +1706,7 @@ int storeAbort(e, msg) fatal_dump("storeAbort: null mem"); debug(20, 6, "storeAbort: '%s'\n", e->key); - e->expires = squid_curtime + Config.negativeTtl; + storeNegativeCache(e); e->store_status = STORE_ABORTED; storeSetMemStatus(e, IN_MEMORY); /* No DISK swap for negative cached object */ @@ -1998,38 +1998,27 @@ int storeGetSwapSpace(size) /* remove expired objects until recover enough space or no expired objects */ for (i = 0; i < STORE_BUCKETS; i++) { int expired_in_one_bucket = 0; - link_ptr = hash_get_bucket(store_table, storeGetBucketNum()); if (link_ptr == NULL) continue; /* this while loop handles one bucket of hash table */ expired_in_one_bucket = 0; - while (link_ptr) { + for (; link_ptr; link_ptr = next) { scanned++; next = link_ptr->next; e = (StoreEntry *) link_ptr; - - /* Identify objects that aren't locked, for replacement */ - if (!storeEntryLocked(e)) { - if (squid_curtime > e->expires) { - debug(20, 2, "storeGetSwapSpace: Expired: \n", e->url); - /* just call release. don't have to check for lock status. - * storeRelease will take care of that and set a pending flag - * if it's still locked. */ - ++expired_in_one_bucket; - storeRelease(e); - } else { - /* Prepare to do LRU replacement */ - insert_dynamic_array(LRU_list, e); - ++scan_in_objs; - } + if (storeCheckExpired(e)) { + debug(20, 2, "storeGetSwapSpace: Expired: \n", e->url); + ++expired_in_one_bucket; + storeRelease(e); + } else if (!storeEntryLocked(e)) { + insert_dynamic_array(LRU_list, e); + ++scan_in_objs; } else { - locked++; - locked_size += e->mem_obj->e_current_len; + locked++; + locked_size += e->mem_obj->e_current_len; } - link_ptr = next; } /* while, end of one bucket of hash table */ - expired += expired_in_one_bucket; if (expired_in_one_bucket && ((!fReduceSwap && (store_swap_size + kb_size <= store_swap_high)) || @@ -2643,33 +2632,27 @@ int storeMaintainSwapSpace() if (store_rebuilding == STORE_REBUILDING_FAST) return -1; - /* Scan row of hash table each second and free storage if we're - * over the high-water mark */ - storeGetSwapSpace(0); - /* Purges expired objects, check one bucket on each calling */ if (squid_curtime - last_time >= STORE_MAINTAIN_RATE) { last_time = squid_curtime; if (bucket >= STORE_BUCKETS) bucket = 0; link_ptr = hash_get_bucket(store_table, bucket++); - while (link_ptr) { + for (;link_ptr; link_ptr = next) { next = link_ptr->next; e = (StoreEntry *) link_ptr; - if ((squid_curtime > e->expires) && - (e->swap_status == SWAP_OK)) { - debug(20, 2, "storeMaintainSwapSpace: Expired: \n", - e->expires - squid_curtime, e->url); - /* just call release. don't have to check for lock status. - * storeRelease will take care of that and set a pending flag - * if it's still locked. */ - storeRelease(e); - ++rm_obj; - } - link_ptr = next; + if (!storeCheckExpired(e)) + continue; + storeRelease(e); + ++rm_obj; } } debug(20, rm_obj ? 2 : 3, "Removed %d expired objects\n", rm_obj); + + /* Scan row of hash table each second and free storage if we're + * over the high-water mark */ + storeGetSwapSpace(0); + return rm_obj; } @@ -2847,7 +2830,7 @@ static int storeCheckExpired(e) { if (storeEntryLocked(e)) return 0; - if (squid_curtime < e->expires) + if (squid_curtime - e->expires < Config.expireAge) return 0; return 1; } @@ -2871,3 +2854,10 @@ void storeCloseLog() file_close(swaplog_fd); file_close(storelog_fd); } + +void storeNegativeCache(e) + StoreEntry *e; +{ + e->expires = squid_curtime + Config.negativeTtl; + BIT_SET(e->flag, ENTRY_NEGCACHED); +}