fix(release): 收紧分发热路径与事务边界
bat-rust / Build and test Rust (push) Canceled after 0s
bat-rust / Build and test Go API (push) Canceled after 0s

This commit is contained in:
2026-09-12 22:22:11 +08:00
parent f2c20367a6
commit 786b739f99
17 changed files with 835 additions and 124 deletions
+11 -10
View File
@@ -303,12 +303,13 @@ impl SqliteRefCounter {
/// Atomically releases one durable release ownership record.
///
/// The ownership row and the reference decrement are committed in the
/// same SQLite transaction. Retrying the same `(release_id, ordinal)` is
/// therefore idempotent, while a different release keeps its own row and
/// reference count.
/// same SQLite transaction. Retrying the same `(ownership_id, ordinal)` is
/// therefore idempotent, while a different ownership keeps its own row and
/// reference count. The legacy SQL column name is retained for schema
/// compatibility.
pub async fn release_reference_once(
&self,
release_id: &str,
ownership_id: &str,
ordinal: u64,
hash: &Hash,
) -> Result<bool> {
@@ -320,7 +321,7 @@ impl SqliteRefCounter {
WHERE release_id = ?1 AND ordinal = ?2
"#,
)
.bind(release_id)
.bind(ownership_id)
.bind(ordinal as i64)
.fetch_optional(&mut *transaction)
.await?;
@@ -328,8 +329,8 @@ impl SqliteRefCounter {
if let Some((object_id, released)) = existing {
if object_id != hash.to_string() {
return Err(CasError::Other(anyhow::anyhow!(
"CAS release ownership mismatch: release={} ordinal={} expected={} actual={}",
release_id,
"CAS release ownership mismatch: ownership_id={} ordinal={} expected={} actual={}",
ownership_id,
ordinal,
object_id,
hash
@@ -340,8 +341,8 @@ impl SqliteRefCounter {
return Ok(false);
}
return Err(CasError::Other(anyhow::anyhow!(
"CAS release ownership record is not in a retryable state: release={} ordinal={}",
release_id,
"CAS release ownership record is not in a retryable state: ownership_id={} ordinal={}",
ownership_id,
ordinal
)));
}
@@ -380,7 +381,7 @@ impl SqliteRefCounter {
VALUES(?1, ?2, ?3, 1)
"#,
)
.bind(release_id)
.bind(ownership_id)
.bind(ordinal as i64)
.bind(hash.to_string())
.execute(&mut *transaction)
+2 -2
View File
@@ -166,13 +166,13 @@ impl FileSystemCasRepository {
/// Releases one release-owned reference exactly once.
pub async fn release_reference_once(
&self,
release_id: &str,
ownership_id: &str,
ordinal: u64,
hash: &Hash,
) -> Result<bool> {
let _lock = self.acquire_operation_lock().await?;
self.ref_counter
.release_reference_once(release_id, ordinal, hash)
.release_reference_once(ownership_id, ordinal, hash)
.await
}