Skip to content

Commit 91ba766

Browse files
committed
minor refactor
1 parent 57cc2de commit 91ba766

File tree

3 files changed

+68
-67
lines changed

3 files changed

+68
-67
lines changed

src/query/ee/src/license/license_mgr.rs

Lines changed: 56 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -109,30 +109,29 @@ impl LicenseManager for RealLicenseManager {
109109
GlobalInstance::get()
110110
}
111111

112-
fn check_enterprise_enabled(&self, _license_key: String, _feature: Feature) -> Result<()> {
113-
Ok(())
114-
// if license_key.is_empty() {
115-
// return feature.verify_default(format!(
116-
// "[LicenseManager] Feature '{}' requires Databend Enterprise Edition license. No license key found for tenant: {}. Learn more at {}",
117-
// feature, self.tenant, LICENSE_URL
118-
// ));
119-
//}
120-
121-
// if let Some(v) = self.cache.get(&license_key) {
122-
// return self.verify_feature(v.value(), feature);
123-
//}
124-
125-
// match self.parse_license_impl(&license_key) {
126-
// Ok(license) => {
127-
// self.verify_feature(&license, feature)?;
128-
// self.cache.insert(license_key, license);
129-
// Ok(())
130-
// }
131-
// Err(e) => match e.code() == ErrorCode::LICENSE_KEY_EXPIRED {
132-
// true => self.verify_if_expired(feature),
133-
// false => Err(e),
134-
// },
135-
//}
112+
fn check_enterprise_enabled(&self, license_key: String, feature: Feature) -> Result<()> {
113+
if license_key.is_empty() {
114+
return feature.verify_default(format!(
115+
"[LicenseManager] Feature '{}' requires Databend Enterprise Edition license. No license key found for tenant: {}. Learn more at {}",
116+
feature, self.tenant, LICENSE_URL
117+
));
118+
}
119+
120+
if let Some(v) = self.cache.get(&license_key) {
121+
return self.verify_feature(v.value(), feature);
122+
}
123+
124+
match self.parse_license_impl(&license_key) {
125+
Ok(license) => {
126+
self.verify_feature(&license, feature)?;
127+
self.cache.insert(license_key, license);
128+
Ok(())
129+
}
130+
Err(e) => match e.code() == ErrorCode::LICENSE_KEY_EXPIRED {
131+
true => self.verify_if_expired(feature),
132+
false => Err(e),
133+
},
134+
}
136135
}
137136

138137
fn parse_license(&self, raw: &str) -> Result<JWTClaims<LicenseInfo>> {
@@ -198,48 +197,45 @@ impl RealLicenseManager {
198197
}
199198

200199
fn verify_license_expired(l: &JWTClaims<LicenseInfo>) -> Result<bool> {
201-
Ok(true)
202-
// let now = Clock::now_since_epoch();
203-
// match l.expires_at {
204-
// Some(expire_at) => Ok(now > expire_at),
205-
// None => Err(ErrorCode::LicenseKeyInvalid(
206-
// "[LicenseManager] Cannot find valid expiration time",
207-
// )),
208-
//}
200+
let now = Clock::now_since_epoch();
201+
match l.expires_at {
202+
Some(expire_at) => Ok(now > expire_at),
203+
None => Err(ErrorCode::LicenseKeyInvalid(
204+
"[LicenseManager] Cannot find valid expiration time",
205+
)),
206+
}
209207
}
210208

211209
fn verify_feature(&self, l: &JWTClaims<LicenseInfo>, feature: Feature) -> Result<()> {
212-
Ok(())
213-
// if Self::verify_license_expired(l)? {
214-
// return self.verify_if_expired(feature);
215-
//}
216-
217-
// if l.custom.features.is_none() {
218-
// return Ok(());
219-
//}
220-
221-
// let verify_features = l.custom.features.as_ref().unwrap();
222-
// for verify_feature in verify_features {
223-
// if verify_feature.verify(&feature)? {
224-
// return Ok(());
225-
// }
226-
//}
227-
228-
// Err(ErrorCode::LicenseKeyInvalid(format!(
229-
// "[LicenseManager] License does not support feature: {}. Supported features: {}",
230-
// feature,
231-
// l.custom.display_features()
232-
//)))
210+
if Self::verify_license_expired(l)? {
211+
return self.verify_if_expired(feature);
212+
}
213+
214+
if l.custom.features.is_none() {
215+
return Ok(());
216+
}
217+
218+
let verify_features = l.custom.features.as_ref().unwrap();
219+
for verify_feature in verify_features {
220+
if verify_feature.verify(&feature)? {
221+
return Ok(());
222+
}
223+
}
224+
225+
Err(ErrorCode::LicenseKeyInvalid(format!(
226+
"[LicenseManager] License does not support feature: {}. Supported features: {}",
227+
feature,
228+
l.custom.display_features()
229+
)))
233230
}
234231

235232
fn verify_if_expired(&self, feature: Feature) -> Result<()> {
236-
Ok(())
237-
// feature.verify_default("").map_err(|_|
238-
// ErrorCode::LicenseKeyExpired(format!(
239-
// "[LicenseManager] Feature '{}' requires Databend Enterprise Edition license. License key expired for tenant: {}. Learn more at {}",
240-
// feature, self.tenant, LICENSE_URL
241-
// ))
242-
//)
233+
feature.verify_default("").map_err(|_|
234+
ErrorCode::LicenseKeyExpired(format!(
235+
"[LicenseManager] Feature '{}' requires Databend Enterprise Edition license. License key expired for tenant: {}. Learn more at {}",
236+
feature, self.tenant, LICENSE_URL
237+
))
238+
)
243239
}
244240
}
245241

src/query/service/src/sessions/query_ctx.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,9 +1594,9 @@ impl TableContext for QueryContext {
15941594
let txn_mgr_ref = self.txn_mgr();
15951595
let mut txn_mgr = txn_mgr_ref.lock();
15961596
if txn_mgr.is_active() && txn_mgr.get_table_txn_begin_timestamp(table_id).is_none() {
1597-
// If there's an active transaction and we haven't recorded a begin timestamp for this table yet
1598-
// Store the table's segment block timestamp as the transaction begin timestamp
1599-
// This is used for tracking when changes to this table started within the transaction
1597+
// Transaction Timestamp Tracking:
1598+
// When a table is first accessed within an active transaction, we record its
1599+
// segment_block_timestamp as the transaction's begin timestamp for this table.
16001600
txn_mgr.set_table_txn_begin_timestamp(
16011601
table_id,
16021602
table_meta_timestamps.segment_block_timestamp,

src/query/storages/fuse/src/retry/commit.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,18 @@ async fn try_rebuild_req(
105105
let merged_summary = deduct_statistics(&s, &base_snapshot.summary());
106106

107107
{
108-
let txn_mgr = ctx.txn_mgr();
109-
let txn_mgr = txn_mgr.lock();
108+
let txn_mgr_ref = ctx.txn_mgr();
109+
let txn_mgr = txn_mgr_ref.lock();
110110
if let Some(txn_begin_timestamp) =
111111
txn_mgr.get_table_txn_begin_timestamp(latest_table.get_id())
112112
{
113-
// TODO doc why it is safe to unwrap here
114-
let latest_snapshot_timestamp = latest_snapshot.timestamp().unwrap();
113+
let Some(latest_snapshot_timestamp) = latest_snapshot.timestamp() else {
114+
return Err(ErrorCode::UnresolvableConflict(format!(
115+
"Table {} snapshot lacks required timestamp. Table was created with an incompatible version and needs migration.",
116+
tid
117+
)));
118+
};
119+
115120
// TODO doc why we should hold this invariant
116121
if txn_begin_timestamp < latest_snapshot_timestamp {
117122
return Err(ErrorCode::UnresolvableConflict(format!(

0 commit comments

Comments
 (0)