Skip to content

Commit ae5b3c7

Browse files
committed
Merge branch 'master'
2 parents 61d24cd + b5ef25b commit ae5b3c7

File tree

16 files changed

+817
-644
lines changed

16 files changed

+817
-644
lines changed

lib/src/database.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// lib/src/database.rs
2-
// Corrected: 2025-07-02 - Final version ensuring correct trait usage and error handling.
3-
// Fixed: 2025-07-02 - Corrected import for SledStorage and RocksDBStorage, and models crate.
2+
// Refactored: 2025-07-04 - Updated to use new InMemoryGraphStorage and RocksdbGraphStorage.
43

54
use std::sync::Arc;
6-
// Corrected imports for SledStorage and RocksDBStorage to use their full paths
5+
6+
// Import the refactored storage engines
77
use crate::storage_engine::{GraphStorageEngine, StorageConfig, StorageEngineType, open_sled_db};
88
use crate::storage_engine::sled_storage::SledStorage; // Explicitly import SledStorage
99
#[cfg(feature = "with-rocksdb")] // Apply cfg to the import itself
10-
use crate::storage_engine::rocksdb_storage::RocksDBStorage; // Explicitly import RocksDBStorage
10+
use crate::storage_engine::rocksdb_storage::RocksdbGraphStorage; // Explicitly import RocksdbGraphStorage
11+
use crate::memory::InMemoryGraphStorage; // Import the new in-memory storage
1112

12-
// Corrected import for models crate (it's a separate crate, not a module within `crate`)
1313
use models::{Vertex, Edge, Identifier};
1414
use models::errors::{GraphError, GraphResult}; // Use GraphResult directly
1515
use uuid::Uuid;
@@ -28,7 +28,7 @@ pub struct Database {
2828
impl Database {
2929
/// Creates a new database instance based on the provided storage configuration.
3030
///
31-
/// This function initializes and starts the chosen storage engine (Sled or RocksDB).
31+
/// This function initializes and starts the chosen storage engine (Sled, RocksDB, or In-Memory).
3232
///
3333
/// # Arguments
3434
/// * `config`: The configuration for the storage engine.
@@ -38,15 +38,13 @@ impl Database {
3838
pub async fn new(config: StorageConfig) -> GraphResult<Self> {
3939
let storage_engine: Arc<dyn GraphStorageEngine> = match config.engine_type {
4040
StorageEngineType::Sled => {
41-
// Open Sled DB and create SledStorage
4241
let db = open_sled_db(&config.data_path)?;
4342
Arc::new(SledStorage::new(db)?)
4443
},
4544
StorageEngineType::RocksDB => {
46-
// Conditionally compile RocksDB initialization if the feature is enabled
4745
#[cfg(feature = "with-rocksdb")]
4846
{
49-
Arc::new(RocksDBStorage::new(&config)?)
47+
Arc::new(RocksdbGraphStorage::new(&config)?)
5048
}
5149
#[cfg(not(feature = "with-rocksdb"))]
5250
{
@@ -56,6 +54,9 @@ impl Database {
5654
));
5755
}
5856
},
57+
StorageEngineType::InMemory => { // Added InMemory option
58+
Arc::new(InMemoryGraphStorage::new_with_path(&config.data_path))
59+
}
5960
// Add other storage types here as they are implemented (e.g., PostgreSQL, Redis)
6061
_ => return Err(GraphError::ConfigError(
6162
format!("Unsupported storage engine type: {:?}", config.engine_type)

lib/src/lib.rs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// lib/src/lib.rs
2-
// Updated: 2025-07-02 - Refactored to use the new 'models' crate for shared types.
3-
// Corrected unresolved imports for SledUserStorage and UserStorageEngine.
2+
// Updated: 2025-07-04 - Refactored to use new storage engine names and removed obsolete imports.
43

54
#![cfg_attr(feature = "bench-suite", feature(test))]
65

@@ -10,24 +9,23 @@ pub mod graph_evolution;
109
pub mod network_interfaces;
1110
pub mod plugin_system;
1211
pub mod database;
13-
pub mod memory;
14-
// REMOVED: pub mod models; // Models are now in a separate crate!
12+
pub mod memory; // Now contains InMemoryGraphStorage
1513
pub mod errors;
1614
pub mod query_exec_engine;
1715
pub mod storage_engine; // This declares the directory `storage_engine`
1816
pub mod transact_indexing;
1917
pub mod indexing_caching;
2018
pub mod util;
2119

20+
// REMOVED: pub mod rdb; // Obsolete after RocksDB consolidation
21+
2222
// Now, import directly from the 'models' crate.
23-
// Ensure these are correctly named based on what `models/src/lib.rs` re-exports.
24-
// For instance, if models::edges::Edge is simply re-exported as models::Edge, then `models::Edge` is correct.
25-
pub use models::{Edge, Identifier, Json};
23+
pub use models::{Edge, Identifier, Json, Vertex}; // Added Vertex here for convenience
2624

2725
// Fix the imports by specifying the correct sub-modules
2826
pub use models::bulk_insert::BulkInsertItem;
29-
pub use models::queries::EdgeDirection; // CORRECTED PATH (as per previous fix)
30-
pub use models::properties::{EdgeProperties, NamedProperty, PropertyValue, VertexProperties}; // Keep this one for PropertyValue
27+
pub use models::queries::EdgeDirection;
28+
pub use models::properties::{EdgeProperties, NamedProperty, PropertyValue, VertexProperties};
3129
pub use models::queries::{Query, QueryOutputValue};
3230
pub use models::medical::{Login, User};
3331

@@ -44,16 +42,14 @@ pub mod benches;
4442

4543
// Explicit re-exports
4644
pub use crate::indexing_caching::{index_node, cache_node_state, get_cached_node_state};
47-
pub use crate::database::*;
45+
pub use crate::database::*; // Re-exports the main Database struct
4846
pub use crate::errors::*;
49-
pub use crate::memory::*;
50-
// REMOVED: pub use models::PropertyValue; // <-- REMOVED THIS DUPLICATE LINE
47+
pub use crate::memory::InMemoryGraphStorage; // Re-export the new in-memory storage
5148

52-
// Re-export from storage_engine/mod.rs
53-
// Removed SledUserStorage and UserStorageEngine as their definitions/re-exports are not available.
54-
// If these are needed, ensure they are correctly defined and re-exported in storage_engine/mod.rs
55-
// and storage_engine/user_storage.rs
49+
// Re-export from storage_engine/mod.rs (assuming it exists and re-exports these)
5650
pub use crate::storage_engine::{open_sled_db, StorageEngine, GraphStorageEngine};
51+
#[cfg(feature = "with-rocksdb")]
52+
pub use crate::storage_engine::rocksdb_storage::RocksdbGraphStorage; // Re-export the new RocksDB storage
5753

5854

5955
// Do NOT glob-import engine and models together to avoid ambiguity
@@ -63,33 +59,29 @@ pub mod api {
6359
Graph,
6460
Edge as EngineEdge,
6561
Vertex as EngineVertex,
66-
// CHECK THIS: If `engine::properties::PropertyValue` is distinct from `models::properties::PropertyValue`
67-
// and needs to be exposed here. If not, consider removing or aliasing appropriately.
68-
properties::PropertyValue as EnginePropertyValue // Aliased to avoid conflict if both exist
62+
properties::PropertyValue as EnginePropertyValue
6963
};
70-
// Now, import ModelEdge, ModelVertex, Identifier, Json from the new `models` crate
71-
pub use models::{ // Already imported at the top, just re-exporting under `api`
64+
pub use models::{
7265
Edge as ModelEdge,
7366
Vertex as ModelVertex,
7467
Identifier,
7568
Json
7669
};
7770
}
7871

79-
#[cfg(feature = "sled-datastore")]
80-
pub mod sled; // This declares the 'sled' module, referring to src/sled/managers.rs (implicitly)
81-
82-
#[cfg(feature = "sled-datastore")]
83-
// Assuming your main Sled manager struct is named SledManager
84-
// and you want to re-export it as 'SledDatastore' for consistency with the previous name
85-
pub use crate::sled::managers::SledManager as SledDatastore;
86-
87-
// If you had a mechanism to choose between datastores based on feature,
88-
// you might then have a type alias or a trait implementation somewhere that uses it:
89-
90-
// #[cfg(feature = "rocksdb-datastore")]
91-
// pub type CurrentDatastore = RocksdbDatastore;
92-
93-
#[cfg(feature = "sled-datastore")]
94-
pub type CurrentDatastore = SledDatastore;
72+
// The 'sled' module and 'SledDatastore' alias are likely obsolete if SledStorage
73+
// is directly used via `storage_engine`. Remove if not needed.
74+
// #[cfg(feature = "sled-datastore")]
75+
// pub mod sled; // This declares the 'sled' module, referring to src/sled/managers.rs (implicitly)
76+
// #[cfg(feature = "sled-datastore")]
77+
// pub use crate::sled::managers::SledManager as SledDatastore;
78+
79+
// Type alias for CurrentDatastore, now using GraphStorageEngine implementations
80+
#[cfg(feature = "with-rocksdb")]
81+
pub type CurrentGraphStorage = RocksdbGraphStorage; // If RocksDB is enabled, use it
82+
#[cfg(not(feature = "with-rocksdb"))]
83+
pub type CurrentGraphStorage = InMemoryGraphStorage; // Otherwise, default to in-memory (or Sled if preferred)
84+
85+
// You might also want a default for when no feature is enabled, e.g.:
86+
// pub type CurrentGraphStorage = SledStorage; // Assuming Sled is always available
9587

0 commit comments

Comments
 (0)