ClickHouse/dbms/src/Storages/MergeTree/ActiveDataPartSet.h

91 lines
2.7 KiB
C++
Raw Normal View History

#pragma once
#include <mutex>
#include <Poco/RegularExpression.h>
2015-09-29 19:19:54 +00:00
#include <common/DateLUT.h>
#include <Core/Types.h>
#include <set>
namespace DB
{
2017-04-16 15:00:33 +00:00
/** Supports multiple names of active parts of data.
* Repeats part of the MergeTreeData functionality.
* TODO: generalize with MergeTreeData. It is possible to leave this class approximately as is and use it from MergeTreeData.
* Then in MergeTreeData you can make map<String, DataPartPtr> data_parts and all_data_parts.
*/
class ActiveDataPartSet
{
public:
ActiveDataPartSet() {}
ActiveDataPartSet(const Strings & names);
struct Part
{
DayNum_t left_date;
DayNum_t right_date;
Int64 left;
Int64 right;
UInt32 level;
std::string name;
DayNum_t month;
bool operator<(const Part & rhs) const
{
if (month != rhs.month)
return month < rhs.month;
if (left != rhs.left)
return left < rhs.left;
if (right != rhs.right)
return right < rhs.right;
if (level != rhs.level)
return level < rhs.level;
return false;
}
2017-04-16 15:00:33 +00:00
/// Contains another part (obtained after combining another part with some other)
bool contains(const Part & rhs) const
{
2017-04-16 15:00:33 +00:00
return month == rhs.month /// Parts for different months are not combined
&& left_date <= rhs.left_date
&& right_date >= rhs.right_date
&& left <= rhs.left
&& right >= rhs.right
&& level >= rhs.level;
}
};
void add(const String & name);
2017-04-16 15:00:33 +00:00
/// If not found, returns an empty string.
String getContainingPart(const String & name) const;
2014-05-26 18:14:52 +00:00
2017-04-16 15:00:33 +00:00
Strings getParts() const; /// In ascending order of the month and block number.
2014-08-08 08:28:13 +00:00
size_t size() const;
static String getPartName(DayNum_t left_date, DayNum_t right_date, Int64 left_id, Int64 right_id, UInt64 level);
2017-04-16 15:00:33 +00:00
/// Returns true if the directory name matches the format of the directory name of the parts
static bool isPartDirectory(const String & dir_name, Poco::RegularExpression::MatchVec * out_matches = nullptr);
2017-04-16 15:00:33 +00:00
/// Put data in DataPart from the name of the part.
static void parsePartName(const String & file_name, Part & part, const Poco::RegularExpression::MatchVec * matches = nullptr);
static bool contains(const String & outer_part_name, const String & inner_part_name);
2014-07-22 13:49:52 +00:00
private:
using Parts = std::set<Part>;
mutable std::mutex mutex;
Parts parts;
2017-04-16 15:00:33 +00:00
/// Do not block mutex.
void addImpl(const String & name);
String getContainingPartImpl(const String & name) const;
};
}