~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/peer_digest.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
 
 * $Id: peer_digest.cc,v 1.127.2.1 2008/02/25 23:08:51 amosjeffries Exp $
 
3
 * $Id$
4
4
 *
5
5
 * DEBUG: section 72    Peer Digest Routines
6
6
 * AUTHOR: Alex Rousskov
21
21
 *  it under the terms of the GNU General Public License as published by
22
22
 *  the Free Software Foundation; either version 2 of the License, or
23
23
 *  (at your option) any later version.
24
 
 *  
 
24
 *
25
25
 *  This program is distributed in the hope that it will be useful,
26
26
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
27
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
28
 *  GNU General Public License for more details.
29
 
 *  
 
29
 *
30
30
 *  You should have received a copy of the GNU General Public License
31
31
 *  along with this program; if not, write to the Free Software
32
32
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
231
231
{
232
232
    eventAdd("peerDigestCheck", peerDigestCheck, pd, (double) delay, 1);
233
233
    pd->times.next_check = squid_curtime + delay;
234
 
    debugs(72, 3, "peerDigestSetCheck: will check peer " << pd->host.buf() << " in " << delay << " secs");
 
234
    debugs(72, 3, "peerDigestSetCheck: will check peer " << pd->host << " in " << delay << " secs");
235
235
}
236
236
 
237
237
/*
241
241
peerDigestNotePeerGone(PeerDigest * pd)
242
242
{
243
243
    if (pd->flags.requested) {
244
 
        debugs(72, 2, "peerDigest: peer " << pd->host.buf() << " gone, will destroy after fetch.");
 
244
        debugs(72, 2, "peerDigest: peer " << pd->host << " gone, will destroy after fetch.");
245
245
        /* do nothing now, the fetching chain will notice and take action */
246
246
    } else {
247
 
        debugs(72, 2, "peerDigest: peer " << pd->host.buf() << " is gone, destroying now.");
 
247
        debugs(72, 2, "peerDigest: peer " << pd->host << " is gone, destroying now.");
248
248
        peerDigestDestroy(pd);
249
249
    }
250
250
}
251
251
 
252
252
/* callback for eventAdd() (with peer digest locked)
253
 
 * request new digest if our copy is too old or if we lack one; 
 
253
 * request new digest if our copy is too old or if we lack one;
254
254
 * schedule next check otherwise */
255
255
static void
256
256
peerDigestCheck(void *data)
267
267
        return;
268
268
    }
269
269
 
270
 
    debugs(72, 3, "peerDigestCheck: peer " << pd->peer->host << ":" << pd->peer->http_port);
271
 
    debugs(72, 3, "peerDigestCheck: time: " << squid_curtime << 
272
 
           ", last received: " << (long int) pd->times.received << "  (" << 
 
270
    debugs(72, 3, "peerDigestCheck: peer " <<  pd->peer->host << ":" << pd->peer->http_port);
 
271
    debugs(72, 3, "peerDigestCheck: time: " << squid_curtime <<
 
272
           ", last received: " << (long int) pd->times.received << "  (" <<
273
273
           std::showpos << (int) (squid_curtime - pd->times.received) << ")");
274
274
 
275
275
    /* decide when we should send the request:
279
279
    /* per-peer limit */
280
280
 
281
281
    if (req_time - pd->times.received < PeerDigestReqMinGap) {
282
 
        debugs(72, 2, "peerDigestCheck: " << pd->host.buf() <<
 
282
        debugs(72, 2, "peerDigestCheck: " << pd->host <<
283
283
               ", avoiding close peer requests (" <<
284
284
               (int) (req_time - pd->times.received) << " < " <<
285
285
               (int) PeerDigestReqMinGap << " secs).");
289
289
 
290
290
    /* global limit */
291
291
    if (req_time - pd_last_req_time < GlobDigestReqMinGap) {
292
 
        debugs(72, 2, "peerDigestCheck: " << pd->host.buf() <<
 
292
        debugs(72, 2, "peerDigestCheck: " << pd->host <<
293
293
               ", avoiding close requests (" <<
294
294
               (int) (req_time - pd_last_req_time) << " < " <<
295
295
               (int) GlobDigestReqMinGap << " secs).");
376
376
    if (old_e) {
377
377
        debugs(72, 5, "peerDigestRequest: found old entry");
378
378
 
379
 
        old_e->lock()
380
 
 
381
 
        ;
 
379
        old_e->lock();
382
380
        old_e->createMemObject(url, url);
383
381
 
384
382
        fetch->old_sc = storeClientListAdd(old_e, fetch);
546
544
        assert(reply);
547
545
        assert (reply->sline.status != 0);
548
546
        status = reply->sline.status;
549
 
        debugs(72, 3, "peerDigestFetchReply: " << pd->host.buf() << " status: " << status << 
550
 
               ", expires: " << (long int) reply->expires << " (" << std::showpos << 
 
547
        debugs(72, 3, "peerDigestFetchReply: " << pd->host << " status: " << status <<
 
548
               ", expires: " << (long int) reply->expires << " (" << std::showpos <<
551
549
               (int) (reply->expires - squid_curtime) << ")");
552
550
 
553
551
        /* this "if" is based on clientHandleIMSReply() */
636
634
        assert (fetch->entry->getReply()->sline.status != 0);
637
635
 
638
636
        if (fetch->entry->getReply()->sline.status != HTTP_OK) {
639
 
            debugs(72, 1, "peerDigestSwapInHeaders: " << fetch->pd->host.buf() <<
 
637
            debugs(72, 1, "peerDigestSwapInHeaders: " << fetch->pd->host <<
640
638
                   " status " << fetch->entry->getReply()->sline.status <<
641
639
                   " got cached!");
642
640
 
764
762
#endif
765
763
 
766
764
        else
767
 
            host = pd->host.buf();
 
765
            host = pd->host.termedBuf();
768
766
    }
769
767
 
770
768
    debugs(72, 6, step_name << ": peer " << host << ", offset: " <<
815
813
peerDigestFetchStop(DigestFetchState * fetch, char *buf, const char *reason)
816
814
{
817
815
    assert(reason);
818
 
    debugs(72, 2, "peerDigestFetchStop: peer " << fetch->pd->host.buf() << ", reason: " << reason);
 
816
    debugs(72, 2, "peerDigestFetchStop: peer " << fetch->pd->host << ", reason: " << reason);
819
817
    peerDigestReqFinish(fetch, buf, 1, 1, 1, reason, 0);
820
818
}
821
819
 
824
822
peerDigestFetchAbort(DigestFetchState * fetch, char *buf, const char *reason)
825
823
{
826
824
    assert(reason);
827
 
    debugs(72, 2, "peerDigestFetchAbort: peer " << fetch->pd->host.buf() << ", reason: " << reason);
 
825
    debugs(72, 2, "peerDigestFetchAbort: peer " << fetch->pd->host << ", reason: " << reason);
828
826
    peerDigestReqFinish(fetch, buf, 1, 1, 1, reason, 1);
829
827
}
830
828
 
874
872
peerDigestPDFinish(DigestFetchState * fetch, int pcb_valid, int err)
875
873
{
876
874
    PeerDigest *pd = fetch->pd;
877
 
    const char *host = pd->host.buf();
 
875
    const char *host = pd->host.termedBuf();
878
876
 
879
877
    pd->times.received = squid_curtime;
880
878
    pd->times.req_delay = fetch->resp_time;
988
986
{
989
987
    StoreDigestCBlock cblock;
990
988
    int freed_size = 0;
991
 
    const char *host = pd->host.buf();
 
989
    const char *host = pd->host.termedBuf();
992
990
 
993
991
    xmemcpy(&cblock, buf, sizeof(cblock));
994
992
    /* network -> host conversions */
1002
1000
           (int) cblock.ver.current << " (req: " << (int) cblock.ver.required <<
1003
1001
           ")");
1004
1002
 
1005
 
    debugs(72, 2, "\t size: " << 
1006
 
           cblock.mask_size << " bytes, e-cnt: " << 
1007
 
           cblock.count << ", e-util: " << 
 
1003
    debugs(72, 2, "\t size: " <<
 
1004
           cblock.mask_size << " bytes, e-cnt: " <<
 
1005
           cblock.count << ", e-util: " <<
1008
1006
           xpercentInt(cblock.count, cblock.capacity) << "%" );
1009
1007
    /* check version requirements (both ways) */
1010
1008
 
1060
1058
    }
1061
1059
 
1062
1060
    if (!pd->cd) {
1063
 
        debugs(72, 2, "creating " << host << " digest; size: " << cblock.mask_size << " (" << 
1064
 
                std::showpos <<  (int) (cblock.mask_size - freed_size) << ") bytes");
 
1061
        debugs(72, 2, "creating " << host << " digest; size: " << cblock.mask_size << " (" <<
 
1062
               std::showpos <<  (int) (cblock.mask_size - freed_size) << ") bytes");
1065
1063
        pd->cd = cacheDigestCreate(cblock.capacity, cblock.bits_per_entry);
1066
1064
 
1067
1065
        if (cblock.mask_size >= freed_size)
1082
1080
    const int bit_util = cacheDigestBitUtil(pd->cd);
1083
1081
 
1084
1082
    if (bit_util > 65) {
1085
 
        debugs(72, 0, "Warning: " << pd->host.buf() <<
 
1083
        debugs(72, 0, "Warning: " << pd->host <<
1086
1084
               " peer digest has too many bits on (" << bit_util << "%%).");
1087
1085
 
1088
1086
        return 0;
1108
1106
 
1109
1107
    assert(pd);
1110
1108
 
1111
 
    const char *host = pd->host.buf();
 
1109
    const char *host = pd->host.termedBuf();
1112
1110
    storeAppendPrintf(e, "\npeer digest from %s\n", host);
1113
1111
 
1114
1112
    cacheDigestGuessStatsReport(&pd->stats.guess, e, host);