2014-05-26 10:41:40 +00:00
|
|
|
#pragma once
|
2016-05-28 10:15:36 +00:00
|
|
|
#include <mutex>
|
2015-09-29 19:19:54 +00:00
|
|
|
#include <common/DateLUT.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Types.h>
|
2014-05-26 10:41:40 +00:00
|
|
|
#include <set>
|
|
|
|
|
2017-04-18 20:38:07 +00:00
|
|
|
|
2014-05-26 10:41:40 +00:00
|
|
|
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.
|
2014-05-26 10:41:40 +00:00
|
|
|
*/
|
|
|
|
class ActiveDataPartSet
|
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
ActiveDataPartSet() {}
|
|
|
|
ActiveDataPartSet(const Strings & names);
|
2014-10-10 00:46:37 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
struct Part
|
|
|
|
{
|
|
|
|
DayNum_t left_date;
|
|
|
|
DayNum_t right_date;
|
|
|
|
Int64 left;
|
|
|
|
Int64 right;
|
|
|
|
UInt32 level;
|
2017-05-16 15:40:32 +00:00
|
|
|
String name; /// pure name without prefixes
|
2017-04-01 07:20:54 +00:00
|
|
|
DayNum_t month;
|
2014-05-26 10:41:40 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool operator<(const Part & rhs) const
|
|
|
|
{
|
2017-05-23 01:09:47 +00:00
|
|
|
return std::tie(month, left, right, level) < std::tie(rhs.month, rhs.left, rhs.right, rhs.level);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2014-05-26 10:41:40 +00:00
|
|
|
|
2017-05-23 01:09:47 +00:00
|
|
|
/// Contains another part (obtained after merging another part with some other)
|
2017-04-01 07:20:54 +00:00
|
|
|
bool contains(const Part & rhs) const
|
|
|
|
{
|
2017-05-23 01:09:47 +00:00
|
|
|
return month == rhs.month /// Parts for different months are not merged
|
2017-04-01 07:20:54 +00:00
|
|
|
&& left <= rhs.left
|
|
|
|
&& right >= rhs.right
|
|
|
|
&& level >= rhs.level;
|
|
|
|
}
|
|
|
|
};
|
2014-05-26 10:41:40 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void add(const String & name);
|
2014-10-13 17:28:59 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// If not found, returns an empty string.
|
2017-04-01 07:20:54 +00:00
|
|
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t size() const;
|
2014-05-26 10:41:40 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static String getPartName(DayNum_t left_date, DayNum_t right_date, Int64 left_id, Int64 right_id, UInt64 level);
|
2014-05-26 10:41:40 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Returns true if the directory name matches the format of the directory name of the parts
|
2017-04-18 20:38:07 +00:00
|
|
|
static bool isPartDirectory(const String & dir_name);
|
|
|
|
|
|
|
|
static bool parsePartNameImpl(const String & dir_name, Part * part);
|
2014-05-26 10:41:40 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Put data in DataPart from the name of the part.
|
2017-04-18 20:38:07 +00:00
|
|
|
static void parsePartName(const String & dir_name, Part & part);
|
2014-05-26 10:41:40 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static bool contains(const String & outer_part_name, const String & inner_part_name);
|
2014-07-22 13:49:52 +00:00
|
|
|
|
2014-05-26 10:41:40 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
using Parts = std::set<Part>;
|
2014-05-26 10:41:40 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
mutable std::mutex mutex;
|
|
|
|
Parts parts;
|
2014-10-10 00:46:37 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Do not block mutex.
|
2017-04-01 07:20:54 +00:00
|
|
|
void addImpl(const String & name);
|
|
|
|
String getContainingPartImpl(const String & name) const;
|
2014-05-26 10:41:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|