Allow empty parts

This commit is contained in:
alesapin 2019-03-26 12:12:48 +03:00
parent c0e29d3fb4
commit bfbe1263ac
2 changed files with 12 additions and 2 deletions

View File

@ -10,6 +10,7 @@ class IndexGranularity
private: private:
std::vector<size_t> marks_to_rows; std::vector<size_t> marks_to_rows;
size_t total_rows = 0; size_t total_rows = 0;
bool initialized = false;
public: public:
IndexGranularity() = default; IndexGranularity() = default;
@ -34,7 +35,15 @@ public:
{ {
return marks_to_rows.empty(); return marks_to_rows.empty();
} }
bool isInitialized() const
{
return initialized;
}
void setInitialized()
{
initialized = true;
}
void appendMark(size_t rows_count); void appendMark(size_t rows_count);
void resizeWithFixedGranularity(size_t size, size_t fixed_granularity); void resizeWithFixedGranularity(size_t size, size_t fixed_granularity);
}; };

View File

@ -519,7 +519,6 @@ void MergeTreeDataPart::loadIndexGranularity()
if (!granularity_info.is_adaptive) if (!granularity_info.is_adaptive)
{ {
std::cerr << "(1)SET MARKS SIZE FOR:" << marks_file_path << " TO:" << granularity_info.mark_size_in_bytes << std::endl; std::cerr << "(1)SET MARKS SIZE FOR:" << marks_file_path << " TO:" << granularity_info.mark_size_in_bytes << std::endl;
/// TODO(alesap) Replace hardcoded numbers to something better
size_t marks_count = marks_file_size / granularity_info.mark_size_in_bytes; size_t marks_count = marks_file_size / granularity_info.mark_size_in_bytes;
std::cerr << "Marks file size:" << marks_file_size << " Marks count:" << marks_count << std::endl; std::cerr << "Marks file size:" << marks_file_size << " Marks count:" << marks_count << std::endl;
index_granularity.resizeWithFixedGranularity(marks_count, granularity_info.fixed_index_granularity); /// all the same index_granularity.resizeWithFixedGranularity(marks_count, granularity_info.fixed_index_granularity); /// all the same
@ -538,11 +537,13 @@ void MergeTreeDataPart::loadIndexGranularity()
if (index_granularity.getMarksCount() * granularity_info.mark_size_in_bytes != marks_file_size) if (index_granularity.getMarksCount() * granularity_info.mark_size_in_bytes != marks_file_size)
throw Exception("Cannot read all marks from file " + marks_file_path, ErrorCodes::CANNOT_READ_ALL_DATA); throw Exception("Cannot read all marks from file " + marks_file_path, ErrorCodes::CANNOT_READ_ALL_DATA);
} }
index_granularity.setInitialized();
} }
void MergeTreeDataPart::loadIndex() void MergeTreeDataPart::loadIndex()
{ {
if (index_granularity.empty()) /// It can be empty in case of mutations
if (!index_granularity.isInitialized())
throw Exception("Index granularity is not loaded before index loading", ErrorCodes::LOGICAL_ERROR); throw Exception("Index granularity is not loaded before index loading", ErrorCodes::LOGICAL_ERROR);
size_t key_size = storage.primary_key_columns.size(); size_t key_size = storage.primary_key_columns.size();