]> git.ipfire.org Git - thirdparty/squid.git/blame - src/Transients.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / Transients.h
CommitLineData
bbc27441 1/*
77b1029d 2 * Copyright (C) 1996-2020 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
e4d13993 22/// Keeps track of store entries being delivered to clients that arrived before
4310f8b0
EB
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.
2745fea5 26class Transients: public Store::Controlled, public Ipc::StoreMapCleaner
9a9954ba
AR
27{
28public:
d2a6dcba
EB
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
9a9954ba
AR
38 Transients();
39 virtual ~Transients();
40
6919be24
AR
41 /// return a local, previously collapsed entry
42 StoreEntry *findCollapsed(const sfileno xitIndex);
43
d2a6dcba
EB
44 /// removes collapsing requirement (for future hits)
45 void clearCollapsingRequirement(const StoreEntry &e);
46
4310f8b0
EB
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);
99921d9d
AR
50
51 /// called when the in-transit entry has been successfully cached
52 void completeWriting(const StoreEntry &e);
9a9954ba 53
d2a6dcba
EB
54 /// copies current shared entry metadata into entryStatus
55 void status(const StoreEntry &e, EntryStatus &entryStatus) const;
4475555f 56
d366a7fa
AR
57 /// number of entry readers some time ago
58 int readers(const StoreEntry &e) const;
59
4310f8b0
EB
60 /// the caller is done writing or reading the given entry
61 void disconnect(StoreEntry &);
9a9954ba
AR
62
63 /* Store API */
2745fea5
AR
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;
4310f8b0
EB
76 virtual void evictCached(StoreEntry &) override;
77 virtual void evictIfFound(const cache_key *) override;
2745fea5 78 virtual void maintain() override;
9a9954ba 79
4310f8b0
EB
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
9a9954ba
AR
89 static int64_t EntryLimit();
90
daed75a9
EB
91 /// Can we create and initialize Transients?
92 static bool Enabled() { return EntryLimit(); }
93
9a9954ba 94protected:
4310f8b0 95 void addEntry(StoreEntry*, const cache_key *, const Store::IoStatus);
4475555f 96
9a9954ba 97 // Ipc::StoreMapCleaner API
a9b0467a 98 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId) override;
9a9954ba
AR
99
100private:
6919be24
AR
101 /// shared packed info indexed by Store keys, for creating new StoreEntries
102 TransientsMap *map;
103
104 typedef std::vector<StoreEntry*> Locals;
4310f8b0
EB
105 /// local collapsed reader and writer entries, indexed by transient ID,
106 /// for syncing old StoreEntries
6919be24 107 Locals *locals;
9a9954ba
AR
108};
109
110// TODO: Why use Store as a base? We are not really a cache.
111
e4d13993 112#endif /* SQUID_TRANSIENTS_H */
f53969cc 113