]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Transients.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / Transients.h
1 /*
2 * Copyright (C) 1996-2020 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 "ipc/mem/Page.h"
13 #include "ipc/mem/PageStack.h"
14 #include "ipc/StoreMap.h"
15 #include "Store.h"
16 #include "store/Controlled.h"
17 #include "store/forward.h"
18 #include <vector>
19
20 typedef Ipc::StoreMap TransientsMap;
21
22 /// Keeps track of store entries being delivered to clients that arrived before
23 /// those entries were [fully] cached. This SMP-shared table is necessary to
24 /// * sync an entry-writing worker with entry-reading worker(s); and
25 /// * sync an entry-deleting worker with both entry-reading/writing workers.
26 class Transients: public Store::Controlled, public Ipc::StoreMapCleaner
27 {
28 public:
29 /// shared entry metadata, used for synchronization
30 class EntryStatus
31 {
32 public:
33 bool abortedByWriter = false; ///< whether the entry was aborted
34 bool waitingToBeFreed = false; ///< whether the entry was marked for deletion
35 bool collapsed = false; ///< whether the entry allows collapsing
36 };
37
38 Transients();
39 virtual ~Transients();
40
41 /// return a local, previously collapsed entry
42 StoreEntry *findCollapsed(const sfileno xitIndex);
43
44 /// removes collapsing requirement (for future hits)
45 void clearCollapsingRequirement(const StoreEntry &e);
46
47 /// start listening for remote DELETE requests targeting either a complete
48 /// StoreEntry (ioReading) or a being-formed miss StoreEntry (ioWriting)
49 void monitorIo(StoreEntry*, const cache_key*, const Store::IoStatus);
50
51 /// called when the in-transit entry has been successfully cached
52 void completeWriting(const StoreEntry &e);
53
54 /// copies current shared entry metadata into entryStatus
55 void status(const StoreEntry &e, EntryStatus &entryStatus) const;
56
57 /// number of entry readers some time ago
58 int readers(const StoreEntry &e) const;
59
60 /// the caller is done writing or reading the given entry
61 void disconnect(StoreEntry &);
62
63 /* Store API */
64 virtual StoreEntry *get(const cache_key *) override;
65 virtual void create() override {}
66 virtual void init() override;
67 virtual uint64_t maxSize() const override;
68 virtual uint64_t minSize() const override;
69 virtual uint64_t currentSize() const override;
70 virtual uint64_t currentCount() const override;
71 virtual int64_t maxObjectSize() const override;
72 virtual void getStats(StoreInfoStats &stats) const override;
73 virtual void stat(StoreEntry &e) const override;
74 virtual void reference(StoreEntry &e) override;
75 virtual bool dereference(StoreEntry &e) override;
76 virtual void evictCached(StoreEntry &) override;
77 virtual void evictIfFound(const cache_key *) override;
78 virtual void maintain() override;
79
80 /// Whether an entry with the given public key exists and (but) was
81 /// marked for removal some time ago; get(key) returns nil in such cases.
82 bool markedForDeletion(const cache_key *) const;
83
84 /// whether the entry is in "reading from Transients" I/O state
85 bool isReader(const StoreEntry &) const;
86 /// whether the entry is in "writing to Transients" I/O state
87 bool isWriter(const StoreEntry &) const;
88
89 static int64_t EntryLimit();
90
91 /// Can we create and initialize Transients?
92 static bool Enabled() { return EntryLimit(); }
93
94 protected:
95 void addEntry(StoreEntry*, const cache_key *, const Store::IoStatus);
96
97 // Ipc::StoreMapCleaner API
98 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId) override;
99
100 private:
101 /// shared packed info indexed by Store keys, for creating new StoreEntries
102 TransientsMap *map;
103
104 typedef std::vector<StoreEntry*> Locals;
105 /// local collapsed reader and writer entries, indexed by transient ID,
106 /// for syncing old StoreEntries
107 Locals *locals;
108 };
109
110 // TODO: Why use Store as a base? We are not really a cache.
111
112 #endif /* SQUID_TRANSIENTS_H */
113