feat(ecstore): add remote snapshot lease RPCs (#5389)

* feat(ecstore): add local snapshot leases

* feat(ecstore): add remote snapshot lease RPCs

* fix(rpc): keep snapshot lease checks CI-compatible
This commit is contained in:
cxymds
2026-07-29 15:06:18 +08:00
committed by GitHub
parent 2801b2500d
commit d9efd6b853
14 changed files with 805 additions and 17 deletions
+8
View File
@@ -1365,6 +1365,14 @@ impl DiskAPI for LocalDiskWrapper {
.await
}
async fn renew_snapshot_lease(&self, volume: &str, path: &str, token: SnapshotLeaseToken) -> Result<SnapshotLeaseToken> {
self.track_disk_health(
|| async { self.disk.renew_snapshot_lease(volume, path, token).await },
get_max_timeout_duration(),
)
.await
}
async fn delete_data_dir(&self, volume: &str, path: &str, opts: DeleteOptions) -> Result<DataDirDeleteStatus> {
self.track_disk_health(
|| async { self.disk.delete_data_dir(volume, path, opts).await },
+26 -2
View File
@@ -7908,6 +7908,23 @@ impl DiskAPI for LocalDisk {
}
}
async fn renew_snapshot_lease(&self, volume: &str, path: &str, token: SnapshotLeaseToken) -> Result<SnapshotLeaseToken> {
let key = SnapshotLeaseKey {
volume: volume.to_string(),
path: path.to_string(),
};
let mut registry = self.snapshot_leases.lock().await;
let Some(entry) = registry.entries.get_mut(&key) else {
return Err(DiskError::FileNotFound);
};
if entry.deleting || !entry.tokens.remove(&token) {
return Err(DiskError::FileNotFound);
}
let renewed = SnapshotLeaseToken::new();
entry.tokens.insert(renewed);
Ok(renewed)
}
async fn delete_data_dir(&self, volume: &str, path: &str, opts: DeleteOptions) -> Result<DataDirDeleteStatus> {
let key = SnapshotLeaseKey {
volume: volume.to_string(),
@@ -14957,6 +14974,13 @@ mod test {
.acquire_snapshot_lease(volume, &data_dir)
.await
.expect("second lease should be acquired");
let renewed = disk
.renew_snapshot_lease(volume, &data_dir, first)
.await
.expect("first lease should renew atomically");
disk.release_snapshot_lease(volume, &data_dir, first)
.await
.expect("the superseded token should be idempotent");
let status = disk
.delete_data_dir(
volume,
@@ -14976,9 +15000,9 @@ mod test {
Bytes::from_static(b"later")
);
disk.release_snapshot_lease(volume, &data_dir, first)
disk.release_snapshot_lease(volume, &data_dir, renewed)
.await
.expect("first lease release should succeed");
.expect("renewed lease release should succeed");
assert!(
disk.read_all(volume, &first_part).await.is_ok(),
"one remaining lease must keep the data directory"
+22
View File
@@ -79,6 +79,18 @@ impl SnapshotLeaseToken {
pub fn new() -> Self {
Self(Uuid::new_v4())
}
pub fn from_slice(bytes: &[u8]) -> Result<Self> {
let uuid = Uuid::from_slice(bytes).map_err(|_| Error::other("invalid snapshot lease token"))?;
if uuid.is_nil() {
return Err(Error::other("invalid snapshot lease token"));
}
Ok(Self(uuid))
}
pub fn as_bytes(&self) -> &[u8; 16] {
self.0.as_bytes()
}
}
impl Default for SnapshotLeaseToken {
@@ -284,6 +296,13 @@ impl DiskAPI for Disk {
}
}
async fn renew_snapshot_lease(&self, volume: &str, path: &str, token: SnapshotLeaseToken) -> Result<SnapshotLeaseToken> {
match self {
Disk::Local(local_disk) => local_disk.renew_snapshot_lease(volume, path, token).await,
Disk::Remote(remote_disk) => remote_disk.renew_snapshot_lease(volume, path, token).await,
}
}
async fn delete_data_dir(&self, volume: &str, path: &str, opts: DeleteOptions) -> Result<DataDirDeleteStatus> {
match self {
Disk::Local(local_disk) => local_disk.delete_data_dir(volume, path, opts).await,
@@ -694,6 +713,9 @@ pub trait DiskAPI: Debug + Send + Sync + 'static {
async fn release_snapshot_lease(&self, _volume: &str, _path: &str, _token: SnapshotLeaseToken) -> Result<()> {
Err(Error::other("snapshot leases are not supported by this disk"))
}
async fn renew_snapshot_lease(&self, _volume: &str, _path: &str, _token: SnapshotLeaseToken) -> Result<SnapshotLeaseToken> {
Err(Error::other("snapshot leases are not supported by this disk"))
}
async fn delete_data_dir(&self, volume: &str, path: &str, opts: DeleteOptions) -> Result<DataDirDeleteStatus> {
self.delete(volume, path, opts).await?;
Ok(DataDirDeleteStatus::Deleted)