]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
5b74111a | 2 | * Copyright (C) 1996-2018 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
9a9954ba AR |
9 | #ifndef SQUID_TRANSIENTS_H |
10 | #define SQUID_TRANSIENTS_H | |
11 | ||
12 | #include "http/MethodType.h" | |
13 | #include "ipc/mem/Page.h" | |
14 | #include "ipc/mem/PageStack.h" | |
15 | #include "ipc/StoreMap.h" | |
16 | #include "Store.h" | |
2745fea5 | 17 | #include "store/Controlled.h" |
6919be24 | 18 | #include <vector> |
9a9954ba AR |
19 | |
20 | // StoreEntry restoration info not already stored by Ipc::StoreMap | |
1860fbac | 21 | struct TransientsMapExtraItem { |
9a9954ba AR |
22 | char url[MAX_URL+1]; ///< Request-URI; TODO: decrease MAX_URL by one |
23 | RequestFlags reqFlags; ///< request flags | |
24 | Http::MethodType reqMethod; ///< request method; extensions are not supported | |
25 | }; | |
1860fbac AR |
26 | typedef Ipc::StoreMapItems<TransientsMapExtraItem> TransientsMapExtras; |
27 | typedef Ipc::StoreMap TransientsMap; | |
9a9954ba | 28 | |
e4d13993 AR |
29 | /// Keeps track of store entries being delivered to clients that arrived before |
30 | /// those entries were [fully] cached. This shared table is necessary to sync | |
31 | /// the entry-writing worker with entry-reading worker(s). | |
2745fea5 | 32 | class Transients: public Store::Controlled, public Ipc::StoreMapCleaner |
9a9954ba AR |
33 | { |
34 | public: | |
35 | Transients(); | |
36 | virtual ~Transients(); | |
37 | ||
6919be24 AR |
38 | /// return a local, previously collapsed entry |
39 | StoreEntry *findCollapsed(const sfileno xitIndex); | |
40 | ||
9a9954ba | 41 | /// add an in-transit entry suitable for collapsing future requests |
99921d9d AR |
42 | void startWriting(StoreEntry *e, const RequestFlags &reqFlags, const HttpRequestMethod &reqMethod); |
43 | ||
44 | /// called when the in-transit entry has been successfully cached | |
45 | void completeWriting(const StoreEntry &e); | |
9a9954ba | 46 | |
4475555f AR |
47 | /// the calling entry writer no longer expects to cache this entry |
48 | void abandon(const StoreEntry &e); | |
9a9954ba | 49 | |
4475555f AR |
50 | /// whether an in-transit entry is now abandoned by its writer |
51 | bool abandoned(const StoreEntry &e) const; | |
52 | ||
d366a7fa AR |
53 | /// number of entry readers some time ago |
54 | int readers(const StoreEntry &e) const; | |
55 | ||
99921d9d | 56 | /// the caller is done writing or reading this entry |
4475555f | 57 | void disconnect(MemObject &mem_obj); |
9a9954ba AR |
58 | |
59 | /* Store API */ | |
2745fea5 AR |
60 | virtual StoreEntry *get(const cache_key *) override; |
61 | virtual void create() override {} | |
62 | virtual void init() override; | |
63 | virtual uint64_t maxSize() const override; | |
64 | virtual uint64_t minSize() const override; | |
65 | virtual uint64_t currentSize() const override; | |
66 | virtual uint64_t currentCount() const override; | |
67 | virtual int64_t maxObjectSize() const override; | |
68 | virtual void getStats(StoreInfoStats &stats) const override; | |
69 | virtual void stat(StoreEntry &e) const override; | |
70 | virtual void reference(StoreEntry &e) override; | |
71 | virtual bool dereference(StoreEntry &e) override; | |
72 | virtual void markForUnlink(StoreEntry &e) override; | |
73 | virtual void unlink(StoreEntry &e) override; | |
74 | virtual void maintain() override; | |
1a210de4 | 75 | virtual bool smpAware() const override { return true; } |
9a9954ba AR |
76 | |
77 | static int64_t EntryLimit(); | |
78 | ||
79 | protected: | |
4475555f | 80 | StoreEntry *copyFromShm(const sfileno index); |
9a9954ba AR |
81 | bool copyToShm(const StoreEntry &e, const sfileno index, const RequestFlags &reqFlags, const HttpRequestMethod &reqMethod); |
82 | ||
4475555f AR |
83 | bool abandonedAt(const sfileno index) const; |
84 | ||
9a9954ba | 85 | // Ipc::StoreMapCleaner API |
a9b0467a | 86 | virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId) override; |
9a9954ba AR |
87 | |
88 | private: | |
6919be24 AR |
89 | /// shared packed info indexed by Store keys, for creating new StoreEntries |
90 | TransientsMap *map; | |
91 | ||
1860fbac AR |
92 | /// shared packed info that standard StoreMap does not store for us |
93 | typedef TransientsMapExtras Extras; | |
94 | Ipc::Mem::Pointer<Extras> extras; | |
95 | ||
6919be24 AR |
96 | typedef std::vector<StoreEntry*> Locals; |
97 | /// local collapsed entries indexed by transient ID, for syncing old StoreEntries | |
98 | Locals *locals; | |
9a9954ba AR |
99 | }; |
100 | ||
101 | // TODO: Why use Store as a base? We are not really a cache. | |
102 | ||
e4d13993 | 103 | #endif /* SQUID_TRANSIENTS_H */ |
f53969cc | 104 |