]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Transients.h
e05fdb73bdf23c423bfff76980cea74722f8af7c
[thirdparty/squid.git] / src / Transients.h
1 /*
2 * Copyright (C) 1996-2023 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 /// A Transients entry allows workers to Broadcast() DELETE requests and swapout
23 /// progress updates. In a collapsed forwarding context, it also represents a CF
24 /// initiating worker promise to either cache the response or inform the waiting
25 /// slaves (via false EntryStatus::hasWriter) that caching will not happen. A
26 /// Transients entry itself does not carry response- or Store-specific metadata.
27 class Transients: public Store::Controlled, public Ipc::StoreMapCleaner
28 {
29 public:
30 /// shared entry metadata, used for synchronization
31 class EntryStatus
32 {
33 public:
34 bool hasWriter = false; ///< whether some worker is storing the entry
35 bool waitingToBeFreed = false; ///< whether the entry was marked for deletion
36 };
37
38 Transients();
39 ~Transients() override;
40
41 /// return a local, previously collapsed entry
42 StoreEntry *findCollapsed(const sfileno xitIndex);
43
44 /// start listening for remote DELETE requests targeting either a complete
45 /// StoreEntry (ioReading) or a being-formed miss StoreEntry (ioWriting)
46 void monitorIo(StoreEntry*, const cache_key*, const Store::IoStatus);
47
48 /// called when the in-transit entry has been successfully cached
49 void completeWriting(const StoreEntry &e);
50
51 /// copies current shared entry metadata into entryStatus
52 void status(const StoreEntry &e, EntryStatus &entryStatus) const;
53
54 /// number of entry readers some time ago
55 int readers(const StoreEntry &e) const;
56
57 /// the caller is done writing or reading the given entry
58 void disconnect(StoreEntry &);
59
60 /* Store API */
61 StoreEntry *get(const cache_key *) override;
62 void create() override {}
63 void init() override;
64 uint64_t maxSize() const override;
65 uint64_t minSize() const override;
66 uint64_t currentSize() const override;
67 uint64_t currentCount() const override;
68 int64_t maxObjectSize() const override;
69 void getStats(StoreInfoStats &stats) const override;
70 void stat(StoreEntry &e) const override;
71 void reference(StoreEntry &e) override;
72 bool dereference(StoreEntry &e) override;
73 void evictCached(StoreEntry &) override;
74 void evictIfFound(const cache_key *) override;
75 void maintain() override;
76
77 /// Whether an entry with the given public key exists and (but) was
78 /// marked for removal some time ago; get(key) returns nil in such cases.
79 bool markedForDeletion(const cache_key *) const;
80
81 /// whether the entry is in "reading from Transients" I/O state
82 bool isReader(const StoreEntry &) const;
83 /// whether the entry is in "writing to Transients" I/O state
84 bool isWriter(const StoreEntry &) const;
85 /// whether we or somebody else is in the "writing to Transients" I/O state
86 bool hasWriter(const StoreEntry &);
87
88 static int64_t EntryLimit();
89
90 /// Can we create and initialize Transients?
91 static bool Enabled() { return EntryLimit(); }
92
93 protected:
94 void addEntry(StoreEntry*, const cache_key *, const Store::IoStatus);
95 void addWriterEntry(StoreEntry &, const cache_key *);
96 void addReaderEntry(StoreEntry &, const cache_key *);
97 void anchorEntry(StoreEntry &, const sfileno, const Ipc::StoreMapAnchor &);
98
99 // Ipc::StoreMapCleaner API
100 void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId) override;
101
102 private:
103 /// shared packed info indexed by Store keys, for creating new StoreEntries
104 TransientsMap *map;
105
106 typedef std::vector<StoreEntry*> Locals;
107 /// local collapsed reader and writer entries, indexed by transient ID,
108 /// for syncing old StoreEntries
109 Locals *locals;
110 };
111
112 // TODO: Why use Store as a base? We are not really a cache.
113
114 #endif /* SQUID_TRANSIENTS_H */
115