]> git.ipfire.org Git - thirdparty/squid.git/blob - src/store/Controller.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / store / Controller.h
1 /*
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
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
9 #ifndef SQUID_STORE_CONTROLLER_H
10 #define SQUID_STORE_CONTROLLER_H
11
12 #include "store/Storage.h"
13
14 class MemObject;
15 class RequestFlags;
16 class HttpRequestMethod;
17
18 namespace Store {
19
20 /// Public Store interface. Coordinates the work of memory/disk/transient stores
21 /// and hides their individual existence/differences from the callers.
22 class Controller: public Storage
23 {
24 public:
25 Controller();
26 virtual ~Controller() override;
27
28 /* Storage API */
29 virtual void create() override;
30 virtual void init() override;
31 virtual StoreEntry *get(const cache_key *) override;
32 virtual uint64_t maxSize() const override;
33 virtual uint64_t minSize() const override;
34 virtual uint64_t currentSize() const override;
35 virtual uint64_t currentCount() const override;
36 virtual int64_t maxObjectSize() const override;
37 virtual void getStats(StoreInfoStats &stats) const override;
38 virtual void stat(StoreEntry &) const override;
39 virtual void sync() override;
40 virtual void maintain() override;
41 virtual void markForUnlink(StoreEntry &) override;
42 virtual void unlink(StoreEntry &) override;
43 virtual int callback() override;
44
45 /// called when the entry is no longer needed by any transaction
46 void handleIdleEntry(StoreEntry &);
47
48 /// called to get rid of no longer needed entry data in RAM, if any
49 void memoryOut(StoreEntry &, const bool preserveSwappable);
50
51 /// makes the entry available for collapsing future requests
52 void allowCollapsing(StoreEntry *, const RequestFlags &, const HttpRequestMethod &);
53
54 /// marks the entry completed for collapsed requests
55 void transientsCompleteWriting(StoreEntry &);
56
57 /// Update local intransit entry after changes made by appending worker.
58 void syncCollapsed(const sfileno);
59
60 /// calls Root().transients->abandon() if transients are tracked
61 void transientsAbandon(StoreEntry &);
62
63 /// number of the transient entry readers some time ago
64 int transientReaders(const StoreEntry &) const;
65
66 /// disassociates the entry from the intransit table
67 void transientsDisconnect(MemObject &);
68
69 /// removes the entry from the memory cache
70 void memoryUnlink(StoreEntry &);
71
72 /// disassociates the entry from the memory cache, preserving cached data
73 void memoryDisconnect(StoreEntry &);
74
75 /// \returns an iterator for all Store entries
76 StoreSearch *search();
77
78 /// the number of cache_dirs being rebuilt; TODO: move to Disks::Rebuilding
79 static int store_dirs_rebuilding;
80
81 private:
82 /// update reference counters of the recently touched entry
83 void referenceBusy(StoreEntry &e);
84 /// dereference() an idle entry and return true if the entry should be deleted
85 bool dereferenceIdle(StoreEntry &, bool wantsLocalMemory);
86
87 StoreEntry *find(const cache_key *key);
88 bool keepForLocalMemoryCache(StoreEntry &e) const;
89 bool anchorCollapsed(StoreEntry &, bool &inSync);
90
91 Disks *swapDir; ///< summary view of all disk caches
92 Memory *memStore; ///< memory cache
93
94 /// A shared table of public store entries that do not know whether they
95 /// will belong to a memory cache, a disk cache, or will be uncachable
96 /// when the response header comes. Used for SMP collapsed forwarding.
97 Transients *transients;
98 };
99
100 /// safely access controller singleton
101 extern Controller &Root();
102
103 /// initialize the storage module; a custom root is used by unit tests only
104 extern void Init(Controller *root = nullptr);
105
106 /// undo Init()
107 extern void FreeMemory();
108
109 } // namespace Store
110
111 #endif /* SQUID_STORE_CONTROLLER_H */
112