Skip to content

Commit 41e0a2f

Browse files
committed
Pass in GS as a generic
1 parent 133944b commit 41e0a2f

File tree

6 files changed

+43
-41
lines changed

6 files changed

+43
-41
lines changed

db4-storage/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ pub type Extension = NoOpStrategy;
4646
pub type NS<P> = NodeSegmentView<P>;
4747
pub type ES<P> = EdgeSegmentView<P>;
4848
pub type GS = GraphSegmentView;
49-
pub type Layer<P> = GraphStore<NS<P>, ES<P>, P>;
49+
pub type Layer<P> = GraphStore<NS<P>, ES<P>, GS, P>;
5050

5151
pub type WalImpl = NoWal;
5252
pub type GIDResolver = MappingResolver;
5353

54-
pub type ReadLockedLayer<P> = ReadLockedGraphStore<NS<P>, ES<P>, P>;
54+
pub type ReadLockedLayer<P> = ReadLockedGraphStore<NS<P>, ES<P>, GS, P>;
5555
pub type ReadLockedNodes<P> = ReadLockedNodeStorage<NS<P>, P>;
5656
pub type ReadLockedEdges<P> = ReadLockedEdgeStorage<ES<P>, P>;
5757

db4-storage/src/pages/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use crate::{
2-
LocalPOS,
3-
api::{edges::EdgeSegmentOps, nodes::NodeSegmentOps},
4-
error::StorageError,
5-
pages::{edge_store::ReadLockedEdgeStorage, node_store::ReadLockedNodeStorage},
2+
api::{edges::EdgeSegmentOps, graph::GraphSegmentOps, nodes::NodeSegmentOps},
3+
error::StorageError, pages::{edge_store::ReadLockedEdgeStorage, node_store::ReadLockedNodeStorage},
64
persist::strategy::{Config, PersistentStrategy},
75
properties::props_meta_writer::PropsMetaWriter,
86
segments::{edge::segment::MemEdgeSegment, node::segment::MemNodeSegment},
9-
GS,
7+
LocalPOS,
108
};
119
use edge_page::writer::EdgeWriter;
1210
use edge_store::EdgeStorageInner;
@@ -47,7 +45,7 @@ pub mod test_utils;
4745
// graph // (node/edges) // segment // layer_ids (0, 1, 2, ...) // actual graphy bits
4846

4947
#[derive(Debug)]
50-
pub struct GraphStore<NS, ES, EXT: Config> {
48+
pub struct GraphStore<NS, ES, GS, EXT: Config> {
5149
nodes: Arc<NodeStorageInner<NS, EXT>>,
5250
edges: Arc<EdgeStorageInner<ES, EXT>>,
5351
graph: Arc<GraphStorageInner<GS, EXT>>,
@@ -60,20 +58,22 @@ pub struct GraphStore<NS, ES, EXT: Config> {
6058
pub struct ReadLockedGraphStore<
6159
NS: NodeSegmentOps<Extension = EXT>,
6260
ES: EdgeSegmentOps<Extension = EXT>,
61+
GS: GraphSegmentOps,
6362
EXT: Config,
6463
> {
6564
pub nodes: Arc<ReadLockedNodeStorage<NS, EXT>>,
6665
pub edges: Arc<ReadLockedEdgeStorage<ES, EXT>>,
67-
pub graph: Arc<GraphStore<NS, ES, EXT>>,
66+
pub graph: Arc<GraphStore<NS, ES, GS, EXT>>,
6867
}
6968

7069
impl<
7170
NS: NodeSegmentOps<Extension = EXT>,
7271
ES: EdgeSegmentOps<Extension = EXT>,
72+
GS: GraphSegmentOps,
7373
EXT: PersistentStrategy,
74-
> GraphStore<NS, ES, EXT>
74+
> GraphStore<NS, ES, GS, EXT>
7575
{
76-
pub fn read_locked(self: &Arc<Self>) -> ReadLockedGraphStore<NS, ES, EXT> {
76+
pub fn read_locked(self: &Arc<Self>) -> ReadLockedGraphStore<NS, ES, GS, EXT> {
7777
let nodes = self.nodes.locked().into();
7878
let edges = self.edges.locked().into();
7979

@@ -342,7 +342,7 @@ impl<
342342
src: VID,
343343
dst: VID,
344344
e_id: Option<EID>,
345-
) -> WriteSession<'_, NS, ES, EXT> {
345+
) -> WriteSession<'_, NS, ES, GS, EXT> {
346346
let (src_chunk, _) = self.nodes.resolve_pos(src);
347347
let (dst_chunk, _) = self.nodes.resolve_pos(dst);
348348

@@ -375,7 +375,7 @@ impl<
375375
src: VID,
376376
dst: VID,
377377
e_id: Option<EID>,
378-
) -> WriteSession<'_, NS, ES, EXT> {
378+
) -> WriteSession<'_, NS, ES, GS, EXT> {
379379
let (src_chunk, _) = self.nodes.resolve_pos(src);
380380
let (dst_chunk, _) = self.nodes.resolve_pos(dst);
381381

@@ -422,7 +422,7 @@ impl<
422422
}
423423
}
424424

425-
impl<NS, ES, EXT: Config> Drop for GraphStore<NS, ES, EXT> {
425+
impl<NS, ES, GS, EXT: Config> Drop for GraphStore<NS, ES, GS, EXT> {
426426
fn drop(&mut self) {
427427
let node_types = self.nodes.prop_meta().get_all_node_types();
428428
self._ext.set_node_types(node_types);

db4-storage/src/pages/session.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ use super::{
22
GraphStore, edge_page::writer::EdgeWriter, node_page::writer::WriterPair, resolve_pos,
33
};
44
use crate::{
5-
LocalPOS,
6-
api::{edges::EdgeSegmentOps, nodes::NodeSegmentOps},
7-
persist::strategy::{Config, PersistentStrategy},
8-
segments::{edge::segment::MemEdgeSegment, node::segment::MemNodeSegment},
5+
api::{edges::EdgeSegmentOps, graph::GraphSegmentOps, nodes::NodeSegmentOps}, persist::strategy::{Config, PersistentStrategy}, segments::{edge::segment::MemEdgeSegment, node::segment::MemNodeSegment}, LocalPOS
96
};
107
use parking_lot::RwLockWriteGuard;
118
use raphtory_api::core::{entities::properties::prop::Prop, storage::dict_mapper::MaybeNew};
@@ -14,23 +11,24 @@ use raphtory_core::{
1411
storage::timeindex::AsTime,
1512
};
1613

17-
pub struct WriteSession<'a, NS: NodeSegmentOps, ES: EdgeSegmentOps, EXT: Config> {
14+
pub struct WriteSession<'a, NS: NodeSegmentOps, ES: EdgeSegmentOps, GS: GraphSegmentOps, EXT: Config> {
1815
node_writers: WriterPair<'a, RwLockWriteGuard<'a, MemNodeSegment>, NS>,
1916
edge_writer: Option<EdgeWriter<'a, RwLockWriteGuard<'a, MemEdgeSegment>, ES>>,
20-
graph: &'a GraphStore<NS, ES, EXT>,
17+
graph: &'a GraphStore<NS, ES, GS, EXT>,
2118
}
2219

2320
impl<
2421
'a,
2522
NS: NodeSegmentOps<Extension = EXT>,
2623
ES: EdgeSegmentOps<Extension = EXT>,
24+
GS: GraphSegmentOps,
2725
EXT: PersistentStrategy,
28-
> WriteSession<'a, NS, ES, EXT>
26+
> WriteSession<'a, NS, ES, GS, EXT>
2927
{
3028
pub fn new(
3129
node_writers: WriterPair<'a, RwLockWriteGuard<'a, MemNodeSegment>, NS>,
3230
edge_writer: Option<EdgeWriter<'a, RwLockWriteGuard<'a, MemEdgeSegment>, ES>>,
33-
graph: &'a GraphStore<NS, ES, EXT>,
31+
graph: &'a GraphStore<NS, ES, GS, EXT>,
3432
) -> Self {
3533
Self {
3634
node_writers,

db4-storage/src/pages/test_utils/checkers.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
api::{
1616
edges::{EdgeEntryOps, EdgeRefOps, EdgeSegmentOps},
1717
nodes::{NodeEntryOps, NodeRefOps, NodeSegmentOps},
18+
graph::GraphSegmentOps,
1819
},
1920
error::StorageError,
2021
pages::GraphStore,
@@ -26,12 +27,13 @@ use super::fixtures::{AddEdge, Fixture, NodeFixture};
2627
pub fn check_edges_support<
2728
NS: NodeSegmentOps<Extension = EXT>,
2829
ES: EdgeSegmentOps<Extension = EXT>,
30+
GS: GraphSegmentOps,
2931
EXT: PersistentStrategy,
3032
>(
3133
edges: Vec<(impl Into<VID>, impl Into<VID>, Option<usize>)>, // src, dst, optional layer_id
3234
par_load: bool,
3335
check_load: bool,
34-
make_graph: impl FnOnce(&Path) -> GraphStore<NS, ES, EXT>,
36+
make_graph: impl FnOnce(&Path) -> GraphStore<NS, ES, GS, EXT>,
3537
) {
3638
let mut edges = edges
3739
.into_iter()
@@ -103,11 +105,12 @@ pub fn check_edges_support<
103105
fn check<
104106
NS: NodeSegmentOps<Extension = EXT>,
105107
ES: EdgeSegmentOps<Extension = EXT>,
108+
GS: GraphSegmentOps,
106109
EXT: PersistentStrategy,
107110
>(
108111
stage: &str,
109112
expected_edges: &[(VID, VID, Option<usize>)], // (src, dst, layer_id)
110-
graph: &GraphStore<NS, ES, EXT>,
113+
graph: &GraphStore<NS, ES, GS, EXT>,
111114
) {
112115
let nodes = graph.nodes();
113116
let edges = graph.edges();
@@ -189,7 +192,7 @@ pub fn check_edges_support<
189192
if check_load {
190193
drop(graph);
191194

192-
let maybe_ns = GraphStore::<NS, ES, EXT>::load(graph_dir.path());
195+
let maybe_ns = GraphStore::<NS, ES, GS, EXT>::load(graph_dir.path());
193196

194197
match maybe_ns {
195198
Ok(graph) => {
@@ -206,10 +209,11 @@ pub fn check_graph_with_nodes_support<
206209
EXT: PersistentStrategy,
207210
NS: NodeSegmentOps<Extension = EXT>,
208211
ES: EdgeSegmentOps<Extension = EXT>,
212+
GS: GraphSegmentOps,
209213
>(
210214
fixture: &NodeFixture,
211215
check_load: bool,
212-
make_graph: impl FnOnce(&Path) -> GraphStore<NS, ES, EXT>,
216+
make_graph: impl FnOnce(&Path) -> GraphStore<NS, ES, GS, EXT>,
213217
) {
214218
let NodeFixture {
215219
temp_props,
@@ -234,7 +238,7 @@ pub fn check_graph_with_nodes_support<
234238

235239
let check_fn = |temp_props: &[(VID, i64, Vec<(String, Prop)>)],
236240
const_props: &[(VID, Vec<(String, Prop)>)],
237-
graph: &GraphStore<NS, ES, EXT>| {
241+
graph: &GraphStore<NS, ES, GS, EXT>| {
238242
let mut ts_for_nodes = HashMap::new();
239243
for (node, t, _) in temp_props {
240244
ts_for_nodes.entry(*node).or_insert_with(Vec::new).push(*t);
@@ -331,7 +335,7 @@ pub fn check_graph_with_nodes_support<
331335

332336
if check_load {
333337
drop(graph);
334-
let graph = GraphStore::<NS, ES, EXT>::load(graph_dir.path()).unwrap();
338+
let graph = GraphStore::<NS, ES, GS, EXT>::load(graph_dir.path()).unwrap();
335339
check_fn(temp_props, const_props, &graph);
336340
}
337341
}
@@ -340,10 +344,11 @@ pub fn check_graph_with_props_support<
340344
EXT: PersistentStrategy,
341345
NS: NodeSegmentOps<Extension = EXT>,
342346
ES: EdgeSegmentOps<Extension = EXT>,
347+
GS: GraphSegmentOps,
343348
>(
344349
fixture: &Fixture,
345350
check_load: bool,
346-
make_graph: impl FnOnce(&Path) -> GraphStore<NS, ES, EXT>,
351+
make_graph: impl FnOnce(&Path) -> GraphStore<NS, ES, GS, EXT>,
347352
) {
348353
let Fixture { edges, const_props } = fixture;
349354
let graph_dir = tempfile::tempdir().unwrap();
@@ -374,7 +379,7 @@ pub fn check_graph_with_props_support<
374379

375380
black_box(assert!(graph.edges().num_edges() > 0));
376381

377-
let check_fn = |edges: &[AddEdge], graph: &GraphStore<NS, ES, EXT>| {
382+
let check_fn = |edges: &[AddEdge], graph: &GraphStore<NS, ES, GS, EXT>| {
378383
let mut edge_groups = HashMap::new();
379384
let mut node_groups: HashMap<VID, Vec<i64>> = HashMap::new();
380385

@@ -485,7 +490,7 @@ pub fn check_graph_with_props_support<
485490
// Load the graph from disk and check again
486491
drop(graph);
487492

488-
let graph = GraphStore::<NS, ES, EXT>::load(graph_dir.path()).unwrap();
493+
let graph = GraphStore::<NS, ES, GS, EXT>::load(graph_dir.path()).unwrap();
489494
black_box(check_fn(edges, &graph));
490495
}
491496
}

db4-storage/src/persist/strategy.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::ops::DerefMut;
33
use serde::{Deserialize, Serialize};
44

55
use crate::segments::{
6-
edge::segment::{EdgeSegmentView, MemEdgeSegment},
7-
node::segment::{MemNodeSegment, NodeSegmentView},
6+
edge::segment::{EdgeSegmentView, MemEdgeSegment}, graph::GraphSegmentView, node::segment::{MemNodeSegment, NodeSegmentView}
87
};
98

109
pub const DEFAULT_MAX_PAGE_LEN_NODES: u32 = 131_072; // 2^17
@@ -23,12 +22,15 @@ pub trait Config:
2322
pub trait PersistentStrategy: Config {
2423
type NS;
2524
type ES;
25+
type GS;
26+
2627
fn persist_node_segment<MP: DerefMut<Target = MemNodeSegment>>(
2728
&self,
2829
node_page: &Self::NS,
2930
writer: MP,
3031
) where
3132
Self: Sized;
33+
3234
fn persist_edge_page<MP: DerefMut<Target = MemEdgeSegment>>(
3335
&self,
3436
edge_page: &Self::ES,
@@ -86,6 +88,7 @@ impl Config for NoOpStrategy {
8688
impl PersistentStrategy for NoOpStrategy {
8789
type ES = EdgeSegmentView<Self>;
8890
type NS = NodeSegmentView<Self>;
91+
type GS = GraphSegmentView;
8992

9093
fn persist_node_segment<MP: DerefMut<Target = MemNodeSegment>>(
9194
&self,

raphtory-storage/src/mutation/addition_ops_ext.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,24 @@ use raphtory_core::{
1515
storage::timeindex::TimeIndexEntry,
1616
};
1717
use storage::{
18-
pages::{node_page::writer::node_info_as_props, session::WriteSession},
19-
persist::strategy::PersistentStrategy,
20-
properties::props_meta_writer::PropsMetaWriter,
21-
resolver::GIDResolverOps,
22-
Extension, WalImpl, ES, NS,
18+
pages::{node_page::writer::node_info_as_props, session::WriteSession}, persist::strategy::PersistentStrategy, properties::props_meta_writer::PropsMetaWriter, resolver::GIDResolverOps, Extension, WalImpl, ES, GS, NS
2319
};
2420

2521
use crate::mutation::{
2622
addition_ops::{EdgeWriteLock, InternalAdditionOps, SessionAdditionOps},
2723
MutationError,
2824
};
2925

30-
pub struct WriteS<'a, EXT: PersistentStrategy<NS = NS<EXT>, ES = ES<EXT>>> {
31-
static_session: WriteSession<'a, NS<EXT>, ES<EXT>, EXT>,
26+
pub struct WriteS<'a, EXT: PersistentStrategy<NS = NS<EXT>, ES = ES<EXT>, GS = GS>> {
27+
static_session: WriteSession<'a, NS<EXT>, ES<EXT>, GS, EXT>,
3228
}
3329

3430
#[derive(Clone, Copy, Debug)]
3531
pub struct UnlockedSession<'a> {
3632
graph: &'a TemporalGraph<Extension>,
3733
}
3834

39-
impl<'a, EXT: PersistentStrategy<NS = NS<EXT>, ES = ES<EXT>>> EdgeWriteLock for WriteS<'a, EXT> {
35+
impl<'a, EXT: PersistentStrategy<NS = NS<EXT>, ES = ES<EXT>, GS = GS>> EdgeWriteLock for WriteS<'a, EXT> {
4036
fn internal_add_static_edge(
4137
&mut self,
4238
src: impl Into<VID>,

0 commit comments

Comments
 (0)