Skip to content

Commit

Permalink
Merge pull request #466 from jiangliu/blobcache
Browse files Browse the repository at this point in the history
Improvements to the blob cache manager
  • Loading branch information
imeoer authored Jun 6, 2022
2 parents 9a59571 + 3e8709d commit 74ddb6c
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 125 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ path = "src/bin/nydusd/main.rs"
name = "nydus"
path = "src/lib.rs"


[dependencies]
rlimit = "0.8.3"
log = "0.4.8"
Expand Down
13 changes: 10 additions & 3 deletions api/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,16 @@ pub struct BlobCacheList {
pub blobs: Vec<BlobCacheEntry>,
}

/// Identifier for cached blob objects.
///
/// Domains are used to control the blob sharing scope. All blobs associated with the same domain
/// will be shared/reused, but blobs associated with different domains are isolated.
#[derive(Clone, Deserialize, Debug)]
pub struct BlobObjectParam {
pub struct BlobCacheObjectId {
/// Domain identifier for the object.
pub domain_id: String,
/// Blob identifier for the object.
pub blob_id: String,
}

#[derive(Debug)]
Expand Down Expand Up @@ -140,8 +147,8 @@ pub enum ApiRequest {
// Nydus API v2
DaemonInfoV2,
CreateBlobObject(BlobCacheEntry),
GetBlobObject(BlobObjectParam),
DeleteBlobObject(BlobObjectParam),
GetBlobObject(BlobCacheObjectId),
DeleteBlobObject(BlobCacheObjectId),
ListBlobObject,
}

Expand Down
8 changes: 5 additions & 3 deletions api/src/http_endpoint_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dbs_uhttp::{Method, Request, Response};

use crate::http::{
error_response, extract_query_part, parse_body, success_response, translate_status_code,
ApiError, ApiRequest, ApiResponse, ApiResponsePayload, BlobObjectParam, EndpointHandler,
ApiError, ApiRequest, ApiResponse, ApiResponsePayload, BlobCacheObjectId, EndpointHandler,
HttpError, HttpResult,
};

Expand Down Expand Up @@ -57,7 +57,8 @@ impl EndpointHandler for BlobObjectListHandlerV2 {
match (req.method(), req.body.as_ref()) {
(Method::Get, None) => {
if let Some(domain_id) = extract_query_part(req, "domain_id") {
let param = BlobObjectParam { domain_id };
let blob_id = extract_query_part(req, "blob_id").unwrap_or_default();
let param = BlobCacheObjectId { domain_id, blob_id };
let r = kicker(ApiRequest::GetBlobObject(param));
return Ok(convert_to_response(r, HttpError::GetBlobObjects));
}
Expand All @@ -70,7 +71,8 @@ impl EndpointHandler for BlobObjectListHandlerV2 {
}
(Method::Delete, None) => {
if let Some(domain_id) = extract_query_part(req, "domain_id") {
let param = BlobObjectParam { domain_id };
let blob_id = extract_query_part(req, "blob_id").unwrap_or_default();
let param = BlobCacheObjectId { domain_id, blob_id };
let r = kicker(ApiRequest::DeleteBlobObject(param));
return Ok(convert_to_response(r, HttpError::DeleteBlobObject));
}
Expand Down
4 changes: 2 additions & 2 deletions src/bin/nydusd/api_server_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use nix::unistd::Pid;
use nydus::{FsBackendType, NydusError};
use nydus_api::http::{
start_http_thread, ApiError, ApiMountCmd, ApiRequest, ApiResponse, ApiResponsePayload,
ApiResult, BlobCacheEntry, BlobObjectParam, DaemonConf, DaemonErrorKind, MetricsErrorKind,
ApiResult, BlobCacheEntry, BlobCacheObjectId, DaemonConf, DaemonErrorKind, MetricsErrorKind,
};
use nydus_utils::metrics;

Expand Down Expand Up @@ -311,7 +311,7 @@ impl ApiServer {
}
}

fn remove_blob_cache_entry(&self, param: &BlobObjectParam) -> ApiResponse {
fn remove_blob_cache_entry(&self, param: &BlobCacheObjectId) -> ApiResponse {
match DAEMON_CONTROLLER.get_blob_cache_mgr() {
None => Err(ApiError::DaemonAbnormal(DaemonErrorKind::Unsupported)),
Some(mgr) => {
Expand Down
Loading

0 comments on commit 74ddb6c

Please sign in to comment.