ClickHouse/src/Common/ICachePolicyUserQuota.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.8 KiB
C++
Raw Normal View History

2023-03-31 10:37:11 +00:00
#pragma once
2024-01-09 12:05:02 +00:00
#include <base/UUID.h>
2023-03-31 10:37:11 +00:00
#include <base/types.h>
namespace DB
{
/// Per-user quotas for usage of shared caches, used by ICachePolicy.
/// Currently allows to limit
/// - the maximum amount of cache memory a user may consume
/// - the maximum number of items a user can store in the cache
/// Note that caches usually also have global limits which restrict these values at cache level. Per-user quotas have no effect if they
/// exceed the global thresholds.
class ICachePolicyUserQuota
{
public:
/// Register or update the user's quota for the given resource.
2024-01-11 13:33:16 +00:00
virtual void setQuotaForUser(const UUID & user_id, size_t max_size_in_bytes, size_t max_entries) = 0;
2023-03-31 10:37:11 +00:00
/// Update the actual resource usage for the given user.
2024-01-11 13:33:16 +00:00
virtual void increaseActual(const UUID & user_id, size_t entry_size_in_bytes) = 0;
virtual void decreaseActual(const UUID & user_id, size_t entry_size_in_bytes) = 0;
2023-03-31 10:37:11 +00:00
/// Is the user allowed to write a new entry into the cache?
2024-01-11 13:33:16 +00:00
virtual bool approveWrite(const UUID & user_id, size_t entry_size_in_bytes) const = 0;
2023-03-31 10:37:11 +00:00
/// Clears the policy contents
virtual void clear() = 0;
2023-03-31 10:37:11 +00:00
virtual ~ICachePolicyUserQuota() = default;
};
using CachePolicyUserQuotaPtr = std::unique_ptr<ICachePolicyUserQuota>;
class NoCachePolicyUserQuota : public ICachePolicyUserQuota
{
public:
2024-01-11 13:33:16 +00:00
void setQuotaForUser(const UUID & /*user_id*/, size_t /*max_size_in_bytes*/, size_t /*max_entries*/) override {}
void increaseActual(const UUID & /*user_id*/, size_t /*entry_size_in_bytes*/) override {}
void decreaseActual(const UUID & /*user_id*/, size_t /*entry_size_in_bytes*/) override {}
bool approveWrite(const UUID & /*user_id*/, size_t /*entry_size_in_bytes*/) const override { return true; }
void clear() override {}
2023-03-31 10:37:11 +00:00
};
}