]> git.ipfire.org Git - thirdparty/squid.git/blame - src/Transients.h
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / Transients.h
CommitLineData
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
9a9954ba
AR
9#ifndef SQUID_TRANSIENTS_H
10#define SQUID_TRANSIENTS_H
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 20typedef 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 27class Transients: public Store::Controlled, public Ipc::StoreMapCleaner
9a9954ba
AR
28{
29public:
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 93protected:
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 *);
97 void anchorEntry(StoreEntry &, const sfileno, const Ipc::StoreMapAnchor &);
4475555f 98
9a9954ba 99 // Ipc::StoreMapCleaner API
337b9aa4 100 void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId) override;
9a9954ba
AR
101
102private:
6919be24
AR
103 /// shared packed info indexed by Store keys, for creating new StoreEntries
104 TransientsMap *map;
105
106 typedef std::vector<StoreEntry*> Locals;
4310f8b0
EB
107 /// local collapsed reader and writer entries, indexed by transient ID,
108 /// for syncing old StoreEntries
6919be24 109 Locals *locals;
9a9954ba
AR
110};
111
112// TODO: Why use Store as a base? We are not really a cache.
113
e4d13993 114#endif /* SQUID_TRANSIENTS_H */
f53969cc 115