Skip to content

Commit

Permalink
Improve MetaCache trait usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lurenpluto committed Nov 25, 2022
1 parent d76d3c1 commit d9e113f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/component/cyfs-stack/src/meta/fail_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use std::sync::Arc;
const FAIL_CHECK_INTERVAL: u64 = 1000 * 1000 * 60 * 60;

struct DeviceFailHandlerImpl {
meta_cache: Box<dyn MetaCache>,
meta_cache: MetaCacheRef,
device_manager: Box<dyn DeviceCache>,

// FIXME limit max cache count
state: Mutex<HashMap<ObjectId, u64>>,
}

impl DeviceFailHandlerImpl {
pub fn new(meta_cache: Box<dyn MetaCache>, device_manager: Box<dyn DeviceCache>) -> Self {
pub fn new(meta_cache: MetaCacheRef, device_manager: Box<dyn DeviceCache>) -> Self {
Self {
meta_cache,
device_manager,
Expand Down Expand Up @@ -106,7 +106,7 @@ impl DeviceFailHandlerImpl {
pub struct ObjectFailHandler(Arc<DeviceFailHandlerImpl>);

impl ObjectFailHandler {
pub fn new(meta_cache: Box<dyn MetaCache>, device_manager: Box<dyn DeviceCache>) -> Self {
pub fn new(meta_cache: MetaCacheRef, device_manager: Box<dyn DeviceCache>) -> Self {
Self(Arc::new(DeviceFailHandlerImpl::new(
meta_cache,
device_manager,
Expand Down
8 changes: 5 additions & 3 deletions src/component/cyfs-stack/src/meta/raw_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ pub(crate) struct RawMetaCache {
}

impl RawMetaCache {
pub fn new(target: MetaMinerTarget, noc: NamedObjectCacheRef) -> Self {
pub fn new(target: MetaMinerTarget, noc: NamedObjectCacheRef) -> MetaCacheRef {
info!("raw meta cache: {}", target.to_string());
let meta_client =
MetaClient::new_target(target).with_timeout(std::time::Duration::from_secs(60 * 2));

Self {
let ret = Self {
noc,
meta_client: Arc::new(meta_client),
device_id: DeviceId::default(),
fail_cache: MetaFailCache::new(),
}
};

Arc::new(Box::new(ret))
}

async fn get_from_meta(
Expand Down
4 changes: 2 additions & 2 deletions src/component/cyfs-stack/src/name/name_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ pub struct NameResolver {
}

impl NameResolver {
pub fn new(meta_cache: Box<dyn MetaCache>, noc: NamedObjectCacheRef) -> Self {
pub fn new(meta_cache: MetaCacheRef, noc: NamedObjectCacheRef) -> Self {
let id = "cyfs-name-cache";
Self {
meta_cache: Arc::new(meta_cache),
meta_cache,
cache: NOCCollectionSync::new(id, noc),
resolving_list: Arc::new(Mutex::new(HashMap::new())),
next_retry_interval: Arc::new(AtomicU64::new(1000 * 1000 * 2)),
Expand Down
6 changes: 3 additions & 3 deletions src/component/cyfs-stack/src/non_api/meta/meta_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use std::sync::Arc;

pub(crate) struct MetaInputProcessor {
next: Option<NONInputProcessorRef>,
meta_cache: Box<dyn MetaCache>,
meta_cache: MetaCacheRef,
}

impl MetaInputProcessor {
fn new(
next: Option<NONInputProcessorRef>,
meta_cache: Box<dyn MetaCache>,
meta_cache: MetaCacheRef,
) -> NONInputProcessorRef {
let ret = Self { next, meta_cache };
Arc::new(Box::new(ret))
Expand All @@ -24,7 +24,7 @@ impl MetaInputProcessor {
// Integrate noc with inner_path+meta service
pub(crate) fn new_with_inner_path_service(
noc_processor: Option<NONInputProcessorRef>,
meta_cache: Box<dyn MetaCache>,
meta_cache: MetaCacheRef,
ndc: Box<dyn NamedDataCache>,
tracker: Box<dyn TrackerCache>,
chunk_manager: Arc<ChunkManager>,
Expand Down
4 changes: 2 additions & 2 deletions src/component/cyfs-stack/src/non_api/service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::super::noc::*;
use super::super::non::*;
use super::super::router::*;
use crate::forward::ForwardProcessorManager;
use crate::meta::{MetaCache, ObjectFailHandler};
use crate::meta::{MetaCacheRef, ObjectFailHandler};
use crate::ndn_api::*;
use crate::resolver::OodResolver;
use crate::router_handler::RouterHandlersManager;
Expand Down Expand Up @@ -37,7 +37,7 @@ impl NONService {
ood_resovler: OodResolver,

router_handlers: RouterHandlersManager,
meta_cache: Box<dyn MetaCache>,
meta_cache: MetaCacheRef,
fail_handler: ObjectFailHandler,
chunk_manager: ChunkManagerRef,
) -> (NONService, NDNService) {
Expand Down
22 changes: 11 additions & 11 deletions src/component/cyfs-stack/src/stack/cyfs_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ impl CyfsStackImpl {

let noc = Self::init_raw_noc(isolate, known_objects).await?;

// meta with cache
let raw_meta_cache = RawMetaCache::new(param.meta.target, noc.clone());

// 名字解析服务
let name_resolver = NameResolver::new(raw_meta_cache.clone(), noc.clone());
name_resolver.start().await?;

// 加载全局状态
let (local_root_state, local_cache) =
Self::load_global_state(&device_id, &device, noc.clone(), &config).await?;
Expand All @@ -146,10 +153,7 @@ impl CyfsStackImpl {
let trans_store = create_trans_store(isolate).await?;
let chunk_manager = Arc::new(ChunkManager::new());

// 不使用rules的meta_client
// 内部依赖带rule-noc,需要使用延迟绑定策略
let raw_meta_cache = RawMetaCache::new(param.meta.target, noc.clone());

// let sn_config_manager = SNConfigManager::new(name_resolver.clone(), )
// init object searcher for global use
let obj_searcher = CompoundObjectSearcher::new(
noc.clone(),
Expand All @@ -174,7 +178,7 @@ impl CyfsStackImpl {
);

let fail_handler =
ObjectFailHandler::new(raw_meta_cache.clone_meta(), device_manager.clone_cache());
ObjectFailHandler::new(raw_meta_cache.clone(), device_manager.clone_cache());

// Init zone manager
let root_state_processor = GlobalStateOutputTransformer::new(
Expand All @@ -191,7 +195,7 @@ impl CyfsStackImpl {
device_manager.clone_cache(),
device_id.clone(),
device_category,
raw_meta_cache.clone_meta(),
raw_meta_cache.clone(),
fail_handler.clone(),
root_state_processor,
local_cache_processor,
Expand Down Expand Up @@ -284,10 +288,6 @@ impl CyfsStackImpl {
router_handlers.clone(),
);

// 名字解析服务
let name_resolver = NameResolver::new(raw_meta_cache.clone_meta(), noc.clone());
name_resolver.start().await?;

let util_service = UtilService::new(
noc.clone(),
ndc.clone(),
Expand All @@ -310,7 +310,7 @@ impl CyfsStackImpl {
zone_manager.clone(),
ood_resoler.clone(),
router_handlers.clone(),
raw_meta_cache.clone_meta(),
raw_meta_cache.clone(),
fail_handler.clone(),
chunk_manager.clone(),
);
Expand Down
6 changes: 3 additions & 3 deletions src/component/cyfs-stack/src/zone/role_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::acl::AclManagerRef;
use crate::config::StackGlobalConfig;
use crate::events::RouterEventsManager;
use crate::interface::{SyncListenerManager, SyncListenerManagerParams};
use crate::meta::RawMetaCache;
use crate::meta::MetaCacheRef;
use crate::root_state_api::GlobalStateLocalService;
use crate::sync::*;
use crate::util_api::UtilService;
Expand Down Expand Up @@ -56,7 +56,7 @@ pub struct ZoneRoleManager {
device_id: DeviceId,
zone_manager: ZoneManagerRef,
noc: NamedObjectCacheRef,
raw_meta_cache: RawMetaCache,
raw_meta_cache: MetaCacheRef,
acl_manager: AclManagerRef,

config: StackGlobalConfig,
Expand All @@ -75,7 +75,7 @@ impl ZoneRoleManager {
device_id: DeviceId,
zone_manager: ZoneManagerRef,
noc: NamedObjectCacheRef,
raw_meta_cache: RawMetaCache,
raw_meta_cache: MetaCacheRef,
acl_manager: AclManagerRef,
event_manager: RouterEventsManager,
config: StackGlobalConfig,
Expand Down
4 changes: 2 additions & 2 deletions src/component/cyfs-stack/src/zone/zone_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct ZoneManager {
// 当前的zone信息
current_info: Arc<Mutex<Option<Arc<CurrentZoneInfo>>>>,

meta_cache: Arc<Box<dyn MetaCache>>,
meta_cache: Arc<MetaCacheRef>,

zone_changed_event: ZoneChangeEventManager,

Expand All @@ -89,7 +89,7 @@ impl ZoneManager {
device_manager: Box<dyn DeviceCache>,
device_id: DeviceId,
device_category: DeviceCategory,
meta_cache: Box<dyn MetaCache>,
meta_cache: MetaCacheRef,
fail_handler: ObjectFailHandler,
root_state: GlobalStateOutputProcessorRef,
local_cache: GlobalStateOutputProcessorRef,
Expand Down

0 comments on commit d9e113f

Please sign in to comment.