Skip to content

Commit

Permalink
Merge pull request #28 from robsdedude/feat/bolt-5.8-home-db-cache
Browse files Browse the repository at this point in the history
Feat: Bolt 5.8 - home db cache & optimistic routing
  • Loading branch information
robsdedude authored Feb 15, 2025
2 parents aa8628d + 61eaf64 commit 75bac94
Show file tree
Hide file tree
Showing 33 changed files with 1,529 additions and 225 deletions.
20 changes: 19 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@ repos:
hooks:
- id: check
name: cargo check
entry: cargo check --
entry: cargo +stable check --all --tests --
language: system
types: [rust]
pass_filenames: false
- id: check-msrv-all-features
name: cargo check (all features)
entry: cargo +stable check --all --tests --all-features --
language: system
types: [rust]
pass_filenames: false
- id: check-msrv
name: cargo check MSRV
entry: cargo +1.70 check --all --tests --
language: system
types: [rust]
pass_filenames: false
- id: check-msrv-all-features
name: cargo check MSRV (all features)
entry: cargo +1.70 check --all --tests --all-features --
language: system
types: [rust]
pass_filenames: false
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
User-code should not need to create arbitrary `ServerError`s.
In return, `ServerError` now implements `Clone`.
- Add support for bolt handshake manifest v1.
- Add support for Bolt 5.8 (home database resolution cache)
- Includes an optimization where the driver uses a home/default database cache to perform optimistic routing under certain circumstances, saving a full round trip. See the [PR description](https://github.com/robsdedude/neo4j-rust-driver/pull/28) for more details.

**🔧 Fixes**
- Rework `neo4j::value::graph::Path`
Expand Down
44 changes: 37 additions & 7 deletions neo4j/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

pub(crate) mod config;
pub(crate) mod eager_result;
mod home_db_cache;
pub(crate) mod io;
pub(crate) mod record;
pub mod record_stream;
Expand All @@ -40,10 +41,11 @@ pub use config::{
InvalidRoutingContextError, KeepAliveConfig, TlsConfigError,
};
pub use eager_result::{EagerResult, ScalarError};
use home_db_cache::HomeDbCache;
use io::bolt::message_parameters::TelemetryAPI;
#[cfg(feature = "_internal_testkit_backend")]
pub use io::ConnectionPoolMetrics;
use io::{AcquireConfig, Pool, PoolConfig, PooledBolt, SessionAuth, UpdateRtArgs};
use io::{AcquireConfig, Pool, PoolConfig, PooledBolt, SessionAuth, UpdateRtArgs, UpdateRtDb};
use notification::NotificationFilter;
pub use record::Record;
use record_stream::RecordStream;
Expand Down Expand Up @@ -76,8 +78,9 @@ pub mod notification {
/// * [`Driver::session()`] for several mechanisms offering more advance patterns.
#[derive(Debug)]
pub struct Driver {
pub(crate) config: ReducedDriverConfig,
pub(crate) pool: Pool,
config: ReducedDriverConfig,
pool: Pool,
home_db_cache: Arc<HomeDbCache>,
capability_check_config: SessionConfig,
execute_query_bookmark_manager: Arc<dyn BookmarkManager>,
}
Expand Down Expand Up @@ -120,6 +123,7 @@ impl Driver {
idle_time_before_connection_test: config.idle_time_before_connection_test,
},
pool: Pool::new(Arc::new(connection_config.address), pool_config),
home_db_cache: Default::default(),
capability_check_config: SessionConfig::default()
.with_database(Arc::new(String::from("system"))),
execute_query_bookmark_manager: Arc::new(bookmark_managers::simple(None)),
Expand Down Expand Up @@ -169,7 +173,12 @@ impl Driver {
idle_time_before_connection_test: self.config.idle_time_before_connection_test,
eager_begin: true,
};
Session::new(config, &self.pool, &self.config)
Session::new(
config,
&self.pool,
Arc::clone(&self.home_db_cache),
&self.config,
)
}

fn execute_query_session(
Expand Down Expand Up @@ -197,7 +206,12 @@ impl Driver {
idle_time_before_connection_test: self.config.idle_time_before_connection_test,
eager_begin: false,
};
Session::new(config, &self.pool, &self.config)
Session::new(
config,
&self.pool,
Arc::clone(&self.home_db_cache),
&self.config,
)
}

/// Execute a single query inside a transaction.
Expand Down Expand Up @@ -329,7 +343,13 @@ impl Driver {
idle_time_before_connection_test: Some(Duration::ZERO),
eager_begin: true,
};
Session::new(config, &self.pool, &self.config)
let mut session = Session::new(
config,
&self.pool,
Arc::clone(&self.home_db_cache),
&self.config,
);
session
.acquire_connection(RoutingControl::Read)
.and_then(|mut con| {
con.write_all(None)?;
Expand Down Expand Up @@ -380,11 +400,21 @@ impl Driver {
self.pool.acquire(AcquireConfig {
mode: RoutingControl::Read,
update_rt_args: UpdateRtArgs {
db: self.capability_check_config.database.as_ref(),
db: self
.capability_check_config
.database
.as_ref()
.map(|db| UpdateRtDb {
db: Arc::clone(db),
guess: false,
})
.as_ref(),
bookmarks: None,
imp_user: None,
deadline: self.pool.config.connection_acquisition_deadline(),
session_auth: SessionAuth::None,
idle_time_before_connection_test: None,
db_resolution_cb: None,
},
})
}
Expand Down
Loading

0 comments on commit 75bac94

Please sign in to comment.