Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoupling local cache function and cache algorithm #38048

Merged
Prev Previous commit
Next Next commit
better
  • Loading branch information
KinderRiven committed Aug 10, 2022
commit 43cf7716574c5d4c99a16433d18143928a480d25
30 changes: 22 additions & 8 deletions src/Common/IFileCachePriority.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
namespace DB
{

namespace ErrorCodes
{
extern const int NOT_IMPLEMENTED;
}

class IFileCachePriority;
using FileCachePriorityPtr = std::shared_ptr<IFileCachePriority>;

Expand Down Expand Up @@ -39,16 +44,29 @@ class IFileCachePriority
public:
virtual ~IIterator() = default;

virtual void next() = 0;
virtual void next() { throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not support next() for IIterator."); }

virtual bool valid() const = 0;
virtual bool valid() const { throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not support valid() for IIterator."); }

/// Mark a cache record as recently used, it will update the priority
/// of the cache record according to different cache algorithms.
virtual void use(std::lock_guard<std::mutex> & cache_lock) = 0;
virtual void use(std::lock_guard<std::mutex> &)
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not support use() for IIterator.");
}

/// Deletes an existing cached record.
virtual void remove(std::lock_guard<std::mutex> & cache_lock) = 0;
virtual void remove(std::lock_guard<std::mutex> &)
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not support remove() for IIterator.");
}

virtual Iterator getSnapshot() { throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not support getSnapshot() for IIterator."); }

virtual void incrementSize(size_t, std::lock_guard<std::mutex> &)
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not support incrementSize() for IIterator.");
}

virtual Key & key() const = 0;

Expand All @@ -57,10 +75,6 @@ class IFileCachePriority
virtual size_t size() const = 0;

virtual size_t hits() const = 0;

virtual Iterator getSnapshot() = 0;

virtual void incrementSize(size_t size_increment, std::lock_guard<std::mutex> & cache_lock) = 0;
};

public:
Expand Down
2 changes: 1 addition & 1 deletion src/Common/LRUFileCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ void FileCache::assertCacheCellsCorrectness(
if (file_segment->reserved_size != 0)
{
assert(cell.queue_iterator);
assert(priority.contains(file_segment->key(), file_segment->offset(), cache_lock));
assert(main_priority->contains(file_segment->key(), file_segment->offset(), cache_lock));
}
}
}
Expand Down