@@ -20,26 +20,6 @@ use display_more::DisplaySliceExt;
2020use serde:: Deserialize ;
2121use serde:: Serialize ;
2222
23- #[ derive( Debug , Clone , Eq , Ord , PartialOrd , PartialEq , serde:: Serialize , serde:: Deserialize ) ]
24- pub struct ComputeQuota {
25- pub threads_num : Option < usize > ,
26- pub memory_usage : Option < usize > ,
27- }
28-
29- #[ derive( Debug , Clone , Eq , Ord , PartialOrd , PartialEq , serde:: Serialize , serde:: Deserialize ) ]
30- pub struct StorageQuota {
31- pub storage_usage : Option < usize > ,
32- }
33-
34- /// We allow user to use upto 1TiB storage size.
35- impl Default for StorageQuota {
36- fn default ( ) -> Self {
37- Self {
38- storage_usage : Some ( 1024 * 1024 * 1024 * 1024 ) ,
39- }
40- }
41- }
42-
4323// All enterprise features are defined here.
4424#[ derive( Debug , Clone , Eq , Ord , PartialOrd , PartialEq , serde:: Serialize , serde:: Deserialize ) ]
4525pub enum Feature {
@@ -65,10 +45,6 @@ pub enum Feature {
6545 Stream ,
6646 #[ serde( alias = "attach_table" , alias = "ATTACH_TABLE" ) ]
6747 AttacheTable ,
68- #[ serde( alias = "compute_quota" , alias = "COMPUTE_QUOTA" ) ]
69- ComputeQuota ( ComputeQuota ) ,
70- #[ serde( alias = "storage_quota" , alias = "STORAGE_QUOTA" ) ]
71- StorageQuota ( StorageQuota ) ,
7248 #[ serde( alias = "amend_table" , alias = "AMEND_TABLE" ) ]
7349 AmendTable ,
7450 #[ serde( alias = "hilbert_clustering" , alias = "HILBERT_CLUSTERING" ) ]
@@ -115,32 +91,6 @@ impl fmt::Display for Feature {
11591 Feature :: StorageEncryption => write ! ( f, "storage_encryption" ) ,
11692 Feature :: Stream => write ! ( f, "stream" ) ,
11793 Feature :: AttacheTable => write ! ( f, "attach_table" ) ,
118- Feature :: ComputeQuota ( v) => {
119- write ! ( f, "compute_quota(" ) ?;
120-
121- write ! ( f, "threads_num: " ) ?;
122- match & v. threads_num {
123- None => write ! ( f, "unlimited," ) ?,
124- Some ( threads_num) => write ! ( f, "{}" , * threads_num) ?,
125- } ;
126-
127- write ! ( f, ", memory_usage: " ) ?;
128- match v. memory_usage {
129- None => write ! ( f, "unlimited," ) ?,
130- Some ( memory_usage) => write ! ( f, "{}" , memory_usage) ?,
131- }
132- write ! ( f, ")" )
133- }
134- Feature :: StorageQuota ( v) => {
135- write ! ( f, "storage_quota(" ) ?;
136-
137- write ! ( f, "storage_usage: " ) ?;
138- match v. storage_usage {
139- None => write ! ( f, "unlimited," ) ?,
140- Some ( storage_usage) => write ! ( f, "{}" , storage_usage) ?,
141- }
142- write ! ( f, ")" )
143- }
14494 Feature :: AmendTable => write ! ( f, "amend_table" ) ,
14595 Feature :: SystemManagement => write ! ( f, "system_management" ) ,
14696 Feature :: HilbertClustering => write ! ( f, "hilbert_clustering" ) ,
@@ -167,30 +117,6 @@ impl Feature {
167117
168118 pub fn verify ( & self , feature : & Feature ) -> Result < VerifyResult , ErrorCode > {
169119 match ( self , feature) {
170- ( Feature :: ComputeQuota ( c) , Feature :: ComputeQuota ( v) ) => {
171- if let Some ( thread_num) = c. threads_num {
172- if thread_num <= v. threads_num . unwrap_or ( usize:: MAX ) {
173- return Ok ( VerifyResult :: Failure ) ;
174- }
175- }
176-
177- if let Some ( max_memory_usage) = c. memory_usage {
178- if max_memory_usage <= v. memory_usage . unwrap_or ( usize:: MAX ) {
179- return Ok ( VerifyResult :: Failure ) ;
180- }
181- }
182-
183- Ok ( VerifyResult :: Success )
184- }
185- ( Feature :: StorageQuota ( c) , Feature :: StorageQuota ( v) ) => {
186- if let Some ( max_storage_usage) = c. storage_usage {
187- if max_storage_usage <= v. storage_usage . unwrap_or ( usize:: MAX ) {
188- return Ok ( VerifyResult :: Failure ) ;
189- }
190- }
191-
192- Ok ( VerifyResult :: Success )
193- }
194120 ( Feature :: MaxCpuQuota ( c) , Feature :: MaxCpuQuota ( v) ) => match c > v {
195121 true => Ok ( VerifyResult :: Success ) ,
196122 false => Ok ( VerifyResult :: Failure ) ,
@@ -276,24 +202,6 @@ impl LicenseInfo {
276202
277203 DisplayFeatures ( self )
278204 }
279-
280- /// Get Storage Quota from given license info.
281- ///
282- /// Returns the default storage quota if the storage quota is not licensed.
283- pub fn get_storage_quota ( & self ) -> StorageQuota {
284- let Some ( features) = self . features . as_ref ( ) else {
285- return StorageQuota :: default ( ) ;
286- } ;
287-
288- features
289- . iter ( )
290- . find_map ( |f| match f {
291- Feature :: StorageQuota ( v) => Some ( v) ,
292- _ => None ,
293- } )
294- . cloned ( )
295- . unwrap_or_default ( )
296- }
297205}
298206
299207#[ cfg( test) ]
@@ -346,31 +254,6 @@ mod tests {
346254 Feature :: AttacheTable ,
347255 serde_json:: from_str:: <Feature >( "\" ATTACH_TABLE\" " ) . unwrap( )
348256 ) ;
349- assert_eq ! (
350- Feature :: ComputeQuota ( ComputeQuota {
351- threads_num: Some ( 1 ) ,
352- memory_usage: Some ( 1 ) ,
353- } ) ,
354- serde_json:: from_str:: <Feature >(
355- "{\" ComputeQuota\" :{\" threads_num\" :1, \" memory_usage\" :1}}"
356- )
357- . unwrap( )
358- ) ;
359-
360- assert_eq ! (
361- Feature :: ComputeQuota ( ComputeQuota {
362- threads_num: None ,
363- memory_usage: Some ( 1 ) ,
364- } ) ,
365- serde_json:: from_str:: <Feature >( "{\" ComputeQuota\" :{\" memory_usage\" :1}}" ) . unwrap( )
366- ) ;
367-
368- assert_eq ! (
369- Feature :: StorageQuota ( StorageQuota {
370- storage_usage: Some ( 1 ) ,
371- } ) ,
372- serde_json:: from_str:: <Feature >( "{\" StorageQuota\" :{\" storage_usage\" :1}}" ) . unwrap( )
373- ) ;
374257
375258 assert_eq ! (
376259 Feature :: AmendTable ,
@@ -441,13 +324,6 @@ mod tests {
441324 Feature :: StorageEncryption ,
442325 Feature :: Stream ,
443326 Feature :: AttacheTable ,
444- Feature :: ComputeQuota ( ComputeQuota {
445- threads_num: Some ( 1 ) ,
446- memory_usage: Some ( 1 ) ,
447- } ) ,
448- Feature :: StorageQuota ( StorageQuota {
449- storage_usage: Some ( 1 ) ,
450- } ) ,
451327 Feature :: AmendTable ,
452328 Feature :: HilbertClustering ,
453329 Feature :: NgramIndex ,
@@ -459,7 +335,7 @@ mod tests {
459335 } ;
460336
461337 assert_eq ! (
462- "LicenseInfo{ type: enterprise, org: databend, tenants: [databend_tenant,foo], features: [aggregate_index,amend_table,attach_table,compute_quota(threads_num: 1, memory_usage: 1), computed_column,data_mask,hilbert_clustering,inverted_index,license_info,ngram_index,private_task,row_access_policy,storage_encryption,storage_quota(storage_usage: 1) ,stream,system_history,vacuum,virtual_column,workload_group] }" ,
338+ "LicenseInfo{ type: enterprise, org: databend, tenants: [databend_tenant,foo], features: [aggregate_index,amend_table,attach_table,computed_column,data_mask,hilbert_clustering,inverted_index,license_info,ngram_index,private_task,row_access_policy,storage_encryption,stream,system_history,vacuum,virtual_column,workload_group] }" ,
463339 license_info. to_string( )
464340 ) ;
465341 }
0 commit comments