]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/Transients.h
2 * Copyright (C) 1996-2020 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_TRANSIENTS_H
10 #define SQUID_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 /// Keeps track of store entries being delivered to clients that arrived before
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.
26 class Transients
: public Store::Controlled
, public Ipc::StoreMapCleaner
29 /// shared entry metadata, used for synchronization
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
39 virtual ~Transients();
41 /// return a local, previously collapsed entry
42 StoreEntry
*findCollapsed(const sfileno xitIndex
);
44 /// removes collapsing requirement (for future hits)
45 void clearCollapsingRequirement(const StoreEntry
&e
);
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
);
51 /// called when the in-transit entry has been successfully cached
52 void completeWriting(const StoreEntry
&e
);
54 /// copies current shared entry metadata into entryStatus
55 void status(const StoreEntry
&e
, EntryStatus
&entryStatus
) const;
57 /// number of entry readers some time ago
58 int readers(const StoreEntry
&e
) const;
60 /// the caller is done writing or reading the given entry
61 void disconnect(StoreEntry
&);
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
;
76 virtual void evictCached(StoreEntry
&) override
;
77 virtual void evictIfFound(const cache_key
*) override
;
78 virtual void maintain() override
;
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;
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;
89 static int64_t EntryLimit();
91 /// Can we create and initialize Transients?
92 static bool Enabled() { return EntryLimit(); }
95 void addEntry(StoreEntry
*, const cache_key
*, const Store::IoStatus
);
97 // Ipc::StoreMapCleaner API
98 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId
) override
;
101 /// shared packed info indexed by Store keys, for creating new StoreEntries
104 typedef std::vector
<StoreEntry
*> Locals
;
105 /// local collapsed reader and writer entries, indexed by transient ID,
106 /// for syncing old StoreEntries
110 // TODO: Why use Store as a base? We are not really a cache.
112 #endif /* SQUID_TRANSIENTS_H */