Skip to content
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

Discussion: add update_time column to source state table #13437

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/frontend/src/optimizer/plan_node/generic/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,16 @@ impl Source {
sub_fields: vec![],
type_name: "".to_string(),
};
let update_time = Field {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this affect the schema of the already created source/table? Is this change backward-compatible?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, I suggest we add the update time field in the json.

Copy link
Contributor Author

@StrikeW StrikeW Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr won't merge, yesterday we found that debezium can capture the event time on upstream, so we decide to generate a (process_time - event_time) metric to promethues as an indication of lagging. FYI
#13440

data_type: DataType::Timestamptz,
name: "update_time".to_string(),
sub_fields: vec![],
type_name: "".to_string(),
};

let ordered_col_idx = builder.add_column(&key);
builder.add_column(&value);
builder.add_column(&update_time);
builder.add_order_column(ordered_col_idx, OrderType::ascending());

builder.build(vec![], 1)
Expand Down
4 changes: 4 additions & 0 deletions src/stream/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ async-trait = "0.1"
auto_enums = "0.8"
await-tree = { workspace = true }
bytes = "1"
chrono = { version = "0.4", default-features = false, features = [
"clock",
"std",
] }
educe = "0.4"
either = "1"
enum-as-inner = "0.6"
Expand Down
6 changes: 5 additions & 1 deletion src/stream/src/executor/source/state_table_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ use std::collections::HashSet;
use std::ops::{Bound, Deref};
use std::sync::Arc;

use chrono::Utc;
use futures::{pin_mut, StreamExt};
use risingwave_common::buffer::Bitmap;
use risingwave_common::catalog::{DatabaseId, SchemaId};
use risingwave_common::constants::hummock::PROPERTIES_RETENTION_SECOND_KEY;
use risingwave_common::hash::VirtualNode;
use risingwave_common::row::{OwnedRow, Row};
use risingwave_common::types::{JsonbVal, ScalarImpl, ScalarRef, ScalarRefImpl};
use risingwave_common::types::{JsonbVal, ScalarImpl, ScalarRef, ScalarRefImpl, Timestamptz};
use risingwave_common::util::epoch::EpochPair;
use risingwave_common::{bail, row};
use risingwave_connector::source::{SplitId, SplitImpl, SplitMetaData};
Expand Down Expand Up @@ -158,9 +159,11 @@ impl<S: StateStore> SourceStateTableHandler<S> {
}

pub async fn set(&mut self, key: SplitId, value: JsonbVal) -> StreamExecutorResult<()> {
let update_time = Timestamptz::from_micros(Utc::now().timestamp_micros());
let row = [
Some(Self::string_to_scalar(key.deref())),
Some(ScalarImpl::Jsonb(value)),
Some(update_time.into()),
];
match self.get(key).await? {
Some(prev_row) => {
Expand Down Expand Up @@ -277,6 +280,7 @@ pub fn default_source_internal_table(id: u32) -> PbTable {
let columns = vec![
make_column(TypeName::Varchar, 0),
make_column(TypeName::Jsonb, 1),
make_column(TypeName::Timestamptz, 2),
];
PbTable {
id,
Expand Down
Loading