Skip to content

Commit

Permalink
fix: delete asset stable (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Nov 19, 2023
1 parent 956bf3d commit accadf9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/satellite/src/db/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ pub fn delete_docs(collection: &CollectionKey) -> Result<(), String> {
fn delete_docs_impl(collection: &CollectionKey) -> Result<(), String> {
let rule = get_state_rule(collection)?;

let keys: Vec<Key> = get_state_docs(collection, &rule)?.iter()
let keys: Vec<Key> = get_state_docs(collection, &rule)?
.iter()
.map(|(key, _)| key.clone())
.collect();

Expand Down
4 changes: 2 additions & 2 deletions src/satellite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod storage;
mod types;

use crate::controllers::store::get_admin_controllers;
use crate::db::store::{delete_doc, get_doc as get_doc_store, get_docs, insert_doc, delete_docs};
use crate::db::store::{delete_doc, delete_docs, get_doc as get_doc_store, get_docs, insert_doc};
use crate::db::types::interface::{DelDoc, SetDoc};
use crate::db::types::state::Doc;
use crate::guards::caller_is_admin_controller;
Expand All @@ -31,7 +31,7 @@ use crate::storage::store::{
commit_batch, create_batch, create_chunk, delete_asset, delete_assets, delete_domain,
get_config as get_storage_config, get_content_chunks, get_custom_domains, get_public_asset,
init_certified_assets, list_assets as list_assets_store, set_config as set_storage_config,
set_domain
set_domain,
};
use crate::storage::types::config::StorageConfigRewrites;
use crate::storage::types::domain::{CustomDomains, DomainName};
Expand Down
4 changes: 3 additions & 1 deletion src/satellite/src/storage/certification/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use crate::storage::types::config::StorageConfig;
use crate::storage::types::state::FullPath;
use crate::storage::types::store::Asset;
use crate::storage::url::alternative_paths;
use ic_certification::{fork, fork_hash, labeled, labeled_hash, merge_hash_trees, AsHashTree, Hash, HashTree, pruned};
use ic_certification::{
fork, fork_hash, labeled, labeled_hash, merge_hash_trees, pruned, AsHashTree, Hash, HashTree,
};
use sha2::{Digest, Sha256};

impl CertifiedAssetHashes {
Expand Down
17 changes: 17 additions & 0 deletions src/satellite/src/storage/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::storage::types::state::{
};
use crate::storage::types::store::{Asset, AssetEncoding};
use crate::types::core::{Blob, CollectionKey};
use crate::types::state::StableState;
use shared::serializers::{deserialize_from_bytes, serialize_to_bytes};
use std::borrow::Cow;

Expand Down Expand Up @@ -132,6 +133,7 @@ pub fn delete_asset(
delete_asset_heap(full_path, &mut state.borrow_mut().heap.storage.assets)
}),
Memory::Stable => STATE.with(|state| {
delete_content_chunks_stable(collection, full_path, &mut state.borrow_mut().stable);
delete_asset_stable(collection, full_path, &mut state.borrow_mut().stable.assets)
}),
}
Expand Down Expand Up @@ -183,6 +185,21 @@ fn delete_asset_stable(
assets.remove(&stable_full_path(collection, full_path))
}

fn delete_content_chunks_stable(
collection: &CollectionKey,
full_path: &FullPath,
state: &mut StableState,
) {
if let Some(asset) = get_asset_stable(collection, full_path, &state.assets) {
for (_, encoding) in asset.encodings.iter() {
for chunk in encoding.content_chunks.iter() {
let key: StableEncodingChunkKey = deserialize_from_bytes(Cow::Owned(chunk.clone()));
state.content_chunks.remove(&key);
}
}
}
}

fn delete_asset_heap(full_path: &FullPath, assets: &mut AssetsHeap) -> Option<Asset> {
assets.remove(full_path)
}
Expand Down

0 comments on commit accadf9

Please sign in to comment.