ClickHouse/src/Storages/MergeTree/PartMetadataManagerWithCache.h

56 lines
1.9 KiB
C++
Raw Normal View History

#pragma once
#include "config.h"
#if USE_ROCKSDB
#include <Storages/MergeTree/IPartMetadataManager.h>
#include <Storages/MergeTree/MergeTreeMetadataCache.h>
namespace DB
{
2022-01-10 03:45:06 +00:00
/// PartMetadataManagerWithCache stores metadatas of part in RocksDB as cache layer to speed up
/// loading process of merge tree table.
class PartMetadataManagerWithCache : public IPartMetadataManager
{
public:
PartMetadataManagerWithCache(const IMergeTreeDataPart * part_, const MergeTreeMetadataCachePtr & cache_);
~PartMetadataManagerWithCache() override = default;
2022-01-10 03:45:06 +00:00
/// First read the metadata from RocksDB cache, then from disk.
2022-05-29 07:28:02 +00:00
std::unique_ptr<ReadBuffer> read(const String & file_name) const override;
2022-01-10 03:45:06 +00:00
/// First judge existence of the metadata in RocksDB cache, then in disk.
bool exists(const String & file_name) const override;
2022-01-10 03:45:06 +00:00
/// Delete all metadatas in part from RocksDB cache.
void deleteAll(bool include_projection) override;
2022-01-10 03:45:06 +00:00
/// Assert all metadatas in part from RocksDB cache are deleted.
void assertAllDeleted(bool include_projection) const override;
2022-01-10 03:45:06 +00:00
/// Update all metadatas in part from RocksDB cache.
/// Need to be called after part directory is renamed.
void updateAll(bool include_projection) override;
2022-01-10 03:45:06 +00:00
/// Check if all metadatas in part from RocksDB cache are up to date.
2022-01-07 10:37:08 +00:00
std::unordered_map<String, uint128> check() const override;
private:
2022-01-10 03:45:06 +00:00
/// Get cache key from path of metadata file.
/// Format: <disk_name>:relative/full/path/of/metadata/file
String getKeyFromFilePath(const String & file_path) const;
2022-01-10 03:45:06 +00:00
/// Get metadata file path from cache key.
String getFilePathFromKey(const String & key) const;
2022-01-10 03:45:06 +00:00
/// Get cache keys and checksums of corresponding metadata in a part(including projection parts)
void getKeysAndCheckSums(Strings & keys, std::vector<uint128> & checksums) const;
MergeTreeMetadataCachePtr cache;
};
}
#endif