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

fix: catch potential overflow #25123

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Next Next commit
fix: catch potential overflow
LorrensP-2158466 committed Jul 2, 2024
commit 3ce50759271b79903fa42be99d0802194214bcb9
10 changes: 5 additions & 5 deletions influxdb3_write/src/write_buffer/validator.rs
Original file line number Diff line number Diff line change
@@ -506,7 +506,7 @@ fn convert_v3_parsed_line<'a>(
// TODO: change the default time resolution to microseconds in v3
let time_value_nanos = line
.timestamp
.map(|ts| apply_precision_to_timestamp(precision, ts))
.and_then(|ts| apply_precision_to_timestamp(precision, ts))
.unwrap_or(ingest_time.timestamp_nanos());
values.push(Field {
name: TIME_COLUMN_NAME.to_string(),
@@ -628,7 +628,7 @@ fn convert_v1_parsed_line<'a>(
// set the time value
let time_value_nanos = line
.timestamp
.map(|ts| apply_precision_to_timestamp(precision, ts))
.and_then(|ts| apply_precision_to_timestamp(precision, ts))
.unwrap_or(ingest_time.timestamp_nanos());

let segment_start = segment_duration.start_time(time_value_nanos / 1_000_000_000);
@@ -652,7 +652,8 @@ fn convert_v1_parsed_line<'a>(
table_batch_map.lines.push(raw_line);
}

fn apply_precision_to_timestamp(precision: Precision, ts: i64) -> i64 {
/// Returns `None` if calculation overflows
fn apply_precision_to_timestamp(precision: Precision, ts: i64) -> Option<i64> {
let multiplier = match precision {
Precision::Auto => match crate::guess_precision(ts) {
Precision::Second => 1_000_000_000,
@@ -667,8 +668,7 @@ fn apply_precision_to_timestamp(precision: Precision, ts: i64) -> i64 {
Precision::Microsecond => 1_000,
Precision::Nanosecond => 1,
};

ts * multiplier
ts.checked_mul(multiplier)
}

#[cfg(test)]