Skip to content

Commit 0110ea7

Browse files
committed
replace GraphMeta with Meta and other changes to Graph properties
1 parent 5042a5b commit 0110ea7

File tree

25 files changed

+291
-242
lines changed

25 files changed

+291
-242
lines changed

db4-graph/src/lib.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ use raphtory_core::{
1919
storage::timeindex::TimeIndexEntry,
2020
};
2121
use storage::{
22-
api::graph::GraphSegmentOps, error::StorageError, pages::{
22+
api::graph::GraphPropOps,
23+
error::StorageError,
24+
pages::{
2325
layer_counter::GraphStats,
2426
locked::{edges::WriteLockedEdgePages, nodes::WriteLockedNodePages},
25-
}, persist::strategy::{Config, PersistentStrategy},
26-
resolver::GIDResolverOps, wal::{GraphWal, TransactionID, Wal},
27-
Extension, GIDResolver, Layer, ReadLockedLayer, WalImpl, ES, GS, NS
27+
},
28+
persist::strategy::{Config, PersistentStrategy},
29+
resolver::GIDResolverOps,
30+
wal::{GraphWal, TransactionID, Wal},
31+
Extension, GIDResolver, Layer, ReadLockedLayer, WalImpl, ES, GS, NS,
2832
};
2933
use tempfile::TempDir;
3034

@@ -127,17 +131,23 @@ impl<EXT: PersistentStrategy<NS = NS<EXT>, ES = ES<EXT>>> TemporalGraph<EXT> {
127131
pub fn new(ext: EXT) -> Result<Self, StorageError> {
128132
let node_meta = Meta::new_for_nodes();
129133
let edge_meta = Meta::new_for_edges();
130-
let graph_meta = GraphMeta::new();
134+
let graph_meta = Meta::new_for_graph();
131135

132136
Self::new_with_meta(None, node_meta, edge_meta, graph_meta, ext)
133137
}
134138

135139
pub fn new_with_path(path: impl AsRef<Path>, ext: EXT) -> Result<Self, StorageError> {
136140
let node_meta = Meta::new_for_nodes();
137141
let edge_meta = Meta::new_for_edges();
138-
let graph_meta = GraphMeta::new();
142+
let graph_meta = Meta::new_for_graph();
139143

140-
Self::new_with_meta(Some(path.as_ref().into()), node_meta, edge_meta, graph_meta, ext)
144+
Self::new_with_meta(
145+
Some(path.as_ref().into()),
146+
node_meta,
147+
edge_meta,
148+
graph_meta,
149+
ext,
150+
)
141151
}
142152

143153
pub fn load_from_path(path: impl AsRef<Path>) -> Result<Self, StorageError> {
@@ -164,7 +174,7 @@ impl<EXT: PersistentStrategy<NS = NS<EXT>, ES = ES<EXT>>> TemporalGraph<EXT> {
164174
graph_dir: Option<GraphDir>,
165175
node_meta: Meta,
166176
edge_meta: Meta,
167-
graph_meta: GraphMeta,
177+
graph_meta: Meta,
168178
ext: EXT,
169179
) -> Result<Self, StorageError> {
170180
let mut graph_dir = graph_dir;
@@ -238,10 +248,6 @@ impl<EXT: PersistentStrategy<NS = NS<EXT>, ES = ES<EXT>>> TemporalGraph<EXT> {
238248
}
239249
}
240250

241-
pub fn graph_entry(&self) -> <GS as GraphSegmentOps>::Entry<'_> {
242-
self.storage().graph().graph_entry()
243-
}
244-
245251
#[inline]
246252
pub fn internal_num_nodes(&self) -> usize {
247253
self.logical_to_physical.len()
@@ -264,7 +270,7 @@ impl<EXT: PersistentStrategy<NS = NS<EXT>, ES = ES<EXT>>> TemporalGraph<EXT> {
264270
self.storage().node_meta()
265271
}
266272

267-
pub fn graph_meta(&self) -> &GraphMeta {
273+
pub fn graph_meta(&self) -> &Meta {
268274
self.storage.graph_meta()
269275
}
270276

db4-storage/src/api/graph.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
use crate::error::StorageError;
2-
use crate::segments::graph::segment::MemGraphSegment;
2+
use crate::segments::graph::segment::MemGraphProps;
33
use parking_lot::{RwLockReadGuard, RwLockWriteGuard};
4+
use raphtory_api::core::entities::properties::meta::Meta;
45
use raphtory_api::core::entities::properties::prop::Prop;
56
use raphtory_api::core::entities::properties::tprop::TPropOps;
67
use std::fmt::Debug;
78
use std::path::Path;
9+
use std::sync::Arc;
810

9-
pub trait GraphSegmentOps: Send + Sync + Debug + 'static
11+
pub trait GraphPropOps: Send + Sync + Debug + 'static
1012
where
1113
Self: Sized,
1214
{
15+
type Extension;
16+
1317
type Entry<'a>: GraphEntryOps<'a>;
1418

15-
fn new(path: Option<&Path>) -> Self;
19+
fn new(meta: Arc<Meta>, path: Option<&Path>, ext: Self::Extension) -> Self;
1620

17-
fn load(path: impl AsRef<Path>) -> Result<Self, StorageError>;
21+
fn load(
22+
meta: Arc<Meta>,
23+
path: impl AsRef<Path>,
24+
ext: Self::Extension,
25+
) -> Result<Self, StorageError>;
1826

19-
fn head(&self) -> RwLockReadGuard<'_, MemGraphSegment>;
27+
fn head(&self) -> RwLockReadGuard<'_, MemGraphProps>;
2028

21-
fn head_mut(&self) -> RwLockWriteGuard<'_, MemGraphSegment>;
29+
fn head_mut(&self) -> RwLockWriteGuard<'_, MemGraphProps>;
2230

2331
fn entry(&self) -> Self::Entry<'_>;
2432

db4-storage/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ use crate::{
1717
persist::strategy::NoOpStrategy,
1818
resolver::mapping_resolver::MappingResolver,
1919
segments::{
20-
edge::entry::{MemEdgeEntry, MemEdgeRef},
21-
edge::segment::EdgeSegmentView,
20+
edge::{
21+
entry::{MemEdgeEntry, MemEdgeRef},
22+
segment::EdgeSegmentView,
23+
},
2224
graph::entry::MemGraphEntry,
23-
node::entry::{MemNodeEntry, MemNodeRef},
24-
node::segment::NodeSegmentView,
25+
node::{
26+
entry::{MemNodeEntry, MemNodeRef},
27+
segment::NodeSegmentView,
28+
},
2529
},
2630
wal::no_wal::NoWal,
2731
};

db4-storage/src/pages/graph_page/writer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
use crate::{api::graph::GraphSegmentOps, segments::graph::segment::MemGraphSegment};
1+
use crate::{api::graph::GraphPropOps, segments::graph::segment::MemGraphProps};
22
use parking_lot::RwLockWriteGuard;
33
use raphtory_api::core::entities::properties::prop::Prop;
44
use raphtory_core::storage::timeindex::TimeIndexEntry;
55

66
/// Provides mutable access to a graph segment. Holds an exclusive write lock
77
/// on the in-memory segment for the duration of its lifetime.
8-
pub struct GraphWriter<'a, GS: GraphSegmentOps> {
9-
pub mem_segment: RwLockWriteGuard<'a, MemGraphSegment>,
8+
pub struct GraphWriter<'a, GS: GraphPropOps> {
9+
pub mem_segment: RwLockWriteGuard<'a, MemGraphProps>,
1010
pub graph_props: &'a GS,
1111
}
1212

13-
impl<'a, GS: GraphSegmentOps> GraphWriter<'a, GS> {
14-
pub fn new(graph_props: &'a GS, mem_segment: RwLockWriteGuard<'a, MemGraphSegment>) -> Self {
13+
impl<'a, GS: GraphPropOps> GraphWriter<'a, GS> {
14+
pub fn new(graph_props: &'a GS, mem_segment: RwLockWriteGuard<'a, MemGraphProps>) -> Self {
1515
Self {
1616
mem_segment,
1717
graph_props,
@@ -25,7 +25,7 @@ impl<'a, GS: GraphSegmentOps> GraphWriter<'a, GS> {
2525
lsn: u64,
2626
) {
2727
let add = self.mem_segment.add_properties(t, props);
28-
self.mem_segment.as_mut()[MemGraphSegment::LAYER].set_lsn(lsn);
28+
self.mem_segment.as_mut()[MemGraphProps::LAYER].set_lsn(lsn);
2929
self.graph_props.increment_est_size(add);
3030
}
3131

@@ -35,7 +35,7 @@ impl<'a, GS: GraphSegmentOps> GraphWriter<'a, GS> {
3535

3636
pub fn update_metadata(&mut self, props: impl IntoIterator<Item = (usize, Prop)>, lsn: u64) {
3737
let add = self.mem_segment.update_metadata(props);
38-
self.mem_segment.as_mut()[MemGraphSegment::LAYER].set_lsn(lsn);
38+
self.mem_segment.as_mut()[MemGraphProps::LAYER].set_lsn(lsn);
3939
self.graph_props.increment_est_size(add);
4040
}
4141
}

db4-storage/src/pages/graph_store.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
1-
use crate::api::graph::GraphSegmentOps;
1+
use raphtory_api::core::entities::properties::meta::Meta;
2+
3+
use crate::api::graph::GraphPropOps;
24
use crate::error::StorageError;
35
use crate::pages::graph_page::writer::GraphWriter;
46
use crate::persist::strategy::Config;
5-
use raphtory_core::entities::properties::graph_meta::GraphMeta;
7+
68
use std::path::{Path, PathBuf};
79
use std::sync::Arc;
810

911
/// Backing store for graph temporal properties and graph metadata.
1012
#[derive(Debug)]
11-
pub struct GraphStorageInner<GS, EXT> {
13+
pub struct GraphPropsInner<GS, EXT> {
1214
/// The graph segment that contains all graph properties and graph metadata.
1315
/// Unlike node and edge segments, which are split into multiple segments,
1416
/// there is always only one graph segment.
1517
page: Arc<GS>,
1618

1719
/// Stores graph prop metadata (prop name -> prop id mappings, etc).
18-
graph_meta: Arc<GraphMeta>,
20+
graph_meta: Arc<Meta>,
1921

2022
path: Option<PathBuf>,
2123

2224
ext: EXT,
2325
}
2426

25-
impl<GS: GraphSegmentOps, EXT: Config> GraphStorageInner<GS, EXT> {
26-
pub fn new(path: Option<&Path>, ext: EXT) -> Self {
27-
let page = Arc::new(GS::new(path));
28-
let graph_meta = Arc::new(GraphMeta::new());
29-
30-
Self {
31-
page,
32-
path: path.map(|p| p.to_path_buf()),
33-
graph_meta,
34-
ext,
35-
}
36-
}
37-
38-
pub fn new_with_meta(path: Option<&Path>, graph_meta: Arc<GraphMeta>, ext: EXT) -> Self {
39-
let page = Arc::new(GS::new(path));
27+
impl<GS: GraphPropOps<Extension = EXT>, EXT: Config> GraphPropsInner<GS, EXT> {
28+
pub fn new_with_meta(path: Option<&Path>, graph_meta: Arc<Meta>, ext: EXT) -> Self {
29+
let page = Arc::new(GS::new(graph_meta.clone(), path, ext.clone()));
4030

4131
Self {
4232
page,
@@ -47,17 +37,16 @@ impl<GS: GraphSegmentOps, EXT: Config> GraphStorageInner<GS, EXT> {
4737
}
4838

4939
pub fn load(path: impl AsRef<Path>, ext: EXT) -> Result<Self, StorageError> {
50-
let graph_meta = Arc::new(GraphMeta::new());
51-
40+
let graph_meta = Arc::new(Meta::new_for_graph());
5241
Ok(Self {
53-
page: Arc::new(GS::load(path.as_ref())?),
42+
page: Arc::new(GS::load(graph_meta.clone(), path.as_ref(), ext.clone())?),
5443
path: Some(path.as_ref().to_path_buf()),
5544
graph_meta,
5645
ext,
5746
})
5847
}
5948

60-
pub fn graph_meta(&self) -> &Arc<GraphMeta> {
49+
pub fn graph_meta(&self) -> &Arc<Meta> {
6150
&self.graph_meta
6251
}
6352

db4-storage/src/pages/mod.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
use crate::{
2-
api::{edges::EdgeSegmentOps, graph::GraphSegmentOps, nodes::NodeSegmentOps},
3-
error::StorageError, pages::{edge_store::ReadLockedEdgeStorage, node_store::ReadLockedNodeStorage},
2+
LocalPOS,
3+
api::{edges::EdgeSegmentOps, graph::GraphPropOps, nodes::NodeSegmentOps},
4+
error::StorageError,
5+
pages::{edge_store::ReadLockedEdgeStorage, node_store::ReadLockedNodeStorage},
46
persist::strategy::{Config, PersistentStrategy},
57
properties::props_meta_writer::PropsMetaWriter,
68
segments::{edge::segment::MemEdgeSegment, node::segment::MemNodeSegment},
7-
LocalPOS,
89
};
910
use edge_page::writer::EdgeWriter;
1011
use edge_store::EdgeStorageInner;
12+
use graph_store::GraphPropsInner;
1113
use node_page::writer::{NodeWriter, WriterPair};
1214
use node_store::NodeStorageInner;
13-
use graph_store::GraphStorageInner;
1415
use parking_lot::RwLockWriteGuard;
1516
use raphtory_api::core::{
1617
entities::properties::{meta::Meta, prop::Prop},
1718
storage::dict_mapper::MaybeNew,
1819
};
20+
1921
use raphtory_core::{
2022
entities::{EID, ELID, VID},
2123
storage::timeindex::TimeIndexEntry,
@@ -29,17 +31,16 @@ use std::{
2931
atomic::{self, AtomicUsize},
3032
},
3133
};
32-
use raphtory_core::entities::properties::graph_meta::GraphMeta;
3334

3435
pub mod edge_page;
3536
pub mod edge_store;
37+
pub mod graph_page;
38+
pub mod graph_store;
3639
pub mod layer_counter;
3740
pub mod locked;
3841
pub mod node_page;
3942
pub mod node_store;
4043
pub mod session;
41-
pub mod graph_page;
42-
pub mod graph_store;
4344
#[cfg(any(test, feature = "test-utils"))]
4445
pub mod test_utils;
4546

@@ -49,7 +50,7 @@ pub mod test_utils;
4950
pub struct GraphStore<NS, ES, GS, EXT: Config> {
5051
nodes: Arc<NodeStorageInner<NS, EXT>>,
5152
edges: Arc<EdgeStorageInner<ES, EXT>>,
52-
graph: Arc<GraphStorageInner<GS, EXT>>,
53+
graph: Arc<GraphPropsInner<GS, EXT>>,
5354
graph_dir: Option<PathBuf>,
5455
event_id: AtomicUsize,
5556
_ext: EXT,
@@ -59,7 +60,7 @@ pub struct GraphStore<NS, ES, GS, EXT: Config> {
5960
pub struct ReadLockedGraphStore<
6061
NS: NodeSegmentOps<Extension = EXT>,
6162
ES: EdgeSegmentOps<Extension = EXT>,
62-
GS: GraphSegmentOps,
63+
GS: GraphPropOps<Extension = EXT>,
6364
EXT: Config,
6465
> {
6566
pub nodes: Arc<ReadLockedNodeStorage<NS, EXT>>,
@@ -70,7 +71,7 @@ pub struct ReadLockedGraphStore<
7071
impl<
7172
NS: NodeSegmentOps<Extension = EXT>,
7273
ES: EdgeSegmentOps<Extension = EXT>,
73-
GS: GraphSegmentOps,
74+
GS: GraphPropOps<Extension = EXT>,
7475
EXT: PersistentStrategy,
7576
> GraphStore<NS, ES, GS, EXT>
7677
{
@@ -97,7 +98,7 @@ impl<
9798
&self.edges
9899
}
99100

100-
pub fn graph(&self) -> &Arc<GraphStorageInner<GS, EXT>> {
101+
pub fn graph_props(&self) -> &Arc<GraphPropsInner<GS, EXT>> {
101102
&self.graph
102103
}
103104

@@ -109,7 +110,7 @@ impl<
109110
self.nodes.prop_meta()
110111
}
111112

112-
pub fn graph_meta(&self) -> &GraphMeta {
113+
pub fn graph_meta(&self) -> &Meta {
113114
self.graph.graph_meta()
114115
}
115116

@@ -137,7 +138,7 @@ impl<
137138
let node_meta = node_storage.prop_meta();
138139

139140
// Load graph temporal properties and metadata
140-
let graph_storage = Arc::new(GraphStorageInner::load(graph_path, ext.clone())?);
141+
let graph_storage = Arc::new(GraphPropsInner::load(graph_path, ext.clone())?);
141142

142143
for node_type in ext.node_types().iter() {
143144
node_meta.get_or_create_node_type_id(node_type);
@@ -159,7 +160,7 @@ impl<
159160
graph_dir: Option<&Path>,
160161
node_meta: Meta,
161162
edge_meta: Meta,
162-
graph_meta: GraphMeta,
163+
graph_meta: Meta,
163164
ext: EXT,
164165
) -> Self {
165166
let nodes_path = graph_dir.map(|graph_dir| graph_dir.join("nodes"));
@@ -181,14 +182,15 @@ impl<
181182
edge_meta,
182183
ext.clone(),
183184
));
184-
let graph_storage = Arc::new(GraphStorageInner::new_with_meta(
185+
let graph_storage = Arc::new(GraphPropsInner::new_with_meta(
185186
graph_path.as_deref(),
186187
graph_meta,
187188
ext.clone(),
188189
));
189190

190191
if let Some(graph_dir) = graph_dir {
191-
write_graph_config(graph_dir, &ext).expect("Unrecoverable! Failed to write graph config");
192+
write_graph_config(graph_dir, &ext)
193+
.expect("Unrecoverable! Failed to write graph config");
192194
}
193195

194196
Self {
@@ -204,7 +206,7 @@ impl<
204206
pub fn new(graph_dir: Option<&Path>, ext: EXT) -> Self {
205207
let node_meta = Meta::new_for_nodes();
206208
let edge_meta = Meta::new_for_edges();
207-
let graph_meta = GraphMeta::new();
209+
let graph_meta = Meta::new_for_graph();
208210

209211
Self::new_with_meta(graph_dir, node_meta, edge_meta, graph_meta, ext)
210212
}

0 commit comments

Comments
 (0)