]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 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 | ||
ff9d9458 FC |
9 | #ifndef SQUID_SRC_TRANSIENTS_H |
10 | #define SQUID_SRC_TRANSIENTS_H | |
9a9954ba | 11 | |
9a9954ba AR |
12 | #include "ipc/mem/Page.h" |
13 | #include "ipc/mem/PageStack.h" | |
14 | #include "ipc/StoreMap.h" | |
15 | #include "Store.h" | |
2745fea5 | 16 | #include "store/Controlled.h" |
4310f8b0 | 17 | #include "store/forward.h" |
6919be24 | 18 | #include <vector> |
9a9954ba | 19 | |
1860fbac | 20 | typedef Ipc::StoreMap TransientsMap; |
9a9954ba | 21 | |
24c93780 AR |
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. | |
2745fea5 | 27 | class Transients: public Store::Controlled, public Ipc::StoreMapCleaner |
9a9954ba AR |
28 | { |
29 | public: | |
d2a6dcba EB |
30 | /// shared entry metadata, used for synchronization |
31 | class EntryStatus | |
32 | { | |
33 | public: | |
24c93780 | 34 | bool hasWriter = false; ///< whether some worker is storing the entry |
d2a6dcba | 35 | bool waitingToBeFreed = false; ///< whether the entry was marked for deletion |
d2a6dcba EB |
36 | }; |
37 | ||
9a9954ba | 38 | Transients(); |
337b9aa4 | 39 | ~Transients() override; |
9a9954ba | 40 | |
6919be24 AR |
41 | /// return a local, previously collapsed entry |
42 | StoreEntry *findCollapsed(const sfileno xitIndex); | |
43 | ||
4310f8b0 EB |
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); | |
99921d9d AR |
47 | |
48 | /// called when the in-transit entry has been successfully cached | |
49 | void completeWriting(const StoreEntry &e); | |
9a9954ba | 50 | |
d2a6dcba EB |
51 | /// copies current shared entry metadata into entryStatus |
52 | void status(const StoreEntry &e, EntryStatus &entryStatus) const; | |
4475555f | 53 | |
d366a7fa AR |
54 | /// number of entry readers some time ago |
55 | int readers(const StoreEntry &e) const; | |
56 | ||
4310f8b0 EB |
57 | /// the caller is done writing or reading the given entry |
58 | void disconnect(StoreEntry &); | |
9a9954ba AR |
59 | |
60 | /* Store API */ | |
337b9aa4 AR |
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; | |
9a9954ba | 76 | |
4310f8b0 EB |
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; | |
d1d3b4dc EB |
85 | /// whether we or somebody else is in the "writing to Transients" I/O state |
86 | bool hasWriter(const StoreEntry &); | |
4310f8b0 | 87 | |
9a9954ba AR |
88 | static int64_t EntryLimit(); |
89 | ||
daed75a9 EB |
90 | /// Can we create and initialize Transients? |
91 | static bool Enabled() { return EntryLimit(); } | |
92 | ||
9a9954ba | 93 | protected: |
4310f8b0 | 94 | void addEntry(StoreEntry*, const cache_key *, const Store::IoStatus); |
5bd8ce13 AR |
95 | void addWriterEntry(StoreEntry &, const cache_key *); |
96 | void addReaderEntry(StoreEntry &, const cache_key *); | |
4475555f | 97 | |
9a9954ba | 98 | // Ipc::StoreMapCleaner API |
337b9aa4 | 99 | void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId) override; |
9a9954ba AR |
100 | |
101 | private: | |
6919be24 AR |
102 | /// shared packed info indexed by Store keys, for creating new StoreEntries |
103 | TransientsMap *map; | |
104 | ||
105 | typedef std::vector<StoreEntry*> Locals; | |
4310f8b0 EB |
106 | /// local collapsed reader and writer entries, indexed by transient ID, |
107 | /// for syncing old StoreEntries | |
6919be24 | 108 | Locals *locals; |
9a9954ba AR |
109 | }; |
110 | ||
111 | // TODO: Why use Store as a base? We are not really a cache. | |
112 | ||
ff9d9458 | 113 | #endif /* SQUID_SRC_TRANSIENTS_H */ |
f53969cc | 114 |