ClickHouse/src/Dictionaries/ICacheDictionaryStorage.h

128 lines
3.8 KiB
C++
Raw Normal View History

2021-02-16 21:33:02 +00:00
#pragma once
#include <Common/PODArray.h>
#include <Common/HashTable/HashMap.h>
#include <Columns/IColumn.h>
#include <Dictionaries/DictionaryHelpers.h>
namespace DB
{
struct KeyState
{
enum State: uint8_t
{
2021-03-17 17:14:36 +00:00
not_found = 0,
expired = 1,
found = 2,
};
KeyState(State state_, size_t fetched_column_index_)
: state(state_)
, fetched_column_index(fetched_column_index_)
{}
KeyState(State state_)
: state(state_)
{}
inline bool isFound() const { return state == State::found; }
inline bool isExpired() const { return state == State::expired; }
inline bool isNotFound() const { return state == State::not_found; }
inline bool isDefault() const { return is_default; }
inline void setDefault() { is_default = true; }
2021-03-13 21:49:45 +00:00
inline void setDefaultValue(bool is_default_value) { is_default = is_default_value; }
2021-03-04 14:34:39 +00:00
/// Valid only if keyState is found or expired
inline size_t getFetchedColumnIndex() const { return fetched_column_index; }
private:
State state = not_found;
size_t fetched_column_index = 0;
bool is_default = false;
};
2021-02-17 11:48:06 +00:00
/// Result of fetch from CacheDictionaryStorage
2021-02-16 21:33:02 +00:00
template <typename KeyType>
struct KeysStorageFetchResult
{
2021-02-17 11:48:06 +00:00
/// Fetched column values
2021-02-16 21:33:02 +00:00
MutableColumns fetched_columns;
PaddedPODArray<KeyState> key_index_to_state;
2021-02-16 21:33:02 +00:00
size_t expired_keys_size = 0;
2021-02-16 21:33:02 +00:00
size_t found_keys_size = 0;
2021-02-16 21:33:02 +00:00
size_t not_found_keys_size = 0;
2021-02-16 21:33:02 +00:00
size_t default_keys_size = 0;
2021-02-16 21:33:02 +00:00
};
using SimpleKeysStorageFetchResult = KeysStorageFetchResult<UInt64>;
using ComplexKeysStorageFetchResult = KeysStorageFetchResult<StringRef>;
class ICacheDictionaryStorage
{
public:
virtual ~ICacheDictionaryStorage() = default;
2021-02-17 11:48:06 +00:00
/// Necessary if all keys are found we can return result to client without additional aggregation
virtual bool returnsFetchedColumnsInOrderOfRequestedKeys() const = 0;
2021-02-17 11:48:06 +00:00
2021-03-17 17:14:36 +00:00
virtual bool canPerformFetchByMultipleThreadsWithoutLock() const = 0;
/// Name of storage
virtual String getName() const = 0;
2021-02-17 11:48:06 +00:00
/// Does storage support simple keys
2021-02-16 21:33:02 +00:00
virtual bool supportsSimpleKeys() const = 0;
2021-02-17 11:48:06 +00:00
/// Fetch columns for keys, this method is not write thread safe
2021-02-16 21:33:02 +00:00
virtual SimpleKeysStorageFetchResult fetchColumnsForKeys(
const PaddedPODArray<UInt64> & keys,
2021-02-17 11:48:06 +00:00
const DictionaryStorageFetchRequest & fetch_request) = 0;
2021-02-16 21:33:02 +00:00
2021-02-17 11:48:06 +00:00
/// Fetch columns for keys, this method is not write thread safe
2021-02-16 21:33:02 +00:00
virtual void insertColumnsForKeys(const PaddedPODArray<UInt64> & keys, Columns columns) = 0;
/// Insert default keys
virtual void insertDefaultKeys(const PaddedPODArray<UInt64> & keys) = 0;
2021-02-17 11:48:06 +00:00
/// Return cached simple keys
2021-02-16 21:33:02 +00:00
virtual PaddedPODArray<UInt64> getCachedSimpleKeys() const = 0;
2021-02-17 11:48:06 +00:00
/// Does storage support complex keys
2021-02-16 21:33:02 +00:00
virtual bool supportsComplexKeys() const = 0;
2021-02-17 11:48:06 +00:00
/// Fetch columns for keys, this method is not write thread safe
2021-02-16 21:33:02 +00:00
virtual ComplexKeysStorageFetchResult fetchColumnsForKeys(
const PaddedPODArray<StringRef> & keys,
2021-02-17 11:48:06 +00:00
const DictionaryStorageFetchRequest & column_fetch_requests) = 0;
2021-02-16 21:33:02 +00:00
2021-02-17 11:48:06 +00:00
/// Fetch columns for keys, this method is not write thread safe
2021-02-16 21:33:02 +00:00
virtual void insertColumnsForKeys(const PaddedPODArray<StringRef> & keys, Columns columns) = 0;
/// Insert default keys
virtual void insertDefaultKeys(const PaddedPODArray<StringRef> & keys) = 0;
2021-02-17 11:48:06 +00:00
/// Return cached simple keys
2021-02-16 21:33:02 +00:00
virtual PaddedPODArray<StringRef> getCachedComplexKeys() const = 0;
2021-02-17 11:48:06 +00:00
/// Return size of keys in storage
2021-02-16 21:33:02 +00:00
virtual size_t getSize() const = 0;
/// Return maximum size of keys in storage
virtual size_t getMaxSize() const = 0;
2021-02-17 11:48:06 +00:00
/// Return bytes allocated in storage
2021-02-16 21:33:02 +00:00
virtual size_t getBytesAllocated() const = 0;
};
using CacheDictionaryStoragePtr = std::shared_ptr<ICacheDictionaryStorage>;
}