-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[improvement](compaction) be do not compact invisible version to avoid query error -230 #28082
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#include <gen_cpp/Types_types.h> | ||
#include <netinet/in.h> | ||
|
||
#include <atomic> | ||
#include <charconv> | ||
#include <cstdint> | ||
#include <functional> | ||
|
@@ -36,6 +37,7 @@ | |
#include "io/io_common.h" | ||
#include "olap/olap_define.h" | ||
#include "util/hash_util.hpp" | ||
#include "util/time.h" | ||
#include "util/uid_util.h" | ||
|
||
namespace doris { | ||
|
@@ -509,6 +511,25 @@ struct RidAndPos { | |
|
||
using PartialUpdateReadPlan = std::map<RowsetId, std::map<uint32_t, std::vector<RidAndPos>>>; | ||
|
||
// used for controll compaction | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. control |
||
struct VersionWithTime { | ||
std::atomic<int64_t> version; | ||
int64_t update_ts; | ||
|
||
VersionWithTime() : version(0), update_ts(MonotonicMillis()) {} | ||
|
||
void update_version_monoto(int64_t new_version) { | ||
int64_t cur_version = version.load(std::memory_order_relaxed); | ||
while (cur_version < new_version) { | ||
if (version.compare_exchange_strong(cur_version, new_version, std::memory_order_relaxed, | ||
std::memory_order_relaxed)) { | ||
update_ts = MonotonicMillis(); | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
} // namespace doris | ||
|
||
// This intended to be a "good" hash function. It may change from time to time. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1074,25 +1074,41 @@ std::vector<RowsetSharedPtr> Tablet::pick_candidate_rowsets_to_cumulative_compac | |
if (_cumulative_point == K_INVALID_CUMULATIVE_POINT) { | ||
return candidate_rowsets; | ||
} | ||
{ | ||
std::shared_lock rlock(_meta_lock); | ||
for (const auto& [version, rs] : _rs_version_map) { | ||
if (version.first >= _cumulative_point && rs->is_local()) { | ||
candidate_rowsets.push_back(rs); | ||
} | ||
} | ||
} | ||
std::sort(candidate_rowsets.begin(), candidate_rowsets.end(), Rowset::comparator); | ||
return candidate_rowsets; | ||
return _pick_visible_rowsets_to_compaction(_cumulative_point, | ||
std::numeric_limits<int64_t>::max()); | ||
} | ||
|
||
std::vector<RowsetSharedPtr> Tablet::pick_candidate_rowsets_to_base_compaction() { | ||
return _pick_visible_rowsets_to_compaction(std::numeric_limits<int64_t>::min(), | ||
_cumulative_point - 1); | ||
} | ||
|
||
std::vector<RowsetSharedPtr> Tablet::_pick_visible_rowsets_to_compaction( | ||
int64_t min_start_version, int64_t max_start_version) { | ||
auto [visible_version, update_ts] = get_visible_version_and_time(); | ||
bool update_time_long = MonotonicMillis() - update_ts > | ||
config::compaction_keep_invisible_version_timeout_sec * 1000L; | ||
int32_t keep_invisible_version_limit = | ||
update_time_long ? config::compaction_keep_invisible_version_min_count | ||
: config::compaction_keep_invisible_version_max_count; | ||
|
||
std::vector<RowsetSharedPtr> candidate_rowsets; | ||
{ | ||
std::shared_lock rlock(_meta_lock); | ||
for (const auto& [version, rs] : _rs_version_map) { | ||
// Do compaction on local rowsets only. | ||
if (version.first < _cumulative_point && rs->is_local()) { | ||
int64_t version_start = version.first; | ||
// rowset is remote or rowset is not in given range | ||
if (!rs->is_local() || version_start < min_start_version || | ||
version_start > max_start_version) { | ||
continue; | ||
} | ||
|
||
// can compact, met one of the conditions: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. meet? |
||
// 1. had been visible; | ||
// 2. exceeds the limit of keep invisible versions. | ||
int64_t version_end = version.second; | ||
if (version_end <= visible_version || | ||
version_end > visible_version + keep_invisible_version_limit) { | ||
candidate_rowsets.push_back(rs); | ||
} | ||
} | ||
|
@@ -1115,13 +1131,8 @@ std::vector<RowsetSharedPtr> Tablet::pick_candidate_rowsets_to_full_compaction() | |
|
||
std::vector<RowsetSharedPtr> Tablet::pick_first_consecutive_empty_rowsets(int limit) { | ||
std::vector<RowsetSharedPtr> consecutive_empty_rowsets; | ||
std::vector<RowsetSharedPtr> candidate_rowsets; | ||
traverse_rowsets([&candidate_rowsets, this](const auto& rs) { | ||
if (rs->is_local() && rs->start_version() >= _cumulative_point) { | ||
candidate_rowsets.emplace_back(rs); | ||
} | ||
}); | ||
std::sort(candidate_rowsets.begin(), candidate_rowsets.end(), Rowset::comparator); | ||
std::vector<RowsetSharedPtr> candidate_rowsets = | ||
pick_candidate_rowsets_to_cumulative_compaction(); | ||
int len = candidate_rowsets.size(); | ||
for (int i = 0; i < len - 1; ++i) { | ||
auto rowset = candidate_rowsets[i]; | ||
|
@@ -1190,6 +1201,19 @@ std::vector<RowsetSharedPtr> Tablet::pick_candidate_rowsets_to_build_inverted_in | |
return candidate_rowsets; | ||
} | ||
|
||
std::tuple<int64_t, int64_t> Tablet::get_visible_version_and_time() const { | ||
// some old tablet has bug, its partition_id is 0, fe couldn't update its visible version. | ||
// so let this tablet's visible version become int64 max. | ||
auto version_info = std::atomic_load_explicit(&_visible_version, std::memory_order_relaxed); | ||
if (version_info != nullptr && partition_id() != 0) { | ||
return std::make_tuple(version_info->version.load(std::memory_order_relaxed), | ||
version_info->update_ts); | ||
} else { | ||
return std::make_tuple(std::numeric_limits<int64_t>::max(), | ||
std::numeric_limits<int64_t>::max()); | ||
} | ||
} | ||
|
||
// For http compaction action | ||
void Tablet::get_compaction_status(std::string* json_result) { | ||
rapidjson::Document root; | ||
|
@@ -1526,13 +1550,23 @@ void Tablet::build_tablet_report_info(TTabletInfo* tablet_info, | |
} | ||
}); | ||
|
||
int64_t total_version_count = _tablet_meta->version_count(); | ||
|
||
// For compatibility. | ||
// For old fe, it wouldn't send visible version request to be, then be's visible version is always 0. | ||
// Let visible_version_count set to total_version_count in be's report. | ||
int64_t visible_version_count = total_version_count; | ||
if (auto [visible_version, _] = get_visible_version_and_time(); visible_version > 0) { | ||
visible_version_count = _tablet_meta->version_count_cross_with_range({0, visible_version}); | ||
} | ||
// the report version is the largest continuous version, same logic as in FE side | ||
tablet_info->__set_version(cversion.second); | ||
// Useless but it is a required filed in TTabletInfo | ||
tablet_info->__set_version_hash(0); | ||
tablet_info->__set_partition_id(_tablet_meta->partition_id()); | ||
tablet_info->__set_storage_medium(_data_dir->storage_medium()); | ||
tablet_info->__set_version_count(_tablet_meta->version_count()); | ||
tablet_info->__set_total_version_count(total_version_count); | ||
tablet_info->__set_visible_version_count(visible_version_count); | ||
tablet_info->__set_path_hash(_data_dir->path_hash()); | ||
tablet_info->__set_is_in_memory(_tablet_meta->tablet_schema()->is_in_memory()); | ||
tablet_info->__set_replica_id(replica_id()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'gen_cpp/Types_types.h' file not found [clang-diagnostic-error]