Skip to content

Commit

Permalink
read seq value from pk index
Browse files Browse the repository at this point in the history
  • Loading branch information
bobhan1 committed Oct 5, 2024
1 parent 46007c5 commit 3a81b1e
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 147 deletions.
5 changes: 3 additions & 2 deletions be/src/olap/base_tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ Status BaseTablet::lookup_row_key(const Slice& encoded_key, TabletSchema* latest
const std::vector<RowsetSharedPtr>& specified_rowsets,
RowLocation* row_location, uint32_t version,
std::vector<std::unique_ptr<SegmentCacheHandle>>& segment_caches,
RowsetSharedPtr* rowset, bool with_rowid) {
RowsetSharedPtr* rowset, bool with_rowid,
std::string* encoded_seq_value) {
SCOPED_BVAR_LATENCY(g_tablet_lookup_rowkey_latency);
size_t seq_col_length = 0;
// use the latest tablet schema to decide if the tablet has sequence column currently
Expand Down Expand Up @@ -489,7 +490,7 @@ Status BaseTablet::lookup_row_key(const Slice& encoded_key, TabletSchema* latest

for (auto id : picked_segments) {
Status s = segments[id]->lookup_row_key(encoded_key, schema, with_seq_col, with_rowid,
&loc);
&loc, encoded_seq_value);
if (s.is<KEY_NOT_FOUND>()) {
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion be/src/olap/base_tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class BaseTablet {
const std::vector<RowsetSharedPtr>& specified_rowsets,
RowLocation* row_location, uint32_t version,
std::vector<std::unique_ptr<SegmentCacheHandle>>& segment_caches,
RowsetSharedPtr* rowset = nullptr, bool with_rowid = true);
RowsetSharedPtr* rowset = nullptr, bool with_rowid = true,
std::string* encoded_seq_value = nullptr);

// calc delete bitmap when flush memtable, use a fake version to calc
// For example, cur max version is 5, and we use version 6 to calc but
Expand Down
14 changes: 13 additions & 1 deletion be/src/olap/rowset/segment_v2/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,8 @@ Status Segment::new_inverted_index_iterator(const TabletColumn& tablet_column,
}

Status Segment::lookup_row_key(const Slice& key, const TabletSchema* latest_schema,
bool with_seq_col, bool with_rowid, RowLocation* row_location) {
bool with_seq_col, bool with_rowid, RowLocation* row_location,
std::string* encoded_seq_value) {
RETURN_IF_ERROR(load_pk_index_and_bf());
bool has_seq_col = latest_schema->has_sequence_col();
bool has_rowid = !latest_schema->cluster_key_idxes().empty();
Expand Down Expand Up @@ -970,6 +971,7 @@ Status Segment::lookup_row_key(const Slice& key, const TabletSchema* latest_sche
Slice sought_key_without_seq = Slice(
sought_key.get_data(),
sought_key.get_size() - (segment_has_seq_col ? seq_col_length : 0) - rowid_length);

if (has_seq_col) {
// compare key
if (key_without_seq.compare(sought_key_without_seq) != 0) {
Expand Down Expand Up @@ -1007,6 +1009,16 @@ Status Segment::lookup_row_key(const Slice& key, const TabletSchema* latest_sche
(uint8_t*)&row_location->row_id));
}

if (encoded_seq_value) {
if (!segment_has_seq_col) {
*encoded_seq_value = std::string {};
} else {
// include marker
Slice encoded_seq_value_slice = Slice(
sought_key.get_data() + sought_key_without_seq.get_size(), seq_col_length);
*encoded_seq_value = encoded_seq_value_slice.to_string();
}
}
return Status::OK();
}

Expand Down
3 changes: 2 additions & 1 deletion be/src/olap/rowset/segment_v2/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class Segment : public std::enable_shared_from_this<Segment> {
}

Status lookup_row_key(const Slice& key, const TabletSchema* latest_schema, bool with_seq_col,
bool with_rowid, RowLocation* row_location);
bool with_rowid, RowLocation* row_location,
std::string* encoded_seq_value = nullptr);

Status read_key_by_rowid(uint32_t row_id, std::string* key);

Expand Down
18 changes: 7 additions & 11 deletions be/src/olap/rowset/segment_v2/segment_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,6 @@ Status SegmentWriter::append_block_with_flexible_partial_content(const vectorize
int32_t seq_map_col_unique_id = _opts.rowset_ctx->partial_update_info->sequence_map_col_uid();
bool schema_has_sequence_col = _tablet_schema->has_sequence_col();

const auto* delete_sign_column_data =
BaseTablet::get_delete_sign_column_data(*block, row_pos + num_rows);
DCHECK(delete_sign_column_data != nullptr);
int32_t delete_sign_col_unique_id =
_tablet_schema->column(_tablet_schema->delete_sign_idx()).unique_id();

DBUG_EXECUTE_IF("VerticalSegmentWriter._append_block_with_flexible_partial_content.sleep",
{ sleep(60); })
const std::vector<RowsetSharedPtr>& specified_rowsets = _mow_context->rowset_ptrs;
Expand Down Expand Up @@ -760,7 +754,7 @@ Status SegmentWriter::append_block_with_flexible_partial_content(const vectorize
key_columns, specified_rowsets,
segment_caches));
if (origin_rows != num_rows) {
// data in block has changed, should re-encode key columns and re-get skip_bitmaps and delete_sign_column_data
// data in block has changed, should re-encode key columns and re-get skip_bitmaps
_olap_data_convertor->clear_source_content();
key_columns.clear();
for (std::size_t cid {0}; cid < _num_sort_key_columns; cid++) {
Expand All @@ -778,13 +772,15 @@ Status SegmentWriter::append_block_with_flexible_partial_content(const vectorize
.column->assume_mutable()
.get())
->get_data());

delete_sign_column_data =
BaseTablet::get_delete_sign_column_data(*block, row_pos + num_rows);
DCHECK(delete_sign_column_data != nullptr);
}
}

const auto* delete_sign_column_data =
BaseTablet::get_delete_sign_column_data(*block, row_pos + num_rows);
DCHECK(delete_sign_column_data != nullptr);
int32_t delete_sign_col_unique_id =
_tablet_schema->column(_tablet_schema->delete_sign_idx()).unique_id();

// write key columns data
for (std::size_t cid {0}; cid < _num_sort_key_columns; cid++) {
const auto& column = key_columns[cid];
Expand Down
Loading

0 comments on commit 3a81b1e

Please sign in to comment.