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

add "Transaction rolled back" for invalid batons inside transactions #1860

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
31 changes: 27 additions & 4 deletions libsql/src/hrana/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ where
tracing::trace!("baton not found - skipping finalize for {:?}", req);
return Ok(false);
}
let (resp, is_autocommit) = client.finalize(req).await?;
let (resp, is_autocommit) = client.finalize(req).await.map_err(|e| match e {
HranaError::Api(e) if e == "Received an invalid baton" && !self.is_autocommit() => {
HranaError::Api("Received an invalid baton: Transaction rolled back".into())
}
e => e,
})?;
self.inner
.is_autocommit
.store(is_autocommit, Ordering::SeqCst);
Expand All @@ -94,7 +99,9 @@ where
(0, 0)
};

self.inner.total_changes.fetch_add(affected_row_count, Ordering::SeqCst);
self.inner
.total_changes
.fetch_add(affected_row_count, Ordering::SeqCst);
self.inner
.affected_row_count
.store(affected_row_count, Ordering::SeqCst);
Expand Down Expand Up @@ -132,7 +139,15 @@ where
StreamRequest::GetAutocommit(GetAutocommitStreamReq {}),
StreamRequest::Close(CloseStreamReq {}),
])
.await?;
.await
.map_err(|e| match e {
HranaError::Api(e)
if e == "Received an invalid baton" && !self.is_autocommit() =>
{
HranaError::Api("Received an invalid baton: Transaction rolled back".into())
}
e => e,
})?;
client.reset();
(resp, get_autocommit)
} else {
Expand All @@ -142,7 +157,15 @@ where
StreamRequest::Batch(BatchStreamReq { batch }),
StreamRequest::GetAutocommit(GetAutocommitStreamReq {}),
])
.await?;
.await
.map_err(|e| match e {
HranaError::Api(e)
if e == "Received an invalid baton" && !self.is_autocommit() =>
{
HranaError::Api("Received an invalid baton: Transaction rolled back".into())
}
e => e,
})?;
(resp, get_autocommit)
};
drop(client);
Expand Down
Loading