Skip to content

Commit

Permalink
Merge pull request #11 from robsdedude/chore/clean-up-dead-code
Browse files Browse the repository at this point in the history
Clean up dead code
  • Loading branch information
robsdedude authored Apr 13, 2024
2 parents ea9e58b + d929fb4 commit 2d48812
Show file tree
Hide file tree
Showing 21 changed files with 9 additions and 272 deletions.
31 changes: 1 addition & 30 deletions neo4j/src/driver/io/bolt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,6 @@ impl<RW: Read + Write> Bolt<RW> {
self.data.needs_reauth(parameters)
}

pub(crate) fn current_auth(&self) -> Option<Arc<AuthToken>> {
self.data.auth.clone()
}

#[inline]
pub(crate) fn auth_reset_handler(&self) -> AuthResetHandle {
AuthResetHandle::clone(&self.data.auth_reset)
Expand Down Expand Up @@ -364,21 +360,13 @@ impl<RW: Read + Write> Bolt<RW> {
}

pub(crate) fn write_all(&mut self, deadline: Option<Instant>) -> Result<()> {
self.data.idle_since = Instant::now();
self.data.write_all(deadline)?;
self.data.flush(deadline)
}
pub(crate) fn write_one(&mut self, deadline: Option<Instant>) -> Result<()> {
self.data.write_one(deadline)?;
self.data.flush(deadline)?;
self.data.idle_since = Instant::now();
Ok(())
}
pub(crate) fn has_buffered_message(&self) -> bool {
self.data.has_buffered_message()
}
pub(crate) fn buffered_messages_len(&self) -> usize {
self.data.buffered_messages_len()
}
pub(crate) fn expects_reply(&self) -> bool {
self.data.expects_reply()
}
Expand Down Expand Up @@ -522,7 +510,6 @@ pub(crate) struct BoltData<RW: Read + Write> {
server_agent: Arc<AtomicRefCell<Arc<String>>>,
telemetry_enabled: Arc<AtomicRefCell<bool>>,
address: Arc<Address>,
address_str: String,
last_qid: Arc<AtomicRefCell<Option<i64>>>,
auth: Option<Arc<AuthToken>>,
session_auth: bool,
Expand All @@ -539,7 +526,6 @@ impl<RW: Read + Write> BoltData<RW> {
local_port: Option<u16>,
address: Arc<Address>,
) -> Self {
let address_str = address.to_string();
let now = Instant::now();
Self {
message_buff: VecDeque::with_capacity(2048),
Expand All @@ -554,7 +540,6 @@ impl<RW: Read + Write> BoltData<RW> {
server_agent: Default::default(),
telemetry_enabled: Default::default(),
address,
address_str,
last_qid: Default::default(),
auth: None,
session_auth: false,
Expand All @@ -576,17 +561,6 @@ impl<RW: Read + Write> BoltData<RW> {
self.session_auth
}

fn dbg_extra(&self) -> String {
let meta = self.meta.try_borrow();
let Ok(meta) = meta else {
return dbg_extra(self.local_port, Some("!!!!"));
};
let Some(ValueReceive::String(id)) = meta.get("connection_id") else {
return dbg_extra(self.local_port, None);
};
dbg_extra(self.local_port, Some(id))
}

fn closed(&self) -> bool {
!matches!(self.connection_state, ConnectionState::Healthy)
}
Expand Down Expand Up @@ -692,9 +666,6 @@ impl<RW: Read + Write> BoltData<RW> {
fn has_buffered_message(&self) -> bool {
!self.message_buff.is_empty()
}
fn buffered_messages_len(&self) -> usize {
self.message_buff.len()
}

fn expects_reply(&self) -> bool {
!self.responses.is_empty()
Expand Down
3 changes: 0 additions & 3 deletions neo4j/src/driver/io/bolt/bolt4x4/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ use super::super::{
use crate::error_::Result;
use crate::value::ValueReceive;

const SERVER_AGENT_KEY: &str = "server";
const PATCH_BOLT_KEY: &str = "patch_bolt";
const HINTS_KEY: &str = "hints";
const RECV_TIMEOUT_KEY: &str = "connection.recv_timeout_seconds";

#[derive(Debug)]
pub(crate) struct Bolt4x4<T: BoltStructTranslatorWithUtcPatch + Sync + Send + 'static> {
Expand Down
9 changes: 0 additions & 9 deletions neo4j/src/driver/io/bolt/bolt4x4/translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ use crate::value::graph::{Node, Path, Relationship, UnboundRelationship};
use crate::value::time::{local_date_time_from_timestamp, FixedOffset, Tz};
use crate::value::{BrokenValue, BrokenValueInner, ValueReceive, ValueSend};

const TAG_NODE: u8 = b'N';
const TAG_RELATIONSHIP: u8 = b'R';
const TAG_UNBOUND_RELATIONSHIP: u8 = b'r';
const TAG_PATH: u8 = b'P';
const TAG_DATE_TIME: u8 = b'I';
const TAG_LEGACY_DATE_TIME: u8 = b'F';
const TAG_DATE_TIME_ZONE_ID: u8 = b'i';
const TAG_LEGACY_DATE_TIME_ZONE_ID: u8 = b'f';

#[derive(Debug, Default)]
pub(crate) struct Bolt4x4StructTranslator {
utc_patch: bool,
Expand Down
6 changes: 0 additions & 6 deletions neo4j/src/driver/io/bolt/bolt5x1/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,15 @@ use crate::driver::config::auth::AuthToken;
use crate::error_::Result;
use crate::value::ValueReceive;

const SERVER_AGENT_KEY: &str = "server";
const HINTS_KEY: &str = "hints";
const RECV_TIMEOUT_KEY: &str = "connection.recv_timeout_seconds";

#[derive(Debug)]
pub(crate) struct Bolt5x1<T: BoltStructTranslator> {
translator: T,
pub(in super::super) bolt5x0: Bolt5x0<T>,
protocol_version: ServerAwareBoltVersion,
}

impl<T: BoltStructTranslator> Bolt5x1<T> {
pub(in super::super) fn new(protocol_version: ServerAwareBoltVersion) -> Self {
Self {
translator: T::default(),
bolt5x0: Bolt5x0::new(T::default(), protocol_version),
protocol_version,
}
Expand Down
6 changes: 0 additions & 6 deletions neo4j/src/driver/io/bolt/bolt5x2/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,17 @@ use super::super::{
use crate::error_::Result;
use crate::value::ValueReceive;

const SERVER_AGENT_KEY: &str = "server";
const HINTS_KEY: &str = "hints";
const RECV_TIMEOUT_KEY: &str = "connection.recv_timeout_seconds";

#[derive(Debug)]
pub(crate) struct Bolt5x2<T: BoltStructTranslator> {
translator: T,
pub(in super::super) bolt5x1: Bolt5x1<T>,
protocol_version: ServerAwareBoltVersion,
}

impl<T: BoltStructTranslator> Bolt5x2<T> {
pub(in super::super) fn new(protocol_version: ServerAwareBoltVersion) -> Self {
Self {
translator: T::default(),
bolt5x1: Bolt5x1::new(protocol_version),
protocol_version,
}
}

Expand Down
8 changes: 0 additions & 8 deletions neo4j/src/driver/io/bolt/bolt5x3/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,15 @@ use super::super::{
use crate::error_::Result;
use crate::value::ValueReceive;

const SERVER_AGENT_KEY: &str = "server";
const HINTS_KEY: &str = "hints";
const RECV_TIMEOUT_KEY: &str = "connection.recv_timeout_seconds";

#[derive(Debug)]
pub(crate) struct Bolt5x3<T: BoltStructTranslator> {
translator: T,
pub(in super::super) bolt5x2: Bolt5x2<T>,
protocol_version: ServerAwareBoltVersion,
}

impl<T: BoltStructTranslator> Bolt5x3<T> {
pub(in super::super) fn new(protocol_version: ServerAwareBoltVersion) -> Self {
Self {
translator: T::default(),
bolt5x2: Bolt5x2::new(protocol_version),
protocol_version,
}
}

Expand Down
1 change: 1 addition & 0 deletions neo4j/src/driver/io/bolt/bolt_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub(super) enum ServerAwareBoltVersion {
V5x1,
V5x2,
V5x3,
#[allow(dead_code)] // bolt version exists, not yet implemented
V5x4,
}

Expand Down
15 changes: 0 additions & 15 deletions neo4j/src/driver/io/bolt/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ impl ResponseCallbacks {
.with_on_failure(|error| Err(error.into()))
}

pub(crate) fn new_silent_error() -> Self {
Self {
on_success_cb: None,
on_failure_cb: None,
on_ignored_cb: None,
on_record_cb: None,
on_summary_cb: None,
}
}

pub(crate) fn with_on_success<F: FnMut(BoltMeta) -> Result<()> + Send + Sync + 'static>(
mut self,
cb: F,
Expand Down Expand Up @@ -136,11 +126,6 @@ impl ResponseCallbacks {
self
}

pub(crate) fn with_on_summary<F: FnMut() + Send + Sync + 'static>(mut self, cb: F) -> Self {
self.on_summary_cb = Some(Box::new(cb));
self
}

pub(crate) fn on_success(&mut self, meta: ValueReceive) -> Result<()> {
let res = match meta {
ValueReceive::Map(meta) => match self.on_success_cb.as_mut() {
Expand Down
14 changes: 0 additions & 14 deletions neo4j/src/driver/io/bolt/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,6 @@ impl<T: Read + Write> Socket<T> {
}
})
}

pub(super) fn io_ref(&self) -> &T {
match self {
Socket::Plain(io) => io,
Socket::Tls(io) => io.get_ref(),
}
}

pub(super) fn io_mut(&mut self) -> &mut T {
match self {
Socket::Plain(io) => io,
Socket::Tls(io) => io.get_mut(),
}
}
}

impl<T: Read + Write> Read for Socket<T> {
Expand Down
29 changes: 1 addition & 28 deletions neo4j/src/driver/io/deadline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,13 @@

use log::warn;
use std::fmt::Debug;
use std::io::{self, ErrorKind, Read, Write};
use std::io::{self, Read, Write};
use std::net::TcpStream;
use std::time::Duration;

use crate::error_::{Neo4jError, Result};
use crate::time::Instant;

pub(crate) fn rewrite_timeout<R, F: FnOnce() -> Result<R>>(f: F) -> Result<R> {
match f() {
Err(Neo4jError::Disconnect {
message,
source: Some(io_err),
during_commit,
}) => {
let kind = io_err.kind();
match kind {
ErrorKind::WouldBlock | ErrorKind::TimedOut => {
assert!(
!during_commit,
"tried to rewrite io error to timeout error during commit"
);
Err(Neo4jError::Timeout { message })
}
_ => Err(Neo4jError::Disconnect {
message,
source: Some(io_err),
during_commit,
}),
}
}
v => v,
}
}

fn wrap_set_timeout_error<T>(e: Result<T>) -> Result<T> {
match e {
Ok(t) => Ok(t),
Expand Down
59 changes: 2 additions & 57 deletions neo4j/src/driver/io/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ impl<'pool> PooledBolt<'pool> {
move |bolt_data, error| pool.handle_server_error(bolt_data, error)
}

#[inline]
pub(crate) fn write_one(&mut self, deadline: Option<Instant>) -> Result<()> {
self.wrap_io(|this| this.deref_mut().write_one(deadline))
}

#[inline]
pub(crate) fn write_all(&mut self, deadline: Option<Instant>) -> Result<()> {
self.wrap_io(|this| this.deref_mut().write_all(deadline))
Expand Down Expand Up @@ -175,20 +170,15 @@ impl PoolConfig {

#[derive(Debug)]
pub(crate) struct Pool {
address: Arc<Address>,
config: Arc<PoolConfig>,
pools: Pools,
}

impl Pool {
pub(crate) fn new(address: Arc<Address>, config: PoolConfig) -> Self {
let config = Arc::new(config);
let pools = Pools::new(Arc::clone(&address), Arc::clone(&config));
Self {
address,
config,
pools,
}
let pools = Pools::new(address, Arc::clone(&config));
Self { config, pools }
}

#[inline]
Expand All @@ -207,12 +197,6 @@ impl Pool {
self.pools.get_metrics(address)
}

pub(crate) fn default_acquisition_deadline(&self) -> Option<Instant> {
self.config
.connection_acquisition_timeout
.map(|t| Instant::now() + t)
}

pub(crate) fn resolve_home_db(&self, args: UpdateRtArgs) -> Result<Option<Arc<String>>> {
let Pools::Routing(pools) = &self.pools else {
panic!("don't call resolve_home_db on a direct pool")
Expand Down Expand Up @@ -276,12 +260,6 @@ impl Pool {
routing_pool.deactivate_server(addr)
}
}

fn deactivate_writer(&self, addr: &Address) {
if let Pools::Routing(routing_pool) = &self.pools {
routing_pool.deactivate_writer(addr)
}
}
}

#[derive(Debug)]
Expand All @@ -304,14 +282,6 @@ impl Pools {
}
}

pub(crate) fn is_routing(&self) -> bool {
matches!(self, Pools::Routing(_))
}

pub(crate) fn is_direct(&self) -> bool {
matches!(self, Pools::Direct(_))
}

#[cfg(feature = "_internal_testkit_backend")]
fn get_metrics(&self, address: Arc<Address>) -> Option<ConnectionPoolMetrics> {
match self {
Expand Down Expand Up @@ -868,28 +838,3 @@ pub(crate) struct UpdateRtArgs<'a> {
pub(crate) session_auth: SessionAuth<'a>,
pub(crate) idle_time_before_connection_test: Option<Duration>,
}

enum DbName<'a> {
Ref(&'a Option<String>),
Owned(Option<String>),
}

impl<'a> Deref for DbName<'a> {
type Target = Option<String>;

fn deref(&self) -> &Self::Target {
match self {
DbName::Ref(s) => s,
DbName::Owned(s) => s,
}
}
}

impl<'a> DbName<'a> {
fn into_key(self) -> Option<String> {
match self {
DbName::Ref(s) => s.clone(),
DbName::Owned(s) => s,
}
}
}
4 changes: 0 additions & 4 deletions neo4j/src/driver/io/pool/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ impl RoutingTable {
true
}

pub(crate) fn initialized_without_writers(&self) -> bool {
self.initialized_without_writers
}

pub(crate) fn deactivate(&mut self, addr: &Address) {
self.routers = mem::take(&mut self.routers)
.into_iter()
Expand Down
Loading

0 comments on commit 2d48812

Please sign in to comment.