Skip to content

Commit c118cd8

Browse files
committed
test
1 parent f48aba0 commit c118cd8

File tree

8 files changed

+85
-53
lines changed

8 files changed

+85
-53
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ env-file
1313
parseable
1414
parseable_*
1515
parseable-env-secret
16+
cache

server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ xxhash-rust = { version = "0.8", features = ["xxh3"] }
9696
xz2 = { version = "*", features = ["static"] }
9797
nom = "7.1.3"
9898
humantime = "2.1.0"
99-
human-size = "0.4"
99+
human-size = "0.4.3"
100100
openid = { version = "0.12.0", default-features = false, features = ["rustls"] }
101101
url = "2.4.0"
102102
http-auth-basic = "0.3.3"

server/src/banner.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ fn print_ascii_art() {
4545
"#;
4646

4747
eprint!("{ascii_name}");
48-
eprintln!(
49-
"
50-
Welcome to Parseable Server!"
51-
);
5248
}
5349

5450
fn status_info(config: &Config, scheme: &str, id: Uid) {
@@ -71,26 +67,30 @@ fn status_info(config: &Config, scheme: &str, id: Uid) {
7167
None => "Not Configured".grey(),
7268
};
7369

70+
eprintln!(
71+
"
72+
Welcome to Parseable Server! Deployment UID: \"{}\"",
73+
id.to_string(),
74+
);
75+
7476
eprintln!(
7577
"
7678
{}
7779
Address: {}
7880
Credentials: {}
79-
Deployment UID: \"{}\"
8081
LLM: \"{}\"",
8182
"Server:".to_string().bold(),
8283
address,
8384
credentials,
84-
id.to_string(),
8585
llm_status
8686
);
8787
}
8888

8989
/// Prints information about the `ObjectStorage`.
9090
/// - Mode (`Local drive`, `S3 bucket`)
9191
/// - Staging (temporary landing point for incoming events)
92-
/// - Store (path where the data is stored)
93-
/// - Latency
92+
/// - Cache (local cache of data)
93+
/// - Store (path where the data is stored and its latency)
9494
async fn storage_info(config: &Config) {
9595
let storage = config.storage();
9696
let latency = storage.get_object_store().get_latency().await;
@@ -99,29 +99,33 @@ async fn storage_info(config: &Config) {
9999
"
100100
{}
101101
Mode: \"{}\"
102-
Staging: \"{}\"
103-
Store: \"{}\"
104-
Latency: \"{:?}\"",
102+
Staging: \"{}\"",
105103
"Storage:".to_string().bold(),
106104
config.mode_string(),
107105
config.staging_dir().to_string_lossy(),
108-
storage.get_endpoint(),
109-
latency
110106
);
111107

112108
if let Some(path) = &config.parseable.local_cache_path {
113-
let size: SpecificSize<human_size::Gigabyte> =
109+
let size: SpecificSize<human_size::Gigibyte> =
114110
SpecificSize::new(config.parseable.local_cache_size as f64, human_size::Byte)
115111
.unwrap()
116112
.into();
117113

118114
eprintln!(
119115
"\
120-
{:8}Cache: \"{}\"
121-
Cache Size: \"{}\"",
116+
{:8}Cache: \"{}\", (size: {})",
122117
"",
123118
path.display(),
124119
size
125120
);
126121
}
122+
123+
eprintln!(
124+
"\
125+
{:8}Store: \"{}\", (latency: {:?})",
126+
"",
127+
storage.get_endpoint(),
128+
latency
129+
);
130+
127131
}

server/src/catalog/manifest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub enum SortOrder {
4343
}
4444

4545
pub type SortInfo = (String, SortOrder);
46+
pub const CURRENT_MANIFEST_VERSION: &str = "v1";
4647

4748
/// An entry in a manifest which points to a single file.
4849
/// Additionally, it is meant to store the statistics for the file it
@@ -67,7 +68,7 @@ pub struct Manifest {
6768
impl Default for Manifest {
6869
fn default() -> Self {
6970
Self {
70-
version: "v1".to_string(),
71+
version: CURRENT_MANIFEST_VERSION.to_string(),
7172
files: Vec::default(),
7273
}
7374
}

server/src/catalog/snapshot.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use chrono::{DateTime, Utc};
2222

2323
use crate::query::PartialTimeFilter;
2424

25+
pub const CURRENT_SNAPSHOT_VERSION: &str = "v1";
26+
2527
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
2628
pub struct Snapshot {
2729
pub version: String,
@@ -31,7 +33,7 @@ pub struct Snapshot {
3133
impl Default for Snapshot {
3234
fn default() -> Self {
3335
Self {
34-
version: "v1".to_string(),
36+
version: CURRENT_SNAPSHOT_VERSION.to_string(),
3537
manifest_list: Vec::default(),
3638
}
3739
}

server/src/localcache.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ use itertools::{Either, Itertools};
2525
use object_store::{local::LocalFileSystem, ObjectStore};
2626
use once_cell::sync::OnceCell;
2727
use tokio::{fs, sync::Mutex};
28+
use human_size::{SpecificSize, Gigibyte, Byte};
2829

2930
use crate::option::CONFIG;
3031

3132
pub const STREAM_CACHE_FILENAME: &str = ".cache.json";
3233
pub const CACHE_META_FILENAME: &str = ".cache_meta.json";
34+
pub const CURRENT_CACHE_VERSION: &str = "v1";
3335

3436
#[derive(Debug, serde::Deserialize, serde::Serialize)]
3537
pub struct LocalCache {
@@ -42,7 +44,7 @@ pub struct LocalCache {
4244
impl LocalCache {
4345
fn new() -> Self {
4446
Self {
45-
version: "v1".to_string(),
47+
version: CURRENT_CACHE_VERSION.to_string(),
4648
current_size: 0,
4749
files: Cache::new(100),
4850
}
@@ -58,7 +60,7 @@ pub struct CacheMeta {
5860
impl CacheMeta {
5961
fn new() -> Self {
6062
Self {
61-
version: "v1".to_string(),
63+
version: CURRENT_CACHE_VERSION.to_string(),
6264
size_capacity: 0,
6365
}
6466
}
@@ -97,7 +99,9 @@ impl LocalCacheManager {
9799

98100
pub async fn validate(&self, config_capacity: u64) -> Result<(), CacheError> {
99101
fs::create_dir_all(&self.cache_path).await?;
100-
let path = cache_meta_path(&self.cache_path).unwrap();
102+
let path = cache_meta_path(&self.cache_path)
103+
.map_err(|err| CacheError::ObjectStoreError(err.into()))?;
104+
101105
let resp = self
102106
.filesystem
103107
.get(&path)
@@ -107,7 +111,15 @@ impl LocalCacheManager {
107111
let updated_cache = match resp {
108112
Ok(bytes) => {
109113
let mut meta: CacheMeta = serde_json::from_slice(&bytes)?;
110-
if !meta.size_capacity == config_capacity {
114+
if meta.size_capacity != config_capacity {
115+
// log the change in cache size
116+
let configured_size_human: SpecificSize<Gigibyte> = SpecificSize::new(config_capacity as f64, Byte).unwrap().into();
117+
let current_size_human: SpecificSize<Gigibyte> = SpecificSize::new(meta.size_capacity as f64, Byte).unwrap().into();
118+
log::warn!(
119+
"Cache size is updated from {} to {}",
120+
current_size_human,
121+
configured_size_human
122+
);
111123
meta.size_capacity = config_capacity;
112124
Some(meta)
113125
} else {
@@ -123,10 +135,6 @@ impl LocalCacheManager {
123135
};
124136

125137
if let Some(updated_cache) = updated_cache {
126-
log::info!(
127-
"Cache is updated to new size of {} Bytes",
128-
&updated_cache.size_capacity
129-
);
130138
self.filesystem
131139
.put(&path, serde_json::to_vec(&updated_cache)?.into())
132140
.await?

server/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ use crate::localcache::LocalCacheManager;
5454
#[actix_web::main]
5555
async fn main() -> anyhow::Result<()> {
5656
env_logger::init();
57-
CONFIG.validate();
5857
let storage = CONFIG.storage().get_object_store();
5958
CONFIG.validate_staging()?;
6059
migration::run_metadata_migration(&CONFIG).await?;

server/src/option.rs

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ use std::sync::Arc;
2626
use url::Url;
2727

2828
use crate::oidc::{self, OpenidConfig};
29-
use crate::storage::{FSConfig, ObjectStorageProvider, S3Config, LOCAL_SYNC_INTERVAL};
29+
use crate::storage::{FSConfig, ObjectStorageProvider, S3Config};
3030
use crate::utils::validate_path_is_writeable;
3131

3232
pub const MIN_CACHE_SIZE_BYTES: u64 = 1000u64.pow(3); // 1 GiB
33+
pub const MIN_QUERY_MEM_POOL_SIZE_BYTES: u64 = 1000u64.pow(3); // 1 GiB
3334

3435
pub static CONFIG: Lazy<Arc<Config>> = Lazy::new(|| Arc::new(Config::new()));
3536

@@ -98,13 +99,6 @@ impl Config {
9899
_ => unreachable!(),
99100
}
100101
}
101-
102-
pub fn validate(&self) {
103-
if CONFIG.parseable.upload_interval < LOCAL_SYNC_INTERVAL {
104-
panic!("object storage upload_interval (P_STORAGE_UPLOAD_INTERVAL) must be 60 seconds or more");
105-
}
106-
}
107-
108102
pub fn validate_staging(&self) -> anyhow::Result<()> {
109103
let staging_path = self.staging_dir();
110104
validate_path_is_writeable(staging_path)
@@ -412,17 +406,17 @@ impl Server {
412406
.env("P_CACHE_DIR")
413407
.value_name("DIR")
414408
.value_parser(validation::canonicalize_path)
415-
.help("Local path to be used for caching latest files")
409+
.help("Local path on this device to be used for caching data")
416410
.next_line_help(true),
417411
)
418412
.arg(
419413
Arg::new(Self::CACHE_SIZE)
420414
.long(Self::CACHE_SIZE)
421415
.env("P_CACHE_SIZE")
422416
.value_name("size")
423-
.default_value("1Gib")
424-
.value_parser(validation::human_size_to_bytes)
425-
.help("Size for cache in human readable format (e.g 1GiB, 2GiB, 100MB)")
417+
.default_value("1GiB")
418+
.value_parser(validation::cache_size)
419+
.help("Maximum allowed cache size for all streams combined (In human readable format, e.g 1GiB, 2GiB, 100MB)")
426420
.next_line_help(true),
427421
)
428422
.arg(
@@ -431,7 +425,7 @@ impl Server {
431425
.env("P_STORAGE_UPLOAD_INTERVAL")
432426
.value_name("SECONDS")
433427
.default_value("60")
434-
.value_parser(value_parser!(u64))
428+
.value_parser(validation::upload_interval)
435429
.help("Interval in seconds after which staging data would be sent to the storage")
436430
.next_line_help(true),
437431
)
@@ -441,15 +435,15 @@ impl Server {
441435
.env("P_USERNAME")
442436
.value_name("STRING")
443437
.required(true)
444-
.help("Admin username for this server"),
438+
.help("Admin username to be set for this Parseable server"),
445439
)
446440
.arg(
447441
Arg::new(Self::PASSWORD)
448442
.long(Self::PASSWORD)
449443
.env("P_PASSWORD")
450444
.value_name("STRING")
451445
.required(true)
452-
.help("Admin password for this server"),
446+
.help("Admin password to be set for this Parseable server"),
453447
)
454448
.arg(
455449
Arg::new(Self::CHECK_UPDATE)
@@ -459,7 +453,7 @@ impl Server {
459453
.required(false)
460454
.default_value("true")
461455
.value_parser(value_parser!(bool))
462-
.help("Disable/Enable checking for updates"),
456+
.help("Enable/Disable checking for new Parseable release"),
463457
)
464458
.arg(
465459
Arg::new(Self::SEND_ANALYTICS)
@@ -469,15 +463,15 @@ impl Server {
469463
.required(false)
470464
.default_value("true")
471465
.value_parser(value_parser!(bool))
472-
.help("Disable/Enable sending anonymous telemetry"),
466+
.help("Enable/Disable anonymous telemetry data collection"),
473467
)
474468
.arg(
475469
Arg::new(Self::OPEN_AI_KEY)
476470
.long(Self::OPEN_AI_KEY)
477471
.env("P_OPENAI_API_KEY")
478472
.value_name("STRING")
479473
.required(false)
480-
.help("OpenAI key to enable llm feature"),
474+
.help("OpenAI key to enable llm features"),
481475
)
482476
.arg(
483477
Arg::new(Self::OPENID_CLIENT_ID)
@@ -539,8 +533,8 @@ impl Server {
539533
.env("P_QUERY_MEMORY_LIMIT")
540534
.value_name("STRING")
541535
.required(false)
542-
.value_parser(validation::size)
543-
.help("Memory allocated to query in human readable format (e.g 1GiB, 2GiB, 100MB)"),
536+
.value_parser(validation::query_memory_pool_size)
537+
.help("Memory allocated to query sub system (In human readable format, e.g 1GiB, 2GiB, 100MB)"),
544538
)
545539
.arg(
546540
Arg::new(Self::ROW_GROUP_SIZE)
@@ -612,10 +606,11 @@ pub mod validation {
612606
str::FromStr,
613607
};
614608

615-
use human_size::SpecificSize;
616-
617-
use crate::option::MIN_CACHE_SIZE_BYTES;
609+
use human_size::{SpecificSize,multiples};
618610

611+
use crate::option::{MIN_CACHE_SIZE_BYTES, MIN_QUERY_MEM_POOL_SIZE_BYTES};
612+
use crate::storage::LOCAL_SYNC_INTERVAL;
613+
619614
pub fn file_path(s: &str) -> Result<PathBuf, String> {
620615
if s.is_empty() {
621616
return Err("empty path".to_owned());
@@ -652,8 +647,7 @@ pub mod validation {
652647
url::Url::parse(s).map_err(|_| "Invalid URL provided".to_string())
653648
}
654649

655-
pub fn human_size_to_bytes(s: &str) -> Result<u64, String> {
656-
use human_size::multiples;
650+
fn human_size_to_bytes(s: &str) -> Result<u64, String> {
657651
fn parse_and_map<T: human_size::Multiple>(
658652
s: &str,
659653
) -> Result<u64, human_size::ParsingError> {
@@ -668,12 +662,35 @@ pub mod validation {
668662
.or(parse_and_map::<multiples::Terabyte>(s))
669663
.map_err(|_| "Could not parse given size".to_string())?;
670664

665+
Ok(size)
666+
}
667+
668+
pub fn cache_size(s: &str) -> Result<u64, String> {
669+
let size = human_size_to_bytes(s)?;
671670
if size < MIN_CACHE_SIZE_BYTES {
672671
return Err(
673672
"Specified value of cache size is smaller than current minimum of 1GiB".to_string(),
674673
);
675674
}
675+
Ok(size)
676+
}
676677

678+
pub fn query_memory_pool_size(s: &str) -> Result<u64, String> {
679+
let size = human_size_to_bytes(s)?;
680+
if size < MIN_QUERY_MEM_POOL_SIZE_BYTES {
681+
return Err(
682+
"Specified value of query memory pool size is smaller than current minimum of 1GiB".to_string(),
683+
);
684+
}
677685
Ok(size)
678686
}
687+
688+
pub fn upload_interval(s: &str) -> Result<u64, String> {
689+
let u = s.parse::<u64>().map_err(|_| "invalid upload interval".to_string())?;
690+
if u < LOCAL_SYNC_INTERVAL {
691+
return Err("object storage upload interval must be 60 seconds or more".to_string());
692+
}
693+
Ok(u)
694+
}
695+
679696
}

0 commit comments

Comments
 (0)