Skip to content

Commit a68abd6

Browse files
authored
Merge pull request #248 from taosdata/fix/TS-3993
fix: fix edtion check error for cloud
2 parents ae20bb9 + f1c29b7 commit a68abd6

File tree

12 files changed

+133
-95
lines changed

12 files changed

+133
-95
lines changed

mdsn/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg_attr(coverage_nightly, feature(no_coverage))]
2-
31
//! M-DSN: A Multi-address DSN(Data Source Name) parser.
42
//!
53
//! M-DSN support two kind of DSN format:

taos-optin/src/lib.rs

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ use std::{
44
sync::Arc,
55
};
66

7+
use log::warn;
78
use once_cell::sync::OnceCell;
89
use raw::{ApiEntry, BlockState, RawRes, RawTaos};
910

10-
use taos_query::{prelude::{Field, Precision, RawBlock, RawMeta, RawResult, Code}, RawError};
11+
use taos_query::{
12+
prelude::{Field, Precision, RawBlock, RawMeta, RawResult},
13+
util::Edition,
14+
};
1115

1216
const MAX_CONNECT_RETRIES: u8 = 16;
1317

@@ -402,27 +406,23 @@ impl taos_query::TBuilder for TaosBuilder {
402406
"select version, (expire_time < now) as valid from information_schema.ins_cluster",
403407
);
404408

405-
if let Ok(Some((edition, expired))) = grant {
406-
if expired {
407-
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
408-
}
409-
return match edition.as_str() {
410-
"cloud" | "official" | "trial" => Ok(true),
411-
_ => Ok(false),
412-
};
413-
}
414-
415-
let grant: RawResult<Option<(String, (), String)>> =
416-
Queryable::query_one(taos, "show grants");
417-
418-
if let Ok(Some((edition, _, expired))) = grant {
419-
match (edition.trim(), expired.trim()) {
420-
("cloud" | "official" | "trial", "false") => Ok(true),
421-
_ => Ok(false),
422-
}
409+
let edition = if let Ok(Some((edition, expired))) = grant {
410+
Edition::new(edition, expired)
423411
} else {
424-
Ok(false)
425-
}
412+
let grant: RawResult<Option<(String, (), String)>> =
413+
Queryable::query_one(taos, "show grants");
414+
415+
if let Ok(Some((edition, _, expired))) = grant {
416+
Edition::new(
417+
edition.trim(),
418+
expired.trim() == "false" || expired.trim() == "unlimited",
419+
)
420+
} else {
421+
warn!("Can't check enterprise edition with either \"show cluster\" or \"show grants\"");
422+
Edition::new("unknown", true)
423+
}
424+
};
425+
Ok(edition.is_enterprise_edition())
426426
}
427427
}
428428

@@ -516,33 +516,31 @@ impl taos_query::AsyncTBuilder for TaosBuilder {
516516
async fn is_enterprise_edition(&self) -> RawResult<bool> {
517517
let taos = self.inner_connection()?;
518518
use taos_query::prelude::AsyncQueryable;
519+
520+
// the latest version of 3.x should work
519521
let grant: RawResult<Option<(String, bool)>> = AsyncQueryable::query_one(
520522
taos,
521523
"select version, (expire_time < now) as valid from information_schema.ins_cluster",
522524
)
523525
.await;
524526

525-
if let Ok(Some((edition, expired))) = grant {
526-
if expired {
527-
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
528-
}
529-
return match edition.as_str() {
530-
"cloud" | "official" | "trial" => Ok(true),
531-
_ => Ok(false),
532-
};
533-
}
534-
535-
let grant: RawResult<Option<(String, (), String)>> = AsyncQueryable::query_one(taos, "show grants")
536-
.await;
537-
538-
if let Ok(Some((edition, _, expired))) = grant {
539-
match (edition.trim(), expired.trim()) {
540-
("cloud" | "official" | "trial", "false") => Ok(true),
541-
_ => Ok(false),
542-
}
527+
let edition = if let Ok(Some((edition, expired))) = grant {
528+
Edition::new(edition, expired)
543529
} else {
544-
Ok(false)
545-
}
530+
let grant: RawResult<Option<(String, (), String)>> =
531+
AsyncQueryable::query_one(taos, "show grants").await;
532+
533+
if let Ok(Some((edition, _, expired))) = grant {
534+
Edition::new(
535+
edition.trim(),
536+
expired.trim() == "false" || expired.trim() == "unlimited",
537+
)
538+
} else {
539+
warn!("Can't check enterprise edition with either \"show cluster\" or \"show grants\"");
540+
Edition::new("unknown", true)
541+
}
542+
};
543+
Ok(edition.is_enterprise_edition())
546544
}
547545
}
548546

taos-query/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,10 @@ impl<T: AsyncTBuilder> deadpool::managed::Manager for Manager<T> {
329329
self.manager.build().await
330330
}
331331

332-
async fn recycle(&self, conn: &mut Self::Type) -> deadpool::managed::RecycleResult<Self::Error> {
332+
async fn recycle(
333+
&self,
334+
conn: &mut Self::Type,
335+
) -> deadpool::managed::RecycleResult<Self::Error> {
333336
self.ping(conn).await.map_err(RawError::from_any)?;
334337
Ok(())
335338
}

taos-query/src/util/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ pub use inline_str::InlineStr;
2121
pub use inline_read::AsyncInlinableRead;
2222
pub use inline_write::AsyncInlinableWrite;
2323

24+
pub struct Edition {
25+
pub edition: String,
26+
pub expired: bool,
27+
}
28+
29+
impl Edition {
30+
pub fn new(edition: impl Into<String>, expired: bool) -> Self {
31+
Self {
32+
edition: edition.into(),
33+
expired,
34+
}
35+
}
36+
pub fn is_enterprise_edition(&self) -> bool {
37+
match (self.edition.as_str(), self.expired) {
38+
("cloud", _) => true,
39+
("official" | "trial", false) => true,
40+
_ => false,
41+
}
42+
}
43+
}
44+
2445
pub trait InlinableWrite: Write {
2546
#[inline]
2647
/// Write `usize` length as little endian `N` bytes.

taos-sys/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,10 @@ impl taos_query::TBuilder for TaosBuilder {
373373

374374
if let Ok(Some((edition, expired))) = grant {
375375
if expired {
376-
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
376+
return Err(RawError::new(
377+
Code::FAILED,
378+
r#"Enterprise version expired. Please get a new license to activate."#,
379+
));
377380
}
378381
return match edition.as_str() {
379382
"cloud" | "official" | "trial" => Ok(true),
@@ -493,16 +496,19 @@ impl taos_query::AsyncTBuilder for TaosBuilder {
493496

494497
if let Ok(Some((edition, expired))) = grant {
495498
if expired {
496-
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
499+
return Err(RawError::new(
500+
Code::FAILED,
501+
r#"Enterprise version expired. Please get a new license to activate."#,
502+
));
497503
}
498504
return match edition.as_str() {
499505
"cloud" | "official" | "trial" => Ok(true),
500506
_ => Ok(false),
501507
};
502508
}
503509

504-
let grant: RawResult<Option<(String, (), String)>> = AsyncQueryable::query_one(taos, "show grants")
505-
.await;
510+
let grant: RawResult<Option<(String, (), String)>> =
511+
AsyncQueryable::query_one(taos, "show grants").await;
506512

507513
if let Ok(Some((edition, _, expired))) = grant {
508514
match (edition.trim(), expired.trim()) {

taos-ws-sys/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,10 @@ mod tests {
11201120
let version = ws_get_server_info(taos);
11211121
dbg!(CStr::from_ptr(version as _));
11221122

1123-
let res = ws_query(taos, b"select count(*) from ws_stop_query.s1\0" as *const u8 as _);
1123+
let res = ws_query(
1124+
taos,
1125+
b"select count(*) from ws_stop_query.s1\0" as *const u8 as _,
1126+
);
11241127
let cols = ws_field_count(res);
11251128
dbg!(cols);
11261129
let fields = ws_fetch_fields(res);

taos-ws/src/lib.rs

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#![recursion_limit = "256"]
22
use std::fmt::{Debug, Display};
33

4+
use log::warn;
45
use once_cell::sync::OnceCell;
56

67
use taos_query::prelude::Code;
7-
use taos_query::{DsnError, IntoDsn, RawResult, RawError};
8+
use taos_query::util::Edition;
9+
use taos_query::{DsnError, IntoDsn, RawResult};
810

911
pub mod stmt;
1012
pub use stmt::Stmt;
@@ -133,27 +135,23 @@ impl taos_query::TBuilder for TaosBuilder {
133135
"select version, (expire_time < now) from information_schema.ins_cluster",
134136
);
135137

136-
if let Ok(Some((edition, expired))) = grant {
137-
if expired {
138-
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
139-
}
140-
return match edition.trim() {
141-
"cloud" | "official" | "trial" => Ok(true),
142-
_ => Ok(false),
143-
};
144-
}
145-
146-
let grant: RawResult<Option<(String, (), String)>> =
147-
Queryable::query_one(&taos, "show grants");
138+
let edition = if let Ok(Some((edition, expired))) = grant {
139+
Edition::new(edition, expired)
140+
} else {
141+
let grant: RawResult<Option<(String, (), String)>> =
142+
Queryable::query_one(&taos, "show grants");
148143

149-
if let Ok(Some((edition, _, expired))) = grant {
150-
match (edition.trim(), expired.trim()) {
151-
("cloud" | "official" | "trial", "false") => Ok(true),
152-
_ => Ok(false),
144+
if let Ok(Some((edition, _, expired))) = grant {
145+
Edition::new(
146+
edition.trim(),
147+
expired.trim() == "false" || expired.trim() == "unlimited",
148+
)
149+
} else {
150+
warn!("Can't check enterprise edition with either \"show cluster\" or \"show grants\"");
151+
Edition::new("unknown", true)
153152
}
154-
} else {
155-
Ok(false)
156-
}
153+
};
154+
Ok(edition.is_enterprise_edition())
157155
}
158156
}
159157

@@ -221,27 +219,23 @@ impl taos_query::AsyncTBuilder for TaosBuilder {
221219
)
222220
.await;
223221

224-
if let Ok(Some((edition, expired))) = grant {
225-
if expired {
226-
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
227-
}
228-
return match edition.trim() {
229-
"cloud" | "official" | "trial" => Ok(true),
230-
_ => Ok(false),
231-
};
232-
}
233-
234-
let grant: RawResult<Option<(String, (), String)>> = AsyncQueryable::query_one(&taos, "show grants")
235-
.await;
222+
let edition = if let Ok(Some((edition, expired))) = grant {
223+
Edition::new(edition, expired)
224+
} else {
225+
let grant: RawResult<Option<(String, (), String)>> =
226+
AsyncQueryable::query_one(&taos, "show grants").await;
236227

237-
if let Ok(Some((edition, _, expired))) = grant {
238-
match (edition.trim(), expired.trim()) {
239-
("cloud" | "official" | "trial", "false") => Ok(true),
240-
_ => Ok(false),
228+
if let Ok(Some((edition, _, expired))) = grant {
229+
Edition::new(
230+
edition.trim(),
231+
expired.trim() == "false" || expired.trim() == "unlimited",
232+
)
233+
} else {
234+
warn!("Can't check enterprise edition with either \"show cluster\" or \"show grants\"");
235+
Edition::new("unknown", true)
241236
}
242-
} else {
243-
Ok(false)
244-
}
237+
};
238+
Ok(edition.is_enterprise_edition())
245239
}
246240
}
247241

taos-ws/src/stmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use taos_query::common::views::views_to_raw_block;
99
use taos_query::common::ColumnView;
1010
use taos_query::prelude::{InlinableWrite, RawResult};
1111
use taos_query::stmt::{AsyncBindable, Bindable};
12-
use taos_query::{IntoDsn, RawBlock, block_in_place_or_global};
12+
use taos_query::{block_in_place_or_global, IntoDsn, RawBlock};
1313

1414
use taos_query::prelude::tokio;
1515
use tokio::sync::{oneshot, watch};

taos/examples/bind-tags.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ async fn main() -> Result<()> {
1717
let mut stmt = Stmt::init(&taos).await?;
1818
stmt.prepare(
1919
"insert into ? using tb1 tags(?) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
20-
).await?;
20+
)
21+
.await?;
2122
stmt.set_tbname("d0").await?;
2223
stmt.set_tags(&[Value::VarChar("涛思".to_string())]).await?;
2324

@@ -37,7 +38,13 @@ async fn main() -> Result<()> {
3738
ColumnView::from_varchar(vec!["ABC"]),
3839
ColumnView::from_nchar(vec!["涛思数据"]),
3940
];
40-
let rows = stmt.bind(&params).await?.add_batch().await?.execute().await?;
41+
let rows = stmt
42+
.bind(&params)
43+
.await?
44+
.add_batch()
45+
.await?
46+
.execute()
47+
.await?;
4148
assert_eq!(rows, 1);
4249

4350
#[derive(Debug, Deserialize)]

taos/examples/bind.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ async fn main() -> Result<()> {
1515
])
1616
.await?;
1717
let mut stmt = Stmt::init(&taos).await?;
18-
stmt.prepare("insert into tb1 values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").await?;
18+
stmt.prepare("insert into tb1 values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
19+
.await?;
1920
let params = vec![
2021
ColumnView::from_millis_timestamp(vec![0]),
2122
ColumnView::from_bools(vec![true]),
@@ -32,7 +33,13 @@ async fn main() -> Result<()> {
3233
ColumnView::from_varchar(vec!["ABC"]),
3334
ColumnView::from_nchar(vec!["涛思数据"]),
3435
];
35-
let rows = stmt.bind(&params).await?.add_batch().await?.execute().await?;
36+
let rows = stmt
37+
.bind(&params)
38+
.await?
39+
.add_batch()
40+
.await?
41+
.execute()
42+
.await?;
3643
assert_eq!(rows, 1);
3744

3845
#[derive(Debug, Deserialize)]

0 commit comments

Comments
 (0)