]> git.ipfire.org Git - thirdparty/squid.git/blob - src/MemObject.h
Supply AccessLogEntry (ALE) for more fast ACL checks. (#182)
[thirdparty/squid.git] / src / MemObject.h
1 /*
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_MEMOBJECT_H
10 #define SQUID_MEMOBJECT_H
11
12 #include "CommRead.h"
13 #include "dlink.h"
14 #include "http/RequestMethod.h"
15 #include "RemovalPolicy.h"
16 #include "SquidString.h"
17 #include "stmem.h"
18 #include "store/forward.h"
19 #include "StoreIOBuffer.h"
20 #include "StoreIOState.h"
21 #include "typedefs.h" //for IRCB
22
23 #if USE_DELAY_POOLS
24 #include "DelayId.h"
25 #endif
26
27 typedef void STMCB (void *data, StoreIOBuffer wroteBuffer);
28 typedef void STABH(void *);
29
30 class store_client;
31 class PeerSelector;
32
33 class MemObject
34 {
35 MEMPROXY_CLASS(MemObject);
36
37 public:
38 static size_t inUseCount();
39
40 void dump() const;
41 MemObject();
42 ~MemObject();
43
44 /// Sets store ID, log URI, and request method (unless already set). Does
45 /// not clobber the method so that, say, a HEAD hit for a GET entry keeps
46 /// the GET method that matches the entry key. Same for the other parts of
47 /// the trio because the entry filling code may expect them to be constant.
48 /// XXX: Avoid this method. We plan to remove it and make the trio constant
49 /// after addressing the XXX in MemStore::get().
50 void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod);
51
52 /// whether setUris() has been called
53 bool hasUris() const;
54
55 void write(const StoreIOBuffer &buf);
56 void unlinkRequest() { request = nullptr; }
57 const HttpReplyPointer &getReply() const { return reply_; }
58 void replaceReply(const HttpReplyPointer &r) { reply_ = r; }
59 void stat (MemBuf * mb) const;
60 int64_t endOffset () const;
61 void markEndOfReplyHeaders(); ///< sets reply_->hdr_sz to endOffset()
62 /// negative if unknown; otherwise, expected object_sz, expected endOffset
63 /// maximum, and stored reply headers+body size (all three are the same)
64 int64_t expectedReplySize() const;
65 int64_t size() const;
66 void reset();
67 int64_t lowestMemReaderOffset() const;
68 bool readAheadPolicyCanRead() const;
69 void addClient(store_client *);
70 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
71 * better
72 */
73 int64_t objectBytesOnDisk() const;
74 int64_t policyLowestOffsetToKeep(bool swap) const;
75 int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet
76 void trimSwappable();
77 void trimUnSwappable();
78 bool isContiguous() const;
79 int mostBytesWanted(int max, bool ignoreDelayPools) const;
80 void setNoDelay(bool const newValue);
81 #if USE_DELAY_POOLS
82 DelayId mostBytesAllowed() const;
83 #endif
84
85 #if URL_CHECKSUM_DEBUG
86
87 void checkUrlChecksum() const;
88 #endif
89
90 /// Before StoreID, code assumed that MemObject stores Request URI.
91 /// After StoreID, some old code still incorrectly assumes that.
92 /// Use this method to mark that incorrect assumption.
93 const char *urlXXX() const { return storeId(); }
94
95 /// Entry StoreID (usually just Request URI); if a buggy code requests this
96 /// before the information is available, returns an "[unknown_URI]" string.
97 const char *storeId() const;
98
99 /// client request URI used for logging; storeId() by default
100 const char *logUri() const;
101
102 HttpRequestMethod method;
103 mem_hdr data_hdr;
104 int64_t inmem_lo;
105 dlink_list clients;
106
107 size_t clientCount() const {return nclients;}
108
109 bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);}
110
111 int nclients;
112
113 class SwapOut
114 {
115 public:
116 SwapOut() : queue_offset(0), decision(swNeedsCheck) {}
117
118 int64_t queue_offset; ///< number of bytes sent to SwapDir for writing
119 StoreIOState::Pointer sio;
120
121 /// Decision states for StoreEntry::swapoutPossible() and related code.
122 typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision;
123 Decision decision; ///< current decision state
124 };
125
126 SwapOut swapout;
127
128 /* TODO: Remove this change-minimizing hack */
129 using Io = Store::IoStatus;
130 static constexpr Io ioUndecided = Store::ioUndecided;
131 static constexpr Io ioReading = Store::ioReading;
132 static constexpr Io ioWriting = Store::ioWriting;
133 static constexpr Io ioDone = Store::ioDone;
134
135 /// State of an entry with regards to the [shared] in-transit table.
136 class XitTable
137 {
138 public:
139 XitTable(): index(-1), io(ioUndecided) {}
140
141 int32_t index; ///< entry position inside the in-transit table
142 Io io; ///< current I/O state
143 };
144 XitTable xitTable; ///< current [shared] memory caching state for the entry
145
146 /// State of an entry with regards to the [shared] memory caching.
147 class MemCache
148 {
149 public:
150 MemCache(): index(-1), offset(0), io(ioUndecided) {}
151
152 int32_t index; ///< entry position inside the memory cache
153 int64_t offset; ///< bytes written/read to/from the memory cache so far
154
155 Io io; ///< current I/O state
156 };
157 MemCache memCache; ///< current [shared] memory caching state for the entry
158
159 /* Read only - this reply must be preserved by store clients */
160 /* The original reply. possibly with updated metadata. */
161 HttpRequestPointer request;
162
163 struct timeval start_ping;
164 IRCB *ping_reply_callback;
165 PeerSelector *ircb_data;
166
167 struct {
168 STABH *callback;
169 void *data;
170 } abort;
171 RemovalPolicyNode repl;
172 int id;
173 int64_t object_sz;
174 size_t swap_hdr_sz;
175 #if URL_CHECKSUM_DEBUG
176
177 unsigned int chksum;
178 #endif
179
180 SBuf vary_headers;
181
182 void delayRead(DeferredRead const &);
183 void kickReads();
184
185 private:
186 HttpReplyPointer reply_;
187
188 mutable String storeId_; ///< StoreId for our entry (usually request URI)
189 mutable String logUri_; ///< URI used for logging (usually request URI)
190
191 DeferredReadManager deferredReads;
192 };
193
194 /** global current memory removal policy */
195 extern RemovalPolicy *mem_policy;
196
197 #endif /* SQUID_MEMOBJECT_H */
198