Skip to content

Commit 4093b5c

Browse files
authored
Load storage metadata as global static variable (#313)
1 parent 29174ea commit 4093b5c

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ itertools = "0.10"
7272
xxhash-rust = { version = "0.8", features = ["xxh3"] }
7373
xz2 = { version = "*", features=["static"] }
7474
bzip2 = { version = "*", features=["static"] }
75+
once_cell = "1.17.1"
7576

7677
[build-dependencies]
7778
static-files = "0.2"

server/src/banner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crossterm::style::Stylize;
2222
use crate::utils::uid::Uid;
2323
use crate::{option::Config, storage::StorageMetadata};
2424

25-
pub async fn print(config: &Config, meta: StorageMetadata) {
25+
pub async fn print(config: &Config, meta: &StorageMetadata) {
2626
print_ascii_art();
2727
let scheme = config.parseable.get_scheme();
2828
status_info(config, &scheme, meta.deployment_id);
@@ -149,11 +149,11 @@ pub mod about {
149149
eprint!("{}", fmt_latest_version.red());
150150
}
151151

152-
pub async fn print(config: &Config, meta: StorageMetadata) {
152+
pub async fn print(config: &Config, meta: &StorageMetadata) {
153153
// print current version
154154
let current = current();
155155
let latest_release = if config.parseable.check_update {
156-
update::get_latest(&meta).await.ok()
156+
update::get_latest(meta).await.ok()
157157
} else {
158158
None
159159
};

server/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ async fn main() -> anyhow::Result<()> {
6969
CONFIG.validate_staging()?;
7070
CONFIG.validate_storage(&*storage).await;
7171
let metadata = storage::resolve_parseable_metadata().await?;
72-
banner::print(&CONFIG, metadata).await;
72+
metadata.set_global();
73+
banner::print(&CONFIG, storage::StorageMetadata::global()).await;
7374
let prometheus = metrics::build_metrics_handler();
7475
CONFIG.storage().register_store_metrics(&prometheus);
7576

server/src/storage/store_metadata.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ use std::{
2121
path::PathBuf,
2222
};
2323

24+
use once_cell::sync::OnceCell;
2425
use serde::{Deserialize, Serialize};
2526
use std::io;
2627

2728
use crate::{option::CONFIG, utils::uid};
2829

2930
use super::object_storage::PARSEABLE_METADATA_FILE_NAME;
3031

32+
pub static STORAGE_METADATA: OnceCell<StorageMetadata> = OnceCell::new();
33+
3134
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3235
pub struct StorageMetadata {
3336
pub version: String,
@@ -59,6 +62,16 @@ impl StorageMetadata {
5962
stream: Vec::new(),
6063
}
6164
}
65+
66+
pub fn global() -> &'static Self {
67+
STORAGE_METADATA
68+
.get()
69+
.expect("gloabal static is initialized")
70+
}
71+
72+
pub fn set_global(self) {
73+
STORAGE_METADATA.set(self).expect("only set once")
74+
}
6275
}
6376

6477
pub fn check_metadata_conflict(

0 commit comments

Comments
 (0)