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

refactor(kinesis): rename fields of KinesisOffset and KinesisSplit to make everything explicit #18704

Merged
merged 3 commits into from
Sep 25, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/connector/src/source/kinesis/enumerator/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ impl SplitEnumerator for KinesisSplitEnumerator {
.map(|x| KinesisSplit {
shard_id: x.shard_id().to_string().into(),
// handle start with position in reader part
start_position: KinesisOffset::None,
end_position: KinesisOffset::None,
next_offset: KinesisOffset::None,
end_offset: KinesisOffset::None,
Comment on lines +90 to +91
Copy link
Contributor

Choose a reason for hiding this comment

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

you can see from

KinesisOffset::SequenceNumber(seq) => (
Some(seq.clone()),
None,
ShardIteratorType::AfterSequenceNumber,
),

if kinesis read from a position, in current impl, it should begin with the next one.
So next_offset does not mean next offset

Copy link
Member Author

Choose a reason for hiding this comment

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

AfterSequenceNumber is a way to denote the next one after the given sequence number. I don't see any problem here...

Copy link
Member Author

@stdrc stdrc Sep 25, 2024

Choose a reason for hiding this comment

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

Try read this in English: The next_offset is the offset AfterSequenceNumber("abc").

And compare it with previous one: The start_position is the offset SequenceNumber("abc").

Copy link
Contributor

@tabVersion tabVersion Sep 25, 2024

Choose a reason for hiding this comment

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

I understand you want to eliminate the concept misalignment in the sources' split def, it is good for the project.

The variable name ought to describe the value it stores, not involving how other components do with it. But here, it stores the latest successful read offset (and literally the start offset if begin with Timestamp or TrimHorizen). It is not the next offset.
Kinesis does have its own primitive to begin consumption with the offset after the given one, your proposal may not take this for granted.

Try read this in English

Besides this, I know English well and please remain calm and friendly in communications. Be professional, dude.

Copy link
Member Author

@stdrc stdrc Sep 25, 2024

Choose a reason for hiding this comment

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

Try read this in English

Besides this, I know English well and please remain calm and friendly in communications. Be professional, dude.

I'm saying that the new semantics is understandable in English, while the previous one is not.

The value stored by start_position: KinesisOffset is not the sequence number, it's After(sequence number). When recovery happens, the start position is the next one after sequence number, so what start_position = SequenceNumber(abc) actually means is start_position = AfterSequenceNumber(abc). The renaming from start_position to next_offset doesn't change any semantics, it doesn't matter. The core change is start_position = SequenceNumber(abc) to start_position = AfterSequenceNumber(abc).

Copy link
Member Author

Choose a reason for hiding this comment

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

In your logic, if start_position is last seen offset, then the Earliest and Latest variants should be BeforeEarliest, BeforeLatest. Is it clear enough?

Copy link
Contributor

@tabVersion tabVersion Sep 25, 2024

Choose a reason for hiding this comment

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

In your logic, if start_position is last seen offset, then the Earliest and Latest variants should be BeforeEarliest, BeforeLatest. Is it clear enough?

Using sarcasm and rhetorical questions in the workplace is not a friendly communication attitude.

Is it clear enough?

Yes, I fully understand your motivation and proposed changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

In your logic, if start_position is last seen offset, then the Earliest and Latest variants should be BeforeEarliest, BeforeLatest. Is it clear enough?

Using sarcasm and rhetorical questions in the workplace is not a friendly communication attitude.

Hah? I'm not using any sarcasm and rhetorical question. "Is it clear enough?" just means "这么解释足够清楚了吗?".

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't be so sensitive. I'm just trying to explain. I admit that I was a bit impatient at the very beginning of this thread. But I didn't mean to be any aggressive after that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I fully understand your motivation and proposed changes.

Ok, then I think we have reached a consensus.

})
.collect())
}
Expand Down
26 changes: 13 additions & 13 deletions src/connector/src/source/kinesis/source/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pub struct KinesisSplitReader {
shard_id: SplitId,
latest_offset: Option<String>,
shard_iter: Option<String>,
start_position: KinesisOffset,
next_offset: KinesisOffset,
#[expect(dead_code)]
end_position: KinesisOffset,
end_offset: KinesisOffset,

split_id: SplitId,
parser_config: ParserConfig,
Expand All @@ -67,7 +67,7 @@ impl SplitReader for KinesisSplitReader {

let split = splits.into_iter().next().unwrap();

let start_position = match &split.start_position {
let next_offset = match &split.next_offset {
KinesisOffset::None => match &properties.scan_startup_mode {
None => KinesisOffset::Earliest,
Some(mode) => match mode.as_str() {
Expand All @@ -85,10 +85,10 @@ impl SplitReader for KinesisSplitReader {
}
},
},
start_position => start_position.to_owned(),
next_offset => next_offset.to_owned(),
};

if !matches!(start_position, KinesisOffset::Timestamp(_))
if !matches!(next_offset, KinesisOffset::Timestamp(_))
&& properties.timestamp_offset.is_some()
{
// cannot bail! here because all new split readers will fail to start if user set 'scan.startup.mode' to 'timestamp'
Expand All @@ -107,8 +107,8 @@ impl SplitReader for KinesisSplitReader {
shard_id: split.shard_id,
shard_iter: None,
latest_offset: None,
start_position,
end_position: split.end_position,
next_offset,
end_offset: split.end_offset,
split_id,
parser_config,
source_ctx,
Expand Down Expand Up @@ -250,9 +250,9 @@ impl KinesisSplitReader {
ShardIteratorType::AfterSequenceNumber,
)
} else {
match &self.start_position {
match &self.next_offset {
KinesisOffset::Earliest => (None, None, ShardIteratorType::TrimHorizon),
KinesisOffset::SequenceNumber(seq) => (
KinesisOffset::AfterSequenceNumber(seq) => (
Some(seq.clone()),
None,
ShardIteratorType::AfterSequenceNumber,
Expand Down Expand Up @@ -365,8 +365,8 @@ mod tests {
properties.clone(),
vec![KinesisSplit {
shard_id: "shardId-000000000001".to_string().into(),
start_position: KinesisOffset::Earliest,
end_position: KinesisOffset::None,
next_offset: KinesisOffset::Earliest,
end_offset: KinesisOffset::None,
}],
Default::default(),
SourceContext::dummy().into(),
Expand All @@ -381,10 +381,10 @@ mod tests {
properties.clone(),
vec![KinesisSplit {
shard_id: "shardId-000000000001".to_string().into(),
start_position: KinesisOffset::SequenceNumber(
next_offset: KinesisOffset::AfterSequenceNumber(
"49629139817504901062972448413535783695568426186596941842".to_string(),
),
end_position: KinesisOffset::None,
end_offset: KinesisOffset::None,
}],
Default::default(),
SourceContext::dummy().into(),
Expand Down
32 changes: 18 additions & 14 deletions src/connector/src/source/kinesis/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,30 @@ use serde::{Deserialize, Serialize};
use crate::error::ConnectorResult;
use crate::source::{SplitId, SplitMetaData};

/// See <https://docs.aws.amazon.com/kinesis/latest/APIReference/API_StartingPosition.html> for more details.
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, Hash)]
pub enum KinesisOffset {
/// Corresponds to `TRIM_HORIZON`. Points the oldest record in the shard.
Earliest,
/// Corresponds to `LATEST`. Points to the (still-nonexisting) record just after the most recent one in the shard.
Latest,
SequenceNumber(String),
/// Corresponds to `AFTER_SEQUENCE_NUMBER`. Points the record just after the one with the given sequence number.
#[serde(alias = "SequenceNumber")] // for backward compatibility
AfterSequenceNumber(String),
/// Corresponds to `AT_TIMESTAMP`. Points to the (first) record right at or after the given timestamp.
Timestamp(i64),

None,
}
stdrc marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Hash)]
pub struct KinesisSplit {
pub(crate) shard_id: SplitId,
pub(crate) start_position: KinesisOffset,
pub(crate) end_position: KinesisOffset,

#[serde(alias = "start_position")] // for backward compatibility
pub(crate) next_offset: KinesisOffset,
#[serde(alias = "end_position")] // for backward compatibility
pub(crate) end_offset: KinesisOffset,
}

impl SplitMetaData for KinesisSplit {
Expand All @@ -48,27 +58,21 @@ impl SplitMetaData for KinesisSplit {
}

fn update_offset(&mut self, last_seen_offset: String) -> ConnectorResult<()> {
let start_offset = if last_seen_offset.is_empty() {
KinesisOffset::Earliest
} else {
KinesisOffset::SequenceNumber(last_seen_offset)
};

self.start_position = start_offset;
self.next_offset = KinesisOffset::AfterSequenceNumber(last_seen_offset);
Ok(())
}
}

impl KinesisSplit {
pub fn new(
shard_id: SplitId,
start_position: KinesisOffset,
end_position: KinesisOffset,
next_offset: KinesisOffset,
end_offset: KinesisOffset,
) -> KinesisSplit {
KinesisSplit {
shard_id,
start_position,
end_position,
next_offset,
end_offset,
}
}
}
Loading