gavinchou commented on code in PR #59754:
URL: https://github.com/apache/doris/pull/59754#discussion_r2705427979
##########
be/src/cloud/cloud_tablet.cpp:
##########
@@ -1736,5 +1738,177 @@ void CloudTablet::add_warmed_up_rowset(const RowsetId&
rowset_id) {
.start_tp = std::chrono::steady_clock::now()};
}
+void CloudTablet::clear_unused_visible_pending_rowsets() {
+ int64_t cur_max_version = max_version().second;
+ int32_t max_version_count = max_version_config();
+ int64_t current_time = std::chrono::duration_cast<std::chrono::seconds>(
+
std::chrono::system_clock::now().time_since_epoch())
+ .count();
+ {
+ std::unique_lock<std::mutex> wlock(_visible_pending_rs_lock);
+ for (auto it = _visible_pending_rs_map.begin(); it !=
_visible_pending_rs_map.end();) {
+ if (int64_t version = it->first, expiration_time =
it->second.expiration_time;
+ version <= cur_max_version || expiration_time < current_time) {
+ it = _visible_pending_rs_map.erase(it);
+ } else {
+ ++it;
+ }
+ }
+
+ while (!_visible_pending_rs_map.empty() &&
+ _visible_pending_rs_map.size() > max_version_count) {
+ _visible_pending_rs_map.erase(--_visible_pending_rs_map.end());
+ }
+ }
+}
+
+void CloudTablet::try_make_committed_rs_visible(int64_t txn_id, int64_t
visible_version,
+ int64_t
version_update_time_ms) {
+ if (enable_unique_key_merge_on_write()) {
+ try_make_committed_rs_visible_for_mow(txn_id, visible_version,
version_update_time_ms);
+ } else {
+ auto& committed_rs_mgr = _engine.committed_rs_mgr();
+ auto res = committed_rs_mgr.get_committed_rowset(txn_id, tablet_id());
+ if (!res.has_value()) {
+ return;
+ }
+ auto [rowset_meta, expiration_time] = res.value();
+ bool is_empty_rowset = (rowset_meta == nullptr);
+ if (!is_empty_rowset) {
+ rowset_meta->set_cloud_fields_after_visible(visible_version,
version_update_time_ms);
+ }
+ {
+ std::lock_guard<std::mutex> lock(_visible_pending_rs_lock);
+ _visible_pending_rs_map.emplace(
+ visible_version,
+ VisiblePendingRowset {rowset_meta, expiration_time,
is_empty_rowset});
+ }
+
+ apply_visible_pending_rowsets();
+ committed_rs_mgr.remove_committed_rowset(txn_id, tablet_id());
+ }
+}
+
+void CloudTablet::try_make_committed_rs_visible_for_mow(int64_t txn_id,
int64_t visible_version,
+ int64_t
version_update_time_ms) {
+ Defer defer {[&] {
+
_engine.txn_delete_bitmap_cache().remove_unused_tablet_txn_info(txn_id,
tablet_id());
+ }};
+ auto res =
_engine.txn_delete_bitmap_cache().get_rowset_and_delete_bitmap(txn_id,
tablet_id());
+ if (!res.has_value()) {
+ return;
+ }
+ auto [rowset, delete_bitmap] = res.value();
+ bool is_empty_rowset = (rowset == nullptr);
+ {
+ std::unique_lock lock {_sync_meta_lock};
+ std::unique_lock meta_wlock {_meta_lock};
+ if (_max_version + 1 != visible_version) {
+ return;
+ }
+ if (is_empty_rowset) {
+ Versions existing_versions;
+ for (const auto& [_, rs] : tablet_meta()->all_rs_metas()) {
+ existing_versions.emplace_back(rs->version());
+ }
+ if (existing_versions.empty()) {
+ return;
+ }
+ auto max_version = std::ranges::max(existing_versions, {},
&Version::first);
+ auto prev_rowset = get_rowset_by_version(max_version);
+ auto st = _engine.meta_mgr().create_empty_rowset_for_hole(
+ this, visible_version, prev_rowset->rowset_meta(),
&rowset);
+ if (!st.ok()) {
+ return;
+ }
+ } else {
+ for (const auto& [delete_bitmap_key, bitmap_value] :
delete_bitmap->delete_bitmap) {
+ // skip sentinel mark, which is used for delete bitmap
correctness check
+ if (std::get<1>(delete_bitmap_key) !=
DeleteBitmap::INVALID_SEGMENT_ID) {
+ tablet_meta()->delete_bitmap().merge(
+ {std::get<0>(delete_bitmap_key),
std::get<1>(delete_bitmap_key),
+ visible_version},
+ bitmap_value);
+ }
+ }
+ }
+ rowset->rowset_meta()->set_cloud_fields_after_visible(visible_version,
+
version_update_time_ms);
+ add_rowsets({rowset}, false, meta_wlock, true);
+ }
+ LOG(INFO) << "mow added visible pending rowset, txn_id=" << txn_id
+ << ", tablet_id=" << tablet_id() << ", version=" <<
visible_version
+ << ", rowset_id=" << rowset->rowset_id().to_string();
+}
+
+void CloudTablet::apply_visible_pending_rowsets() {
+ Defer defer {[&] { clear_unused_visible_pending_rowsets(); }};
+ {
+ std::unique_lock lock(_sync_meta_lock);
+ std::unique_lock<std::shared_mutex> meta_wlock(_meta_lock);
+ int64_t next_version = _max_version + 1;
+ std::vector<RowsetSharedPtr> to_add;
+ std::lock_guard<std::mutex> pending_lock(_visible_pending_rs_lock);
+ for (auto it = _visible_pending_rs_map.upper_bound(_max_version);
+ it != _visible_pending_rs_map.end(); ++it) {
+ if (int64_t version = it->first; version == next_version) {
Review Comment:
```suggestion
if (!(int64_t version = it->first; version == next_version))
break;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]