Skip to content

Commit 989cfe0

Browse files
committed
some other fixes
1 parent 43c1383 commit 989cfe0

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

src/Storages/Cache/ObjectStorageListObjectsCache.cpp

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <Storages/Cache/ObjectStorageListObjectsCache.h>
2+
#include <boost/functional/hash.hpp>
23

34
namespace DB
45
{
@@ -67,16 +68,6 @@ class ObjectStorageListObjectsCachePolicy : public TTLCachePolicy<Key, Mapped, H
6768
return std::nullopt;
6869
}
6970

70-
bool contains(const Key & key) const override
71-
{
72-
if (cache.contains(key))
73-
{
74-
return true;
75-
}
76-
77-
return findAnyMatchingPrefix(key) != cache.end();
78-
}
79-
8071
private:
8172
auto findBestMatchingPrefix(const Key & key)
8273
{
@@ -85,16 +76,18 @@ class ObjectStorageListObjectsCachePolicy : public TTLCachePolicy<Key, Mapped, H
8576
auto best_match = cache.end();
8677
size_t best_length = 0;
8778

79+
std::vector<Key> to_remove;
80+
8881
for (auto it = cache.begin(); it != cache.end(); ++it)
8982
{
9083
const auto & candidate_bucket = it->first.bucket;
9184
const auto & candidate_prefix = it->first.prefix;
9285

9386
if (candidate_bucket == key.bucket && prefix.starts_with(candidate_prefix))
9487
{
95-
if (IsStaleFunction()(it->fist))
88+
if (IsStaleFunction()(it->first))
9689
{
97-
BasePolicy::remove(it->first);
90+
to_remove.push_back(it->first);
9891
continue;
9992
}
10093

@@ -106,29 +99,10 @@ class ObjectStorageListObjectsCachePolicy : public TTLCachePolicy<Key, Mapped, H
10699
}
107100
}
108101

109-
return best_match;
110-
}
111-
112-
auto findAnyMatchingPrefix(const Key & key) const
113-
{
114-
const auto & bucket = key.bucket;
115-
const auto & prefix = key.prefix;
116-
return std::find_if(cache.begin(), cache.end(), [&](const auto & it)
117-
{
118-
const auto & candidate_bucket = it.first.bucket;
119-
const auto & candidate_prefix = it.first.prefix;
120-
if (candidate_bucket == key.bucket && prefix.starts_with(candidate_prefix))
121-
{
122-
if (IsStaleFunction()(it->fist))
123-
{
124-
BasePolicy::remove(it->first);
125-
continue;
126-
}
127-
return true;
128-
}
102+
for (const auto & k : to_remove)
103+
BasePolicy::remove(k);
129104

130-
return false;
131-
});
105+
return best_match;
132106
}
133107
};
134108

@@ -146,7 +120,12 @@ bool ObjectStorageListObjectsCache::Key::operator==(const Key & other) const
146120

147121
size_t ObjectStorageListObjectsCache::KeyHasher::operator()(const Key & key) const
148122
{
149-
return std::hash<String>()(key.prefix) + std::hash<String>()(key.bucket);
123+
std::size_t seed = 0;
124+
125+
boost::hash_combine(seed, std::hash<String>()(key.bucket));
126+
boost::hash_combine(seed, std::hash<String>()(key.prefix));
127+
128+
return seed;
150129
}
151130

152131
bool ObjectStorageListObjectsCache::IsStale::operator()(const Key & key) const
@@ -160,7 +139,7 @@ size_t ObjectStorageListObjectsCache::WeightFunction::operator()(const Value & v
160139

161140
for (const auto & object : value)
162141
{
163-
weight += object->relative_path.size() + sizeof(ObjectMetadata);
142+
weight += object->relative_path.capacity() + sizeof(ObjectMetadata);
164143
}
165144

166145
return weight;

src/Storages/ObjectStorage/StorageObjectStorageSource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <Processors/Formats/IInputFormat.h>
88
#include <Storages/ObjectStorage/StorageObjectStorage.h>
99
#include <Storages/ObjectStorage/IObjectIterator.h>
10+
#include <Storages/Cache/ObjectStorageListObjectsCache.h>
1011

1112

1213
namespace DB

0 commit comments

Comments
 (0)