]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/Transients.h
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_TRANSIENTS_H
10 #define SQUID_SRC_TRANSIENTS_H
12 #include "ipc/mem/Page.h"
13 #include "ipc/mem/PageStack.h"
14 #include "ipc/StoreMap.h"
16 #include "store/Controlled.h"
17 #include "store/forward.h"
20 typedef Ipc::StoreMap TransientsMap
;
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
30 /// shared entry metadata, used for synchronization
34 bool hasWriter
= false; ///< whether some worker is storing the entry
35 bool waitingToBeFreed
= false; ///< whether the entry was marked for deletion
39 ~Transients() override
;
41 /// return a local, previously collapsed entry
42 StoreEntry
*findCollapsed(const sfileno xitIndex
);
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
);
48 /// called when the in-transit entry has been successfully cached
49 void completeWriting(const StoreEntry
&e
);
51 /// copies current shared entry metadata into entryStatus
52 void status(const StoreEntry
&e
, EntryStatus
&entryStatus
) const;
54 /// number of entry readers some time ago
55 int readers(const StoreEntry
&e
) const;
57 /// the caller is done writing or reading the given entry
58 void disconnect(StoreEntry
&);
61 StoreEntry
*get(const cache_key
*) override
;
62 void create() 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
;
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;
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
&);
88 static int64_t EntryLimit();
90 /// Can we create and initialize Transients?
91 static bool Enabled() { return EntryLimit(); }
94 void addEntry(StoreEntry
*, const cache_key
*, const Store::IoStatus
);
95 void addWriterEntry(StoreEntry
&, const cache_key
*);
96 void addReaderEntry(StoreEntry
&, const cache_key
*);
98 // Ipc::StoreMapCleaner API
99 void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId
) override
;
102 /// shared packed info indexed by Store keys, for creating new StoreEntries
105 typedef std::vector
<StoreEntry
*> Locals
;
106 /// local collapsed reader and writer entries, indexed by transient ID,
107 /// for syncing old StoreEntries
111 // TODO: Why use Store as a base? We are not really a cache.
113 #endif /* SQUID_SRC_TRANSIENTS_H */