]>
Commit | Line | Data |
---|---|---|
2745fea5 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
2745fea5 AR |
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 | /* DEBUG: section 47 Store Search */ | |
10 | ||
11 | #include "squid.h" | |
675b8408 | 12 | #include "debug/Stream.h" |
2745fea5 AR |
13 | #include "globals.h" |
14 | #include "store/LocalSearch.h" | |
15 | #include "StoreSearch.h" | |
16 | ||
17 | namespace Store { | |
18 | ||
19 | /// iterates local store_table | |
20 | class LocalSearch : public StoreSearch | |
21 | { | |
22 | CBDATA_CLASS(LocalSearch); | |
23 | ||
24 | public: | |
2745fea5 | 25 | /* StoreSearch API */ |
337b9aa4 AR |
26 | void next(void (callback)(void *cbdata), void *cbdata) override; |
27 | bool next() override; | |
28 | bool error() const override; | |
29 | bool isDone() const override; | |
30 | StoreEntry *currentItem() override; | |
2745fea5 AR |
31 | |
32 | private: | |
33 | void copyBucket(); | |
43b6575c AJ |
34 | bool _done = false; |
35 | int bucket = 0; | |
2745fea5 AR |
36 | std::vector<StoreEntry *> entries; |
37 | }; | |
38 | ||
39 | } // namespace Store | |
40 | ||
41 | CBDATA_NAMESPACED_CLASS_INIT(Store, LocalSearch); | |
42 | ||
43 | StoreSearch * | |
44 | Store::NewLocalSearch() | |
45 | { | |
46 | return new LocalSearch; | |
47 | } | |
48 | ||
2745fea5 AR |
49 | void |
50 | Store::LocalSearch::next(void (aCallback)(void *), void *aCallbackData) | |
51 | { | |
52 | next(); | |
53 | aCallback (aCallbackData); | |
54 | } | |
55 | ||
56 | bool | |
57 | Store::LocalSearch::next() | |
58 | { | |
59 | if (!entries.empty()) | |
60 | entries.pop_back(); | |
61 | ||
62 | while (!isDone() && !entries.size()) | |
63 | copyBucket(); | |
64 | ||
aee3523a | 65 | return currentItem() != nullptr; |
2745fea5 AR |
66 | } |
67 | ||
68 | bool | |
69 | Store::LocalSearch::error() const | |
70 | { | |
71 | return false; | |
72 | } | |
73 | ||
74 | bool | |
75 | Store::LocalSearch::isDone() const | |
76 | { | |
77 | return bucket >= store_hash_buckets || _done; | |
78 | } | |
79 | ||
80 | StoreEntry * | |
81 | Store::LocalSearch::currentItem() | |
82 | { | |
83 | if (!entries.size()) | |
aee3523a | 84 | return nullptr; |
2745fea5 AR |
85 | |
86 | return entries.back(); | |
87 | } | |
88 | ||
89 | void | |
90 | Store::LocalSearch::copyBucket() | |
91 | { | |
92 | /* probably need to lock the store entries... | |
93 | * we copy them all to prevent races on the links. */ | |
2745fea5 | 94 | assert (!entries.size()); |
aee3523a AR |
95 | hash_link *link_ptr = nullptr; |
96 | hash_link *link_next = nullptr; | |
2745fea5 AR |
97 | link_next = hash_get_bucket(store_table, bucket); |
98 | ||
aee3523a | 99 | while (nullptr != (link_ptr = link_next)) { |
2745fea5 AR |
100 | link_next = link_ptr->next; |
101 | StoreEntry *e = (StoreEntry *) link_ptr; | |
102 | ||
103 | entries.push_back(e); | |
104 | } | |
105 | ||
123cad13 EB |
106 | // minimize debugging: we may be called more than a million times on startup |
107 | if (const auto count = entries.size()) | |
108 | debugs(47, 8, "bucket #" << bucket << " entries: " << count); | |
109 | ||
2745fea5 | 110 | ++bucket; |
2745fea5 | 111 | } |
7d84d4ca | 112 |