From 4ba34c7300d97839308c58eba107450f6ad2a830 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Mon, 29 Apr 2024 17:39:44 +0300 Subject: [PATCH] server_storage core topic OKM object key/col/value mapping --- ng-broker/src/server_broker.rs | 4 +-- ng-broker/src/server_storage/core/topic.rs | 31 +++++++++++++--------- ng-net/src/actors/client/pin_repo.rs | 2 +- ng-repo/src/kcv_storage.rs | 14 ++++++++++ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/ng-broker/src/server_broker.rs b/ng-broker/src/server_broker.rs index 47ca602..63e2a5f 100644 --- a/ng-broker/src/server_broker.rs +++ b/ng-broker/src/server_broker.rs @@ -21,14 +21,14 @@ use ng_repo::{ use crate::rocksdb_server_storage::RocksDbServerStorage; -struct TopicInfo { +pub struct TopicInfo { repo: RepoHash, publisher_advert: Option, current_heads: HashSet, - expose_outer: bool, + root_commit: Option, /// indicates which users have opened the topic (boolean says if as publisher or not) users: HashMap, diff --git a/ng-broker/src/server_storage/core/topic.rs b/ng-broker/src/server_storage/core/topic.rs index 7d8ed56..63eb59e 100644 --- a/ng-broker/src/server_storage/core/topic.rs +++ b/ng-broker/src/server_storage/core/topic.rs @@ -19,6 +19,8 @@ use ng_repo::types::*; use serde_bare::to_vec; +use crate::server_broker::TopicInfo; + pub struct Topic<'a> { key: Vec, repo: ExistentialValue, @@ -60,18 +62,23 @@ impl<'a> Topic<'a> { vec![&Self::USERS, &Self::HEADS], ); - pub fn load(&self) -> Result<(), StorageError> { - let props = self.load_props()?; - // let bs = BranchInfo { - // id: id.clone(), - // branch_type: prop(Self::TYPE, &props)?, - // read_cap: prop(Self::READ_CAP, &props)?, - // topic: prop(Self::TOPIC, &props)?, - // topic_priv_key: prop(Self::PUBLISHER, &props).ok(), - // current_heads: Self::get_all_heads(id, storage)?, - // }; - // Ok(bs) - Ok(()) + pub fn load( + id: &TopicId, + overlay: &OverlayId, + storage: &'a dyn KCVStorage, + ) -> Result { + let mut opening = Topic::new(id, overlay, storage); + let props = opening.load_props()?; + let existential = col(&Self::REPO, &props)?; + opening.repo.set(&existential, &opening)?; + let ti = TopicInfo { + repo: existential, + publisher_advert: col(&Self::ADVERT, &props).ok(), + root_commit: col(&Self::ROOT_COMMIT, &props).ok(), + users: Self::USERS.get_all(&mut opening)?, + current_heads: Self::HEADS.get_all(&mut opening)?, + }; + Ok(ti) } pub fn new(id: &TopicId, overlay: &OverlayId, storage: &'a dyn KCVStorage) -> Self { diff --git a/ng-net/src/actors/client/pin_repo.rs b/ng-net/src/actors/client/pin_repo.rs index 2a77232..5ed6017 100644 --- a/ng-net/src/actors/client/pin_repo.rs +++ b/ng-net/src/actors/client/pin_repo.rs @@ -48,7 +48,7 @@ impl PinRepo { expose_outer: false, peers: vec![], max_peer_count: 0, - allowed_peers: vec![], + //allowed_peers: vec![], ro_topics, rw_topics, }) diff --git a/ng-repo/src/kcv_storage.rs b/ng-repo/src/kcv_storage.rs index 7107b1a..a18180f 100644 --- a/ng-repo/src/kcv_storage.rs +++ b/ng-repo/src/kcv_storage.rs @@ -24,6 +24,20 @@ where )?) } +pub fn col( + column: &dyn ISingleValueColumn, + props: &HashMap>, +) -> Result +where + A: for<'a> Deserialize<'a>, +{ + Ok(from_slice( + &props + .get(&column.suffix()) + .ok_or(StorageError::PropertyNotFound)?, + )?) +} + pub struct Class<'a> { columns: Vec<&'a dyn ISingleValueColumn>, multi_value_columns: Vec<&'a dyn IMultiValueColumn>,