Copilot commented on code in PR #62457:
URL: https://github.com/apache/doris/pull/62457#discussion_r3074207300
##########
be/src/storage/rowset/rowset_meta.h:
##########
@@ -355,7 +361,11 @@ class RowsetMeta : public MetadataAdder<RowsetMeta> {
_rowset_meta_pb.set_segments_key_bounds_truncated(truncated);
}
- bool get_first_segment_key_bound(KeyBoundsPB* key_bounds) {
+ bool get_first_segment_key_bound(KeyBoundsPB* key_bounds) const {
+ if (_rowset_meta_pb.has_rowset_key_bounds()) {
+ *key_bounds = _rowset_meta_pb.rowset_key_bounds();
+ return true;
+ }
Review Comment:
`get_first_segment_key_bound` / `get_last_segment_key_bound` now return the
full `rowset_key_bounds` when present. That changes the meaning of the returned
`KeyBoundsPB`: the “first segment bound” will carry the *rowset* max key (not
the first segment’s max), and the “last segment bound” will carry the *rowset*
min key (not the last segment’s min). If any caller relies on both min/max
being the segment’s range (not just one side), this will yield incorrect
results. Consider either (a) keeping these APIs strictly “segment” by only
setting the relevant side (first: min + first-segment max if available; last:
last-segment min + max), or (b) introducing a separate
`get_rowset_key_bounds()` and leaving the segment APIs to consult
`segments_key_bounds` only.
##########
be/src/storage/rowset/rowset_meta.h:
##########
@@ -364,7 +374,11 @@ class RowsetMeta : public MetadataAdder<RowsetMeta> {
return true;
}
- bool get_last_segment_key_bound(KeyBoundsPB* key_bounds) {
+ bool get_last_segment_key_bound(KeyBoundsPB* key_bounds) const {
+ if (_rowset_meta_pb.has_rowset_key_bounds()) {
+ *key_bounds = _rowset_meta_pb.rowset_key_bounds();
+ return true;
+ }
Review Comment:
`get_first_segment_key_bound` / `get_last_segment_key_bound` now return the
full `rowset_key_bounds` when present. That changes the meaning of the returned
`KeyBoundsPB`: the “first segment bound” will carry the *rowset* max key (not
the first segment’s max), and the “last segment bound” will carry the *rowset*
min key (not the last segment’s min). If any caller relies on both min/max
being the segment’s range (not just one side), this will yield incorrect
results. Consider either (a) keeping these APIs strictly “segment” by only
setting the relevant side (first: min + first-segment max if available; last:
last-segment min + max), or (b) introducing a separate
`get_rowset_key_bounds()` and leaving the segment APIs to consult
`segments_key_bounds` only.
##########
be/src/storage/rowset/beta_rowset_writer.cpp:
##########
@@ -782,7 +787,21 @@ Status BaseBetaRowsetWriter::add_rowset(RowsetSharedPtr
rowset) {
// append key_bounds to current rowset
RETURN_IF_ERROR(rowset->get_segments_key_bounds(&_segments_encoded_key_bounds));
rowset->get_num_segment_rows(&_segment_num_rows);
- _segments_key_bounds_truncated =
rowset->rowset_meta()->is_segments_key_bounds_truncated();
+ _segments_key_bounds_truncated =
+ _segments_key_bounds_truncated.value_or(false) ||
+ rowset->rowset_meta()->is_segments_key_bounds_truncated();
+ std::string first_key;
+ bool has_first_key = rowset->first_key(&first_key);
+ std::string last_key;
+ bool has_last_key = rowset->last_key(&last_key);
+ DCHECK_EQ(has_first_key, has_last_key);
+ if (has_first_key) {
+ if (!_rowset_key_bounds.has_value()) {
+ _rowset_key_bounds.emplace();
+ _rowset_key_bounds->set_min_key(first_key);
+ }
+ _rowset_key_bounds->set_max_key(last_key);
+ }
Review Comment:
`rowset->first_key()` / `rowset->last_key()` may involve extra work
(depending on implementation) even though the metadata paths now carry
`rowset_key_bounds` / `segments_key_bounds`. Since you only need rowset-level
min/max here, consider reading from `rowset->rowset_meta()` (e.g.,
`rowset_meta->rowset_key_bounds()` when present, or
`get_first_segment_key_bound`/`get_last_segment_key_bound`) to avoid any
potential segment/index reads during `add_rowset()`.
##########
be/src/storage/rowset/rowset_meta.cpp:
##########
@@ -291,29 +329,31 @@ int64_t RowsetMeta::segment_file_size(int seg_id) const {
: -1;
}
+void RowsetMeta::set_rowset_key_bounds(const KeyBoundsPB& rowset_key_bounds) {
+ *_rowset_meta_pb.mutable_rowset_key_bounds() = rowset_key_bounds;
+ bool really_do_truncation =
truncate_key_bounds(_rowset_meta_pb.mutable_rowset_key_bounds(),
+
get_segments_key_bounds_truncation_threshold());
+ set_segments_key_bounds_truncated(really_do_truncation ||
is_segments_key_bounds_truncated());
+}
+
void RowsetMeta::set_segments_key_bounds(const std::vector<KeyBoundsPB>&
segments_key_bounds) {
+ if (!segments_key_bounds.empty()) {
+ *_rowset_meta_pb.mutable_rowset_key_bounds() =
build_rowset_key_bounds(segments_key_bounds);
+ }
Review Comment:
This unconditionally persists `rowset_key_bounds` whenever
`set_segments_key_bounds()` is called, including when
`config::enable_rowset_key_bounds_for_non_mow` is `false`. The PR description
states “non-MoW rowsets can persist rowset-level key bounds only when
enable_rowset_key_bounds_for_non_mow is set to true”. If the intent is truly
“only persist `rowset_key_bounds` behind the gate”, then this needs to be
guarded (or moved to the gated write path). If the intent is “only omit
per-segment bounds behind the gate (but always persist rowset-level bounds when
available)”, then the PR description (and any related comments) should be
updated to match the actual behavior.
--
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]