~measurement-factory/squid/bag5

« back to all changes in this revision

Viewing changes to src/MemObject.cc

  • Committer: Alex Rousskov
  • Date: 2013-08-16 15:40:14 UTC
  • mfrom: (12501.2.58 collapsed-fwd)
  • Revision ID: rousskov@measurement-factory.com-20130816154014-od2kncs1egeerazs
Merged from collapsed-fwd (r12587) to get initial Collapsed Forwarding
support and Large Rock/Store fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
    return Pool().inUseCount();
75
75
}
76
76
 
 
77
const char *
 
78
MemObject::storeId() const {
 
79
    if (!storeId_.defined()) {
 
80
        debugs(20, DBG_IMPORTANT, "Bug: Missing MemObject::storeId value");
 
81
        dump();
 
82
        storeId_ = "[unknown_URI]";
 
83
    }
 
84
    return storeId_.termedBuf();
 
85
}
 
86
 
 
87
const char *
 
88
MemObject::logUri() const {
 
89
    return logUri_.defined() ? logUri_.termedBuf() : storeId();
 
90
}
 
91
 
 
92
bool
 
93
MemObject::hasUris() const {
 
94
    return storeId_.defined();
 
95
}
 
96
 
77
97
void
78
 
MemObject::resetUrls(char const *aUrl, char const *aLog_url)
 
98
MemObject::setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod)
79
99
{
80
 
    safe_free(url);
81
 
    safe_free(log_url);    /* XXX account log_url */
82
 
    log_url = xstrdup(aLog_url);
83
 
    url = xstrdup(aUrl);
 
100
    storeId_ = aStoreId;
 
101
 
 
102
    // fast pointer comparison for a common storeCreateEntry(url,url,...) case
 
103
    if (!aLogUri || aLogUri == aStoreId) 
 
104
        logUri_.clean(); // use storeId_ by default to minimize copying
 
105
    else
 
106
        logUri_ = aLogUri;
 
107
 
 
108
    method = aMethod;
 
109
 
 
110
#if URL_CHECKSUM_DEBUG
 
111
    chksum = url_checksum(urlXXX());
 
112
#endif
84
113
}
85
114
 
86
 
MemObject::MemObject(char const *aUrl, char const *aLog_url)
 
115
MemObject::MemObject(): smpCollapsed(false)
87
116
{
88
117
    debugs(20, 3, HERE << "new MemObject " << this);
89
118
    _reply = new HttpReply;
90
119
    HTTPMSGLOCK(_reply);
91
120
 
92
 
    url = xstrdup(aUrl);
93
 
 
94
 
#if URL_CHECKSUM_DEBUG
95
 
 
96
 
    chksum = url_checksum(url);
97
 
 
98
 
#endif
99
 
 
100
 
    log_url = xstrdup(aLog_url);
101
 
 
102
121
    object_sz = -1;
103
122
 
104
123
    /* XXX account log_url */
109
128
MemObject::~MemObject()
110
129
{
111
130
    debugs(20, 3, HERE << "del MemObject " << this);
112
 
    const Ctx ctx = ctx_enter(url);
 
131
    const Ctx ctx = ctx_enter(hasUris() ? urlXXX() : "[unknown_ctx]");
 
132
 
113
133
#if URL_CHECKSUM_DEBUG
114
 
 
115
 
    assert(chksum == url_checksum(url));
 
134
    checkUrlChecksum();
116
135
#endif
117
136
 
118
 
    if (!shutting_down)
 
137
    if (!shutting_down) { // Store::Root() is FATALly missing during shutdown
 
138
        assert(xitTable.index < 0);
 
139
        assert(memCache.index < 0);
119
140
        assert(swapout.sio == NULL);
 
141
    }
120
142
 
121
143
    data_hdr.freeContent();
122
144
 
135
157
 
136
158
    ctx_exit(ctx);              /* must exit before we free mem->url */
137
159
 
138
 
    safe_free(url);
139
 
 
140
 
    safe_free(log_url);    /* XXX account log_url */
141
 
 
142
160
    safe_free(vary_headers);
143
161
}
144
162
 
149
167
}
150
168
 
151
169
void
152
 
MemObject::write ( StoreIOBuffer writeBuffer, STMCB *callback, void *callbackData)
 
170
MemObject::write(const StoreIOBuffer &writeBuffer)
153
171
{
154
172
    PROF_start(MemObject_write);
155
173
    debugs(19, 6, "memWrite: offset " << writeBuffer.offset << " len " << writeBuffer.length);
156
174
 
157
 
    /* the offset is into the content, not the headers */
158
 
    writeBuffer.offset += (_reply ? _reply->hdr_sz : 0);
159
 
 
160
175
    /* We don't separate out mime headers yet, so ensure that the first
161
176
     * write is at offset 0 - where they start
162
177
     */
163
178
    assert (data_hdr.endOffset() || writeBuffer.offset == 0);
164
179
 
165
180
    assert (data_hdr.write (writeBuffer));
166
 
    callback (callbackData, writeBuffer);
167
181
    PROF_stop(MemObject_write);
168
182
}
169
183
 
182
196
    debugs(20, DBG_IMPORTANT, "MemObject->nclients: " << nclients);
183
197
    debugs(20, DBG_IMPORTANT, "MemObject->reply: " << _reply);
184
198
    debugs(20, DBG_IMPORTANT, "MemObject->request: " << request);
185
 
    debugs(20, DBG_IMPORTANT, "MemObject->log_url: " << checkNullString(log_url));
 
199
    debugs(20, DBG_IMPORTANT, "MemObject->logUri: " << logUri_);
 
200
    debugs(20, DBG_IMPORTANT, "MemObject->storeId: " << storeId_);
186
201
}
187
202
 
188
203
HttpReply const *
226
241
MemObject::stat(MemBuf * mb) const
227
242
{
228
243
    mb->Printf("\t%s %s\n",
229
 
               RequestMethodStr(method), log_url);
 
244
               RequestMethodStr(method), logUri());
230
245
    if (vary_headers)
231
246
        mb->Printf("\tvary_headers: %s\n", vary_headers);
232
247
    mb->Printf("\tinmem_lo: %" PRId64 "\n", inmem_lo);
238
253
        mb->Printf("\tswapout: %" PRId64 " bytes written\n",
239
254
                   (int64_t) swapout.sio->offset());
240
255
 
 
256
    if (xitTable.index >= 0)
 
257
        mb->Printf("\ttransient index: %d state: %d\n",
 
258
                   xitTable.index, xitTable.io);
 
259
    if (memCache.index >= 0)
 
260
        mb->Printf("\tmem-cache index: %d state: %d offset: %" PRId64 "\n",
 
261
                   memCache.index, memCache.io, memCache.offset);
 
262
    if (object_sz >= 0)
 
263
        mb->Printf("\tobject_sz: %" PRId64 "\n", object_sz);
 
264
    if (smpCollapsed)
 
265
        mb->Printf("\tsmp-collapsed\n");
 
266
 
241
267
    StoreClientStats statsVisitor(mb);
242
268
 
243
269
    for_each<StoreClientStats>(clients, statsVisitor);
307
333
bool
308
334
MemObject::readAheadPolicyCanRead() const
309
335
{
310
 
    return endOffset() - getReply()->hdr_sz < lowestMemReaderOffset() + Config.readAheadGap;
 
336
    const bool canRead = endOffset() - getReply()->hdr_sz <
 
337
        lowestMemReaderOffset() + Config.readAheadGap;
 
338
 
 
339
    if (!canRead) {
 
340
        debugs(19, 9, "no: " << endOffset() << '-' << getReply()->hdr_sz <<
 
341
               " < " << lowestMemReaderOffset() << '+' << Config.readAheadGap);
 
342
    }
 
343
 
 
344
    return canRead;
311
345
}
312
346
 
313
347
void
321
355
void
322
356
MemObject::checkUrlChecksum () const
323
357
{
324
 
    assert(chksum == url_checksum(url));
 
358
    assert(chksum == url_checksum(urlXXX()));
325
359
}
326
360
 
327
361
#endif
400
434
void
401
435
MemObject::trimUnSwappable()
402
436
{
403
 
    int64_t new_mem_lo = policyLowestOffsetToKeep(0);
404
 
    assert (new_mem_lo > 0);
405
 
 
406
 
    data_hdr.freeDataUpto(new_mem_lo);
407
 
    inmem_lo = new_mem_lo;
 
437
    if (const int64_t new_mem_lo = policyLowestOffsetToKeep(false)) {
 
438
        assert (new_mem_lo > 0);
 
439
        data_hdr.freeDataUpto(new_mem_lo);
 
440
        inmem_lo = new_mem_lo;
 
441
    } // else we should not trim anything at this time
408
442
}
409
443
 
410
444
bool