MemObject.h
Go to the documentation of this file.
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 {
36 
37 public:
38  static size_t inUseCount();
39 
40  void dump() const;
41  MemObject();
42  ~MemObject();
43 
50  void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod);
51 
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();
62  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;
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 
93  const char *urlXXX() const { return storeId(); }
94 
97  const char *storeId() const;
98 
100  const char *logUri() const;
101 
104  int64_t inmem_lo = 0;
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 = 0;
112 
113  class SwapOut
114  {
115  public:
116  int64_t queue_offset = 0;
118 
120  typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision;
122  };
123 
125 
126  /* TODO: Remove this change-minimizing hack */
128  static constexpr Io ioUndecided = Store::ioUndecided;
129  static constexpr Io ioReading = Store::ioReading;
130  static constexpr Io ioWriting = Store::ioWriting;
131  static constexpr Io ioDone = Store::ioDone;
132 
134  class XitTable
135  {
136  public:
137  int32_t index = -1;
139  };
141 
143  class MemCache
144  {
145  public:
146  int32_t index = -1;
147  int64_t offset = 0;
148 
150  };
152 
153  /* Read only - this reply must be preserved by store clients */
154  /* The original reply. possibly with updated metadata. */
156 
157  struct timeval start_ping;
160 
161  struct abort_ {
162  abort_() { callback = nullptr; }
164  void *data = nullptr;
165  } abort;
167  int id = 0;
168  int64_t object_sz = -1;
169  size_t swap_hdr_sz = 0;
170 #if URL_CHECKSUM_DEBUG
171  unsigned int chksum = 0;
172 #endif
173 
175 
176  void delayRead(DeferredRead const &);
177  void kickReads();
178 
179 private:
181 
182  mutable String storeId_;
183  mutable String logUri_;
184 
186 };
187 
189 extern RemovalPolicy *mem_policy;
190 
191 #endif /* SQUID_MEMOBJECT_H */
192 
void replaceReply(const HttpReplyPointer &r)
Definition: MemObject.h:58
Io io
current I/O state
Definition: MemObject.h:138
RemovalPolicyNode repl
Definition: MemObject.h:166
Decision decision
current decision state
Definition: MemObject.h:121
void kickReads()
Definition: MemObject.cc:442
static int sc[16]
Definition: smbdes.c:121
int64_t size() const
Definition: MemObject.cc:233
#define MEMPROXY_CLASS(CLASS)
String storeId_
StoreId for our entry (usually request URI)
Definition: MemObject.h:182
size_t swap_hdr_sz
Definition: MemObject.h:169
void unlinkRequest()
Definition: MemObject.h:56
Definition: SBuf.h:86
static constexpr Io ioWriting
Definition: MemObject.h:130
int64_t endOffset() const
Definition: MemObject.cc:218
void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod)
Definition: MemObject.cc:77
Io io
current I/O state
Definition: MemObject.h:149
STABH * callback
Definition: MemObject.h:163
DeferredReadManager deferredReads
Definition: MemObject.h:185
bool clientIsFirst(void *sc) const
Definition: MemObject.h:109
static size_t inUseCount()
Definition: MemObject.cc:48
Definition: stmem.h:19
const char * logUri() const
client request URI used for logging; storeId() by default
Definition: MemObject.cc:65
struct timeval start_ping
Definition: MemObject.h:157
A const & max(A const &lhs, A const &rhs)
MemCache memCache
current [shared] memory caching state for the entry
Definition: MemObject.h:151
XitTable xitTable
current [shared] memory caching state for the entry
Definition: MemObject.h:140
void trimUnSwappable()
Definition: MemObject.cc:382
static constexpr Io ioUndecided
Definition: MemObject.h:128
int32_t index
entry position inside the memory cache
Definition: MemObject.h:146
int64_t lowestMemReaderOffset() const
Definition: MemObject.cc:270
StoreIOState::Pointer sio
Definition: MemObject.h:117
bool readAheadPolicyCanRead() const
Definition: MemObject.cc:281
int32_t index
entry position inside the in-transit table
Definition: MemObject.h:137
void const char HLPCB void * data
Definition: stub_helper.cc:16
void delayRead(DeferredRead const &)
Definition: MemObject.cc:428
void stat(MemBuf *mb) const
Definition: MemObject.cc:193
HttpReplyPointer reply_
Definition: MemObject.h:180
State of an entry with regards to the [shared] memory caching.
Definition: MemObject.h:143
int64_t object_sz
Definition: MemObject.h:168
const char * storeId() const
Definition: MemObject.cc:54
HttpRequestMethod method
Definition: MemObject.h:102
IoStatus
cache "I/O" direction and status
Definition: forward.h:40
int64_t policyLowestOffsetToKeep(bool swap) const
Definition: MemObject.cc:340
PeerSelector * ircb_data
Definition: MemObject.h:159
void STMCB(void *data, StoreIOBuffer wroteBuffer)
Definition: MemObject.h:27
bool hasUris() const
whether setUris() has been called
Definition: MemObject.cc:71
int64_t objectBytesOnDisk() const
Definition: MemObject.cc:314
String logUri_
URI used for logging (usually request URI)
Definition: MemObject.h:183
void markEndOfReplyHeaders()
Definition: MemObject.cc:224
DelayId mostBytesAllowed() const
Definition: MemObject.cc:449
void write(const StoreIOBuffer &buf)
Definition: MemObject.cc:136
RemovalPolicy * mem_policy
Definition: MemObject.cc:45
void IRCB(CachePeer *, peer_t, AnyP::ProtocolType, void *, void *data)
Definition: typedefs.h:22
void STABH(void *)
Definition: MemObject.h:28
void const char * buf
Definition: stub_helper.cc:16
int mostBytesWanted(int max, bool ignoreDelayPools) const
Definition: MemObject.cc:401
State of an entry with regards to the [shared] in-transit table.
Definition: MemObject.h:134
SwapOut swapout
Definition: MemObject.h:124
SBuf vary_headers
Definition: MemObject.h:174
int64_t queue_offset
number of bytes sent to SwapDir for writing
Definition: MemObject.h:116
struct MemObject::abort_ abort
void reset()
Definition: MemObject.cc:259
dlink_list clients
Definition: MemObject.h:105
Definition: MemBuf.h:23
int nclients
Definition: MemObject.h:111
Decision
Decision states for StoreEntry::swapoutPossible() and related code.
Definition: MemObject.h:120
const HttpReplyPointer & getReply() const
Definition: MemObject.h:57
void dump() const
Definition: MemObject.cc:151
size_t clientCount() const
Definition: MemObject.h:107
mem_hdr data_hdr
Definition: MemObject.h:103
static constexpr Io ioDone
Definition: MemObject.h:131
static constexpr Io ioReading
Definition: MemObject.h:129
void trimSwappable()
Definition: MemObject.cc:357
bool isContiguous() const
Definition: MemObject.cc:392
IRCB * ping_reply_callback
Definition: MemObject.h:158
int64_t availableForSwapOut() const
buffered bytes we have not swapped out yet
Definition: MemObject.cc:485
HttpRequestPointer request
Definition: MemObject.h:155
void setNoDelay(bool const newValue)
Definition: MemObject.cc:415
void addClient(store_client *)
Definition: MemObject.cc:295
int64_t expectedReplySize() const
Definition: MemObject.cc:242
const char * urlXXX() const
Definition: MemObject.h:93
int64_t inmem_lo
Definition: MemObject.h:104
int64_t offset
bytes written/read to/from the memory cache so far
Definition: MemObject.h:147

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors