Skip to content

Commit 40227fe

Browse files
committed
Implement GraphPropOps and MemGraphPropSegment
1 parent f7e7496 commit 40227fe

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

db4-storage/src/api/graph_props.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
use std::fmt::Debug;
22
use std::path::Path;
33
use crate::error::StorageError;
4+
use raphtory_core::entities::properties::props::MetadataError;
5+
use raphtory_core::storage::locked_view::LockedView;
6+
use raphtory_core::entities::properties::tprop::TProp;
7+
use raphtory_core::entities::properties::tprop::IllegalPropType;
8+
use raphtory_core::storage::timeindex::TimeIndexEntry;
9+
use raphtory_api::core::entities::properties::prop::Prop;
410

511
pub trait GraphPropSegmentOps: Send + Sync + Debug + 'static
612
where
@@ -10,3 +16,21 @@ where
1016

1117
fn load(path: impl AsRef<Path>) -> Result<Self, StorageError>;
1218
}
19+
20+
/// Methods for reading/writing graph properties and graph metadata from storage.
21+
pub trait GraphPropOps: Send + Sync {
22+
fn get_temporal_prop(&self, prop_id: usize) -> Option<LockedView<'_, TProp>>;
23+
24+
fn add_prop(
25+
&self,
26+
t: TimeIndexEntry,
27+
prop_id: usize,
28+
prop: Prop,
29+
) -> Result<(), IllegalPropType>;
30+
31+
fn get_metadata(&self, id: usize) -> Option<Prop>;
32+
33+
fn add_metadata(&self, prop_id: usize, prop: Prop) -> Result<(), MetadataError>;
34+
35+
fn update_metadata(&self, prop_id: usize, prop: Prop);
36+
}

db4-storage/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub type NodeEntry<'a> = MemNodeEntry<'a, parking_lot::RwLockReadGuard<'a, MemNo
5656
pub type EdgeEntry<'a> = MemEdgeEntry<'a, parking_lot::RwLockReadGuard<'a, MemEdgeSegment>>;
5757
pub type NodeEntryRef<'a> = MemNodeRef<'a>;
5858
pub type EdgeEntryRef<'a> = MemEdgeRef<'a>;
59+
// pub type GraphProps = MemGraphProps;
5960

6061
pub type NodePropAdditions<'a> = GenericTimeOps<'a, PropAdditionCellsRef<'a, MemNodeRef<'a>>>;
6162
pub type NodeEdgeAdditions<'a> = GenericTimeOps<'a, EdgeAdditionCellsRef<'a, MemNodeRef<'a>>>;

db4-storage/src/segments/graph_prop.rs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,46 @@ use raphtory_core::entities::properties::graph_meta::GraphMeta;
22
use std::path::Path;
33
use std::sync::Arc;
44
use std::sync::atomic::AtomicUsize;
5-
use crate::api::graph_props::GraphPropSegmentOps;
5+
use crate::api::graph_props::{GraphPropSegmentOps, GraphPropOps};
66
use crate::error::StorageError;
77
use parking_lot::RwLock;
8+
use raphtory_core::entities::properties::props::MetadataError;
9+
use raphtory_core::storage::locked_view::LockedView;
10+
use raphtory_core::entities::properties::tprop::{TProp, IllegalPropType};
11+
use raphtory_core::storage::timeindex::TimeIndexEntry;
12+
use raphtory_api::core::entities::properties::prop::Prop;
13+
use crate::properties::Properties;
814

15+
/// In-memory segment that contains graph temporal properties and graph metadata.
16+
#[derive(Debug)]
17+
pub struct MemGraphPropSegment {
18+
properties: Properties,
19+
}
20+
21+
impl MemGraphPropSegment {
22+
pub fn new() -> Self {
23+
Self {
24+
properties: Properties::default(),
25+
}
26+
}
27+
}
28+
29+
/// `GraphPropSegmentView` manages graph temporal properties and graph metadata
30+
/// (constant properties). Reads / writes are always served from the in-memory segment.
931
#[derive(Debug)]
1032
pub struct GraphPropSegmentView {
11-
head: Arc<RwLock<GraphMeta>>,
33+
/// In-memory segment that contains the latest graph properties
34+
/// and graph metadata writes.
35+
head: Arc<RwLock<MemGraphPropSegment>>,
36+
37+
/// Estimated size of the segment in bytes.
1238
est_size: AtomicUsize,
1339
}
1440

1541
impl GraphPropSegmentOps for GraphPropSegmentView {
1642
fn new() -> Self {
1743
Self {
18-
head: Arc::new(RwLock::new(GraphMeta::new())),
44+
head: Arc::new(RwLock::new(MemGraphPropSegment::new())),
1945
est_size: AtomicUsize::new(0),
2046
}
2147
}
@@ -24,3 +50,25 @@ impl GraphPropSegmentOps for GraphPropSegmentView {
2450
todo!()
2551
}
2652
}
53+
54+
impl GraphPropOps for GraphPropSegmentView {
55+
fn get_temporal_prop(&self, prop_id: usize) -> Option<LockedView<'_, TProp>> {
56+
todo!()
57+
}
58+
59+
fn add_prop(&self, t: TimeIndexEntry, prop_id: usize, prop: Prop) -> Result<(), IllegalPropType> {
60+
todo!()
61+
}
62+
63+
fn get_metadata(&self, id: usize) -> Option<Prop> {
64+
todo!()
65+
}
66+
67+
fn add_metadata(&self, prop_id: usize, prop: Prop) -> Result<(), MetadataError> {
68+
todo!()
69+
}
70+
71+
fn update_metadata(&self, prop_id: usize, prop: Prop) {
72+
todo!()
73+
}
74+
}

0 commit comments

Comments
 (0)