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(connector): add additional check in nats list_splits #14546

Merged
merged 2 commits into from
Jan 12, 2024
Merged
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
13 changes: 12 additions & 1 deletion src/connector/src/source/nats/enumerator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ use super::source::{NatsOffset, NatsSplit};
use super::NatsProperties;
use crate::source::{SourceEnumeratorContextRef, SplitEnumerator, SplitId};

#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug, Clone)]
pub struct NatsSplitEnumerator {
subject: String,
split_id: SplitId,
client: async_nats::Client,
}

#[async_trait]
Expand All @@ -36,13 +37,23 @@ impl SplitEnumerator for NatsSplitEnumerator {
properties: Self::Properties,
_context: SourceEnumeratorContextRef,
) -> anyhow::Result<NatsSplitEnumerator> {
let client = properties.common.build_client().await?;
Ok(Self {
subject: properties.common.subject,
split_id: Arc::from("0"),
client,
})
}

async fn list_splits(&mut self) -> anyhow::Result<Vec<NatsSplit>> {
// Nats currently does not support list_splits API, if we simple return the default 0 without checking the client status, will result executor crash
let state = self.client.connection_state();
if state != async_nats::connection::State::Connected {
return Err(anyhow::anyhow!(
"Nats connection status is not connected, current status is {:?}",
state
));
}
// TODO: to simplify the logic, return 1 split for first version
let nats_split = NatsSplit {
subject: self.subject.clone(),
Expand Down
Loading