Change cumulative compaction for decoupling storage from compution (#1576)

1. Calculate cumulative point when loading tablet first time.
2. Simplify pick rowsets logic upon delete predicate.
3. Saving meta and modify rowsets only once after cumulative compaction.
This commit is contained in:
lichaoyong
2019-08-13 18:25:56 +08:00
committed by ZHAO Chun
parent 582c313190
commit dcb75729db
19 changed files with 617 additions and 1356 deletions

View File

@ -150,6 +150,8 @@ OLAPStatus Tablet::init_once() {
_inc_rs_version_map[version] = rowset;
}
_cumulative_point = -1;
return res;
}
@ -670,6 +672,17 @@ OLAPStatus Tablet::compute_all_versions_hash(const vector<Version>& versions,
return OLAP_SUCCESS;
}
void Tablet::compute_version_hash_from_rowsets(
const std::vector<RowsetSharedPtr>& rowsets, VersionHash* version_hash) const {
DCHECK(version_hash != nullptr) << "invalid parameter, version_hash is nullptr";
int64_t v_hash = 0;
for (auto& rowset : rowsets) {
v_hash ^= rowset->version_hash();
}
*version_hash = v_hash;
}
void Tablet::calc_missed_versions(int64_t spec_version,
vector<Version>* missed_versions) {
ReadLock rdlock(&_meta_lock);
@ -736,6 +749,38 @@ OLAPStatus Tablet::max_continuous_version_from_begining(Version* version, Versio
return OLAP_SUCCESS;
}
OLAPStatus Tablet::calculate_cumulative_point() {
WriteLock wrlock(&_meta_lock);
if (_cumulative_point != -1) {
return OLAP_SUCCESS;
}
std::list<Version> existing_versions;
for (auto& rs : _tablet_meta->all_rs_metas()) {
existing_versions.emplace_back(rs->version());
}
// sort the existing versions in ascending order
existing_versions.sort([](const Version& a, const Version& b) {
// simple because 2 versions are certainly not overlapping
return a.first < b.first;
});
int64_t prev_version = -1;
for (const Version& version : existing_versions) {
if (version.first > prev_version + 1) {
break;
}
if (version.first == version.second) {
_cumulative_point = version.first;
break;
}
prev_version = version.second;
_cumulative_point = version.second + 1;
}
return OLAP_SUCCESS;
}
OLAPStatus Tablet::split_range(
const OlapTuple& start_key_strings,
const OlapTuple& end_key_strings,
@ -937,4 +982,23 @@ TabletInfo Tablet::get_tablet_info() {
return TabletInfo(tablet_id(), schema_hash(), tablet_uid());
}
void Tablet::pick_candicate_rowsets_to_cumulative_compaction(std::vector<RowsetSharedPtr>* candidate_rowsets) {
ReadLock rdlock(&_meta_lock);
for (auto& it : _rs_version_map) {
if (it.first.first >= _cumulative_point
&& it.first.first == it.first.second) {
candidate_rowsets->push_back(it.second);
}
}
}
void Tablet::pick_candicate_rowsets_to_base_compaction(std::vector<RowsetSharedPtr>* candidate_rowsets) {
ReadLock rdlock(&_meta_lock);
for (auto& it : _rs_version_map) {
if (it.first.first < _cumulative_point) {
candidate_rowsets->push_back(it.second);
}
}
}
} // namespace doris