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(sink): Fix excessive number of starrocks txn #19217

Merged
merged 5 commits into from
Nov 4, 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
21 changes: 19 additions & 2 deletions src/connector/src/sink/starrocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ pub struct StarrocksSinkWriter {
pk_indices: Vec<usize>,
is_append_only: bool,
client: Option<StarrocksClient>,
txn_client: StarrocksTxnClient,
txn_client: Arc<StarrocksTxnClient>,
row_encoder: JsonEncoder,
executor_id: u64,
curr_txn_label: Option<String>,
Expand Down Expand Up @@ -432,7 +432,7 @@ impl StarrocksSinkWriter {
pk_indices,
is_append_only,
client: None,
txn_client: StarrocksTxnClient::new(txn_request_builder),
txn_client: Arc::new(StarrocksTxnClient::new(txn_request_builder)),
row_encoder: JsonEncoder::new_with_starrocks(schema, None),
executor_id,
curr_txn_label: None,
Expand Down Expand Up @@ -527,6 +527,23 @@ impl StarrocksSinkWriter {
}
}

impl Drop for StarrocksSinkWriter {
fn drop(&mut self) {
if let Some(txn_label) = self.curr_txn_label.take() {
let txn_client = self.txn_client.clone();
tokio::spawn(async move {
if let Err(e) = txn_client.rollback(txn_label.clone()).await {
tracing::error!(
"starrocks rollback transaction error: {:?}, txn label: {}",
e.as_report(),
txn_label
);
}
});
}
}
}

#[async_trait]
impl SinkWriter for StarrocksSinkWriter {
type CommitMetadata = Option<SinkMetadata>;
Expand Down
Loading