]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Transients.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / Transients.h
1 /*
2 * Copyright (C) 1996-2017 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_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"
17 #include "store/Controlled.h"
18 #include <vector>
19
20 // StoreEntry restoration info not already stored by Ipc::StoreMap
21 struct TransientsMapExtraItem {
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 };
26 typedef Ipc::StoreMapItems<TransientsMapExtraItem> TransientsMapExtras;
27 typedef Ipc::StoreMap TransientsMap;
28
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).
32 class Transients: public Store::Controlled, public Ipc::StoreMapCleaner
33 {
34 public:
35 Transients();
36 virtual ~Transients();
37
38 /// return a local, previously collapsed entry
39 StoreEntry *findCollapsed(const sfileno xitIndex);
40
41 /// add an in-transit entry suitable for collapsing future requests
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);
46
47 /// the calling entry writer no longer expects to cache this entry
48 void abandon(const StoreEntry &e);
49
50 /// whether an in-transit entry is now abandoned by its writer
51 bool abandoned(const StoreEntry &e) const;
52
53 /// number of entry readers some time ago
54 int readers(const StoreEntry &e) const;
55
56 /// the caller is done writing or reading this entry
57 void disconnect(MemObject &mem_obj);
58
59 /* Store API */
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;
75 virtual bool smpAware() const override { return true; }
76
77 static int64_t EntryLimit();
78
79 protected:
80 StoreEntry *copyFromShm(const sfileno index);
81 bool copyToShm(const StoreEntry &e, const sfileno index, const RequestFlags &reqFlags, const HttpRequestMethod &reqMethod);
82
83 bool abandonedAt(const sfileno index) const;
84
85 // Ipc::StoreMapCleaner API
86 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId) override;
87
88 private:
89 /// shared packed info indexed by Store keys, for creating new StoreEntries
90 TransientsMap *map;
91
92 /// shared packed info that standard StoreMap does not store for us
93 typedef TransientsMapExtras Extras;
94 Ipc::Mem::Pointer<Extras> extras;
95
96 typedef std::vector<StoreEntry*> Locals;
97 /// local collapsed entries indexed by transient ID, for syncing old StoreEntries
98 Locals *locals;
99 };
100
101 // TODO: Why use Store as a base? We are not really a cache.
102
103 #endif /* SQUID_TRANSIENTS_H */
104