Skip to content

Commit f734d58

Browse files
committed
Fetch server version using futures
1 parent d1c5141 commit f734d58

File tree

5 files changed

+27
-83
lines changed

5 files changed

+27
-83
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ anyhow = "1.0.89"
2020
serde = { version = "1.0.210", features = ["derive"], optional = true }
2121
serde_json = { version = "1.0.128", optional = true }
2222
reqwest = { version = "0.12.8", optional = true, default-features = false, features = ["stream", "rustls-tls", "http2"] }
23+
futures = { version = "0.3.31" }
2324
futures-util = { version = "0.3.31", optional = true }
2425
derive_builder = { version = "0.20.2" }
2526
thiserror = "1.0.64"

src/qdrant_client/collection.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::qdrant::{
1414
ListCollectionAliasesRequest, ListCollectionsRequest, ListCollectionsResponse, RenameAlias,
1515
UpdateCollection, UpdateCollectionClusterSetupRequest, UpdateCollectionClusterSetupResponse,
1616
};
17-
use crate::qdrant_client::version_check::is_compatible;
1817
use crate::qdrant_client::{Qdrant, QdrantResult};
1918

2019
/// # Collection operations
@@ -28,27 +27,6 @@ impl Qdrant {
2827
&self,
2928
f: impl Fn(CollectionsClient<InterceptedService<Channel, TokenInterceptor>>) -> O,
3029
) -> QdrantResult<T> {
31-
if self.config.check_compatibility && self.is_compatible().is_none() {
32-
let client_version = env!("CARGO_PKG_VERSION").to_string();
33-
let server_version = match self.health_check().await {
34-
Ok(info) => info.version,
35-
Err(_) => "Unknown".to_string(),
36-
};
37-
if server_version == "Unknown" {
38-
println!(
39-
"Failed to obtain server version. \
40-
Unable to check client-server compatibility. \
41-
Set check_compatibility=false to skip version check."
42-
);
43-
} else {
44-
let is_compatible = is_compatible(Some(&client_version), Some(&server_version));
45-
self.set_is_compatible(Some(is_compatible));
46-
println!("Client version {client_version} is not compatible with server version {server_version}. \
47-
Major versions should match and minor version difference must not exceed 1. \
48-
Set check_compatibility=false to skip version check.");
49-
}
50-
}
51-
5230
let result = self
5331
.channel
5432
.with_channel(

src/qdrant_client/mod.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ mod sharding_keys;
1212
mod snapshot;
1313
mod version_check;
1414

15-
use std::cell::RefCell;
1615
use std::future::Future;
1716

17+
use futures::executor::block_on;
1818
use tonic::codegen::InterceptedService;
1919
use tonic::transport::{Channel, Uri};
2020
use tonic::Status;
@@ -23,6 +23,7 @@ use crate::auth::TokenInterceptor;
2323
use crate::channel_pool::ChannelPool;
2424
use crate::qdrant::{qdrant_client, HealthCheckReply, HealthCheckRequest};
2525
use crate::qdrant_client::config::QdrantConfig;
26+
use crate::qdrant_client::version_check::is_compatible;
2627
use 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

src/qdrant_client/points.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::qdrant::{
1212
SearchMatrixOffsetsResponse, SearchMatrixPairsResponse, SearchMatrixPoints, UpdateBatchPoints,
1313
UpdateBatchResponse, UpdatePointVectors, UpsertPoints,
1414
};
15-
use crate::qdrant_client::version_check::is_compatible;
1615
use crate::qdrant_client::{Qdrant, QdrantResult};
1716

1817
/// # Point operations
@@ -25,27 +24,6 @@ impl Qdrant {
2524
&self,
2625
f: impl Fn(PointsClient<InterceptedService<Channel, TokenInterceptor>>) -> O,
2726
) -> QdrantResult<T> {
28-
if self.config.check_compatibility && self.is_compatible().is_none() {
29-
let client_version = env!("CARGO_PKG_VERSION").to_string();
30-
let server_version = match self.health_check().await {
31-
Ok(info) => info.version,
32-
Err(_) => "Unknown".to_string(),
33-
};
34-
if server_version == "Unknown" {
35-
println!(
36-
"Failed to obtain server version. \
37-
Unable to check client-server compatibility. \
38-
Set check_compatibility=false to skip version check."
39-
);
40-
} else {
41-
let is_compatible = is_compatible(Some(&client_version), Some(&server_version));
42-
self.set_is_compatible(Some(is_compatible));
43-
println!("Client version {client_version} is not compatible with server version {server_version}. \
44-
Major versions should match and minor version difference must not exceed 1. \
45-
Set check_compatibility=false to skip version check.");
46-
}
47-
}
48-
4927
let result = self
5028
.channel
5129
.with_channel(

src/qdrant_client/snapshot.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::qdrant::{
1111
DeleteFullSnapshotRequest, DeleteSnapshotRequest, DeleteSnapshotResponse,
1212
ListFullSnapshotsRequest, ListSnapshotsRequest, ListSnapshotsResponse,
1313
};
14-
use crate::qdrant_client::version_check::is_compatible;
1514
use crate::qdrant_client::{Qdrant, QdrantResult};
1615

1716
/// # Snapshot operations
@@ -24,27 +23,6 @@ impl Qdrant {
2423
&self,
2524
f: impl Fn(SnapshotsClient<InterceptedService<Channel, TokenInterceptor>>) -> O,
2625
) -> QdrantResult<T> {
27-
if self.config.check_compatibility && self.is_compatible().is_none() {
28-
let client_version = env!("CARGO_PKG_VERSION").to_string();
29-
let server_version = match self.health_check().await {
30-
Ok(info) => info.version,
31-
Err(_) => "Unknown".to_string(),
32-
};
33-
if server_version == "Unknown" {
34-
println!(
35-
"Failed to obtain server version. \
36-
Unable to check client-server compatibility. \
37-
Set check_compatibility=false to skip version check."
38-
);
39-
} else {
40-
let is_compatible = is_compatible(Some(&client_version), Some(&server_version));
41-
self.set_is_compatible(Some(is_compatible));
42-
println!("Client version {client_version} is not compatible with server version {server_version}. \
43-
Major versions should match and minor version difference must not exceed 1. \
44-
Set check_compatibility=false to skip version check.");
45-
}
46-
}
47-
4826
let result = self
4927
.channel
5028
.with_channel(

0 commit comments

Comments
 (0)