@@ -12,9 +12,9 @@ mod sharding_keys;
1212mod snapshot;
1313mod version_check;
1414
15- use std::cell::RefCell;
1615use std::future::Future;
1716
17+ use futures::executor::block_on;
1818use tonic::codegen::InterceptedService;
1919use tonic::transport::{Channel, Uri};
2020use tonic::Status;
@@ -23,6 +23,7 @@ use crate::auth::TokenInterceptor;
2323use crate::channel_pool::ChannelPool;
2424use crate::qdrant::{qdrant_client, HealthCheckReply, HealthCheckRequest};
2525use crate::qdrant_client::config::QdrantConfig;
26+ use crate::qdrant_client::version_check::is_compatible;
2627use crate::QdrantError;
2728
2829/// [`Qdrant`] client result
@@ -87,9 +88,6 @@ pub struct Qdrant {
8788
8889 /// Internal connection pool
8990 channel: ChannelPool,
90-
91- /// Internal flag for checking compatibility with the server
92- is_compatible: RefCell<Option<bool>>,
9391}
9492
9593/// # Construct and connect
@@ -100,30 +98,41 @@ impl Qdrant {
10098 ///
10199 /// Constructs the client and connects based on the given [`QdrantConfig`](config::QdrantConfig).
102100 pub fn new(config: QdrantConfig) -> QdrantResult<Self> {
101+ let check_compatibility = config.check_compatibility;
103102 let channel = ChannelPool::new(
104103 config.uri.parse::<Uri>()?,
105104 config.timeout,
106105 config.connect_timeout,
107106 config.keep_alive_while_idle,
108107 );
109108
110- let client = Self {
111- channel,
112- config,
113- is_compatible: RefCell::new(None),
114- };
109+ let client = Self { channel, config };
110+
111+ if check_compatibility {
112+ let client_version = env!("CARGO_PKG_VERSION").to_string();
113+ let server_version = match block_on(async { client.health_check().await }) {
114+ Ok(server_info) => server_info.version,
115+ Err(_) => "Unknown".to_string(),
116+ };
117+ if server_version == "Unknown" {
118+ println!(
119+ "Failed to obtain server version. \
120+ Unable to check client-server compatibility. \
121+ Set check_compatibility=false to skip version check."
122+ );
123+ } else {
124+ let is_compatible = is_compatible(Some(&client_version), Some(&server_version));
125+ if !is_compatible {
126+ println!("Client version {client_version} is not compatible with server version {server_version}. \
127+ Major versions should match and minor version difference must not exceed 1. \
128+ Set check_compatibility=false to skip version check.");
129+ }
130+ }
131+ }
115132
116133 Ok(client)
117134 }
118135
119- fn set_is_compatible(&self, value: Option<bool>) {
120- *self.is_compatible.borrow_mut() = value;
121- }
122-
123- fn is_compatible(&self) -> Option<bool> {
124- *self.is_compatible.borrow()
125- }
126-
127136 /// Build a new Qdrant client with the given URL.
128137 ///
129138 /// ```no_run
0 commit comments