--------------------- PatchSet 377 Date: 2002/12/14 09:54:25 Author: rbcollins Branch: unify-io Tag: (none) Log: and more Members: src/ufscommon.cc:1.4.10.28->1.4.10.29 Index: squid3/src/ufscommon.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ufscommon.cc,v retrieving revision 1.4.10.28 retrieving revision 1.4.10.29 diff -u -r1.4.10.28 -r1.4.10.29 --- squid3/src/ufscommon.cc 14 Dec 2002 09:40:24 -0000 1.4.10.28 +++ squid3/src/ufscommon.cc 14 Dec 2002 09:54:25 -0000 1.4.10.29 @@ -1,5 +1,5 @@ /* - * $Id: ufscommon.cc,v 1.4.10.28 2002/12/14 09:40:24 rbcollins Exp $ + * $Id: ufscommon.cc,v 1.4.10.29 2002/12/14 09:54:25 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -39,6 +39,7 @@ class RebuildState { public: static EVH RebuildFromDirectory; + static EVH RebuildFromSwapLog; UFSSwapDir *sd; int n_read; FILE *log; @@ -60,13 +61,13 @@ struct _store_rebuild_data counts; private: void rebuildFromDirectory(); + void rebuildFromSwapLog(); }; static int n_dirs = 0; static int *dir_index = NULL; static int commonUfsFilenoBelongsHere(int fn, int F0, int F1, int F2); static int commonUfsDirVerifyDirectory(const char *path); -static EVH commonUfsDirRebuildFromSwapLog; static int commonUfsDirGetNextFile(RebuildState *, sfileno *, int *size); static STLOGCLEANWRITE commonUfsDirWriteCleanEntry; static QS rev_int_sort; @@ -444,10 +445,15 @@ } void -commonUfsDirRebuildFromSwapLog(void *data) +RebuildState::RebuildFromSwapLog(void *data) { RebuildState *rb = (RebuildState *)data; - UFSSwapDir *SD = (UFSSwapDir *)rb->sd; + rb->rebuildFromSwapLog(); +} + +void +RebuildState::rebuildFromSwapLog() +{ StoreEntry *e = NULL; storeSwapLogData s; size_t ss = sizeof(storeSwapLogData); @@ -455,21 +461,21 @@ int used; /* is swapfile already in use? */ int disk_entry_newer; /* is the log entry newer than current entry? */ double x; - assert(rb != NULL); /* load a number of objects per invocation */ - for (count = 0; count < rb->speed; count++) { - if (fread(&s, ss, 1, rb->log) != 1) { + for (count = 0; count < speed; count++) { + if (fread(&s, ss, 1, log) != 1) { debug(47, 1) ("Done reading %s swaplog (%d entries)\n", - rb->sd->path, rb->n_read); - fclose(rb->log); - rb->log = NULL; + sd->path, n_read); + fclose(log); + log = NULL; store_dirs_rebuilding--; - ((UFSSwapDir *)rb->sd)->closeTmpSwapLog(); - storeRebuildComplete(&rb->counts); - cbdataFree(rb); + sd->closeTmpSwapLog(); + storeRebuildComplete(&counts); + RebuildState *anLvalue = this; + cbdataFree(anLvalue); return; } - rb->n_read++; + n_read++; if (s.op <= SWAP_LOG_NOP) continue; if (s.op >= SWAP_LOG_MAX) @@ -502,48 +508,48 @@ storeReleaseRequest(e); if (e->swap_filen > -1) { commonUfsDirReplRemove(e); - SD->mapBitReset(e->swap_filen); + sd->mapBitReset(e->swap_filen); e->swap_filen = -1; e->swap_dirn = -1; } storeRelease(e); - rb->counts.objcount--; - rb->counts.cancelcount++; + counts.objcount--; + counts.cancelcount++; } continue; } else { - x = log(++rb->counts.bad_log_op) / log(10.0); + x = ::log(++counts.bad_log_op) / ::log(10.0); if (0.0 == x - (double) (int) x) debug(47, 1) ("WARNING: %d invalid swap log entries found\n", - rb->counts.bad_log_op); - rb->counts.invalid++; + counts.bad_log_op); + counts.invalid++; continue; } - if ((++rb->counts.scancount & 0xFFF) == 0) { + if ((++counts.scancount & 0xFFF) == 0) { struct stat sb; - if (0 == fstat(fileno(rb->log), &sb)) - storeRebuildProgress(SD->index, - (int) sb.st_size / ss, rb->n_read); + if (0 == fstat(fileno(log), &sb)) + storeRebuildProgress(sd->index, + (int) sb.st_size / ss, n_read); } - if (!SD->validFileno(s.swap_filen, 0)) { - rb->counts.invalid++; + if (!sd->validFileno(s.swap_filen, 0)) { + counts.invalid++; continue; } if (EBIT_TEST(s.flags, KEY_PRIVATE)) { - rb->counts.badflags++; + counts.badflags++; continue; } e = storeGet(s.key); - used = SD->mapBitTest(s.swap_filen); + used = sd->mapBitTest(s.swap_filen); /* If this URL already exists in the cache, does the swap log * appear to have a newer entry? Compare 'lastref' from the * swap log to e->lastref. */ disk_entry_newer = e ? (s.lastref > e->lastref ? 1 : 0) : 0; if (used && !disk_entry_newer) { /* log entry is old, ignore it */ - rb->counts.clashcount++; + counts.clashcount++; continue; - } else if (used && e && e->swap_filen == s.swap_filen && e->swap_dirn == SD->index) { + } else if (used && e && e->swap_filen == s.swap_filen && e->swap_dirn == sd->index) { /* swapfile taken, same URL, newer, update meta */ if (e->store_status == STORE_OK) { e->lastref = s.timestamp; @@ -552,7 +558,7 @@ e->lastmod = s.lastmod; e->flags = s.flags; e->refcount += s.refcount; - SD->dereference(*e); + sd->dereference(*e); } else { debug_trap("commonUfsDirRebuildFromSwapLog: bad condition"); debug(47, 1) ("\tSee %s:%d\n", __FILE__, __LINE__); @@ -565,7 +571,7 @@ * caught this. If the log is clean, there should never be a * newer entry. */ debug(47, 1) ("WARNING: newer swaplog entry for dirno %d, fileno %08X\n", - SD->index, s.swap_filen); + sd->index, s.swap_filen); /* I'm tempted to remove the swapfile here just to be safe, * but there is a bad race condition in the NOVM version if * the swapfile has recently been opened for writing, but @@ -575,13 +581,13 @@ /* We'll assume the existing entry is valid, probably because * were in a slow rebuild and the the swap file number got taken * and the validation procedure hasn't run. */ - assert(rb->flags.need_to_validate); - rb->counts.clashcount++; + assert(flags.need_to_validate); + counts.clashcount++; continue; } else if (e && !disk_entry_newer) { /* key already exists, current entry is newer */ /* keep old, ignore new */ - rb->counts.dupcount++; + counts.dupcount++; continue; } else if (e) { /* key already exists, this swapfile not being used */ @@ -591,20 +597,20 @@ if (e->swap_filen > -1) { commonUfsDirReplRemove(e); /* Make sure we don't actually unlink the file */ - SD->mapBitReset(e->swap_filen); + sd->mapBitReset(e->swap_filen); e->swap_filen = -1; e->swap_dirn = -1; } storeRelease(e); - rb->counts.dupcount++; + counts.dupcount++; } else { /* URL doesnt exist, swapfile not in use */ /* load new */ (void) 0; } /* update store_swap_size */ - rb->counts.objcount++; - e = SD->addDiskRestore(s.key, + counts.objcount++; + e = sd->addDiskRestore(s.key, s.swap_filen, s.swap_file_sz, s.expires, @@ -613,10 +619,10 @@ s.lastmod, s.refcount, s.flags, - (int) rb->flags.clean); + (int) flags.clean); storeDirSwapLog(e, SWAP_LOG_ADD); } - eventAdd("storeRebuild", commonUfsDirRebuildFromSwapLog, rb, 0.0, 1); + eventAdd("storeRebuild", RebuildFromSwapLog, this, 0.0, 1); } int @@ -754,13 +760,12 @@ void UFSSwapDir::rebuild() { - RebuildState *rb; int clean = 0; int zero = 0; FILE *fp; EVH *func = NULL; CBDATA_INIT_TYPE(RebuildState); - rb = cbdataAlloc(RebuildState); + RebuildState *rb = cbdataAlloc(RebuildState); rb->sd = this; rb->speed = opt_foreground_rebuild ? 1 << 30 : 50; /* @@ -775,7 +780,7 @@ fclose(fp); func = RebuildState::RebuildFromDirectory; } else { - func = commonUfsDirRebuildFromSwapLog; + func = RebuildState::RebuildFromSwapLog; rb->log = fp; rb->flags.clean = (unsigned int) clean; }