Make State Anchor acquisition resumable and descriptor-confined
This commit is contained in:
parent
e6d6406c64
commit
48c10e9a7a
1 changed files with 1030 additions and 197 deletions
|
|
@ -351,6 +351,55 @@ impl Catalog {
|
|||
self.acquire_lease_with(lease, Some(expected_artifact))
|
||||
}
|
||||
|
||||
/// Inserts an exact lease or accepts the same already-committed lease checkpoint.
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns an error for artifact or lease ownership drift, absence, reclaim, or a transaction
|
||||
/// failure.
|
||||
pub fn acquire_or_resume_lease_checked(
|
||||
&self,
|
||||
expected_artifact: &PreparedArtifact,
|
||||
lease: &ArtifactLease,
|
||||
) -> Result<(), CatalogError> {
|
||||
if expected_artifact.prepared_artifact_id != lease.prepared_artifact_id {
|
||||
return Err(CatalogError::OwnershipMismatch {
|
||||
row: CatalogRow::PreparedArtifact,
|
||||
});
|
||||
}
|
||||
self.write(|transaction| {
|
||||
let artifact_key = artifact_key(lease.prepared_artifact_id);
|
||||
let artifacts = transaction
|
||||
.open_table(ARTIFACTS)
|
||||
.map_err(CatalogError::redb)?;
|
||||
let artifact: PreparedArtifact =
|
||||
require_row(&artifacts, &artifact_key, CatalogRow::PreparedArtifact)?;
|
||||
if artifact != *expected_artifact {
|
||||
return Err(CatalogError::OwnershipMismatch {
|
||||
row: CatalogRow::PreparedArtifact,
|
||||
});
|
||||
}
|
||||
if artifact.state != ArtifactState::Available {
|
||||
return Err(CatalogError::ArtifactUnavailable);
|
||||
}
|
||||
drop(artifacts);
|
||||
|
||||
let key = lease_key(lease);
|
||||
let mut leases = transaction.open_table(LEASES).map_err(CatalogError::redb)?;
|
||||
if leases
|
||||
.get(key.as_slice())
|
||||
.map_err(CatalogError::redb)?
|
||||
.is_some()
|
||||
{
|
||||
return require_exact(&leases, &key, lease, CatalogRow::ArtifactLease);
|
||||
}
|
||||
let encoded = encode(lease)?;
|
||||
leases
|
||||
.insert(key.as_slice(), encoded.as_slice())
|
||||
.map_err(CatalogError::redb)?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
fn acquire_lease_with(
|
||||
&self,
|
||||
lease: &ArtifactLease,
|
||||
|
|
|
|||
Loading…
Reference in a new issue