20260530 行为保持源码治理重构
This commit is contained in:
119
src/storage/config.rs
Normal file
119
src/storage/config.rs
Normal file
@@ -0,0 +1,119 @@
|
||||
use rocksdb::{ColumnFamilyDescriptor, DBCompressionType, Options};
|
||||
|
||||
pub const CF_REPOSITORY_VIEW: &str = "repository_view";
|
||||
pub const CF_RAW_BY_HASH: &str = "raw_by_hash";
|
||||
pub const CF_RAW_BLOB: &str = "raw_blob";
|
||||
pub const CF_VCIR: &str = "vcir";
|
||||
pub const CF_MANIFEST_REPLAY_META: &str = "manifest_replay_meta";
|
||||
pub const CF_AUDIT_RULE_INDEX: &str = "audit_rule_index";
|
||||
pub const CF_RRDP_SOURCE: &str = "rrdp_source";
|
||||
pub const CF_RRDP_SOURCE_MEMBER: &str = "rrdp_source_member";
|
||||
pub const CF_RRDP_URI_OWNER: &str = "rrdp_uri_owner";
|
||||
|
||||
pub const ALL_COLUMN_FAMILY_NAMES: &[&str] = &[
|
||||
CF_REPOSITORY_VIEW,
|
||||
CF_RAW_BY_HASH,
|
||||
CF_RAW_BLOB,
|
||||
CF_VCIR,
|
||||
CF_MANIFEST_REPLAY_META,
|
||||
CF_AUDIT_RULE_INDEX,
|
||||
CF_RRDP_SOURCE,
|
||||
CF_RRDP_SOURCE_MEMBER,
|
||||
CF_RRDP_URI_OWNER,
|
||||
];
|
||||
|
||||
pub(super) const REPOSITORY_VIEW_KEY_PREFIX: &str = "repo_view:";
|
||||
pub(super) const RAW_BY_HASH_KEY_PREFIX: &str = "rawbyhash:";
|
||||
pub(super) const RAW_BLOB_KEY_PREFIX: &str = "rawblob:";
|
||||
pub(super) const VCIR_KEY_PREFIX: &str = "vcir:";
|
||||
pub(super) const MANIFEST_REPLAY_META_KEY_PREFIX: &str = "manifest_replay_meta:";
|
||||
pub(super) const AUDIT_ROA_RULE_KEY_PREFIX: &str = "audit:roa_rule:";
|
||||
pub(super) const AUDIT_ASPA_RULE_KEY_PREFIX: &str = "audit:aspa_rule:";
|
||||
pub(super) const AUDIT_ROUTER_KEY_RULE_KEY_PREFIX: &str = "audit:router_key_rule:";
|
||||
pub(super) const RRDP_SOURCE_KEY_PREFIX: &str = "rrdp_source:";
|
||||
pub(super) const RRDP_SOURCE_MEMBER_KEY_PREFIX: &str = "rrdp_source_member:";
|
||||
pub(super) const RRDP_URI_OWNER_KEY_PREFIX: &str = "rrdp_uri_owner:";
|
||||
|
||||
const WORK_DB_BLOB_MODE_ENV: &str = "RPKI_WORK_DB_BLOB_MODE";
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(super) enum WorkDbBlobMode {
|
||||
Current,
|
||||
Disabled,
|
||||
Lz4,
|
||||
}
|
||||
|
||||
pub(super) fn parse_work_db_blob_mode(raw: &str) -> Option<WorkDbBlobMode> {
|
||||
match raw.trim().to_ascii_lowercase().as_str() {
|
||||
"" | "default" => Some(default_work_db_blob_mode()),
|
||||
"current" | "legacy" => Some(WorkDbBlobMode::Current),
|
||||
"disabled" | "disable" | "off" | "none" | "no_blob" | "no-blob" => {
|
||||
Some(WorkDbBlobMode::Disabled)
|
||||
}
|
||||
"lz4" | "blob_lz4" | "blob-lz4" => Some(WorkDbBlobMode::Lz4),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn default_work_db_blob_mode() -> WorkDbBlobMode {
|
||||
WorkDbBlobMode::Disabled
|
||||
}
|
||||
|
||||
pub(super) fn work_db_blob_mode_from_env() -> WorkDbBlobMode {
|
||||
let Ok(raw) = std::env::var(WORK_DB_BLOB_MODE_ENV) else {
|
||||
return default_work_db_blob_mode();
|
||||
};
|
||||
match parse_work_db_blob_mode(&raw) {
|
||||
Some(mode) => mode,
|
||||
None => {
|
||||
eprintln!(
|
||||
"warning: unsupported {WORK_DB_BLOB_MODE_ENV}={raw:?}; using default work-db blobdb mode"
|
||||
);
|
||||
default_work_db_blob_mode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn configure_work_db_options(opts: &mut Options, blob_mode: WorkDbBlobMode) {
|
||||
opts.set_compression_type(DBCompressionType::Lz4);
|
||||
match blob_mode {
|
||||
WorkDbBlobMode::Current => enable_blobdb_current(opts),
|
||||
WorkDbBlobMode::Disabled => {}
|
||||
WorkDbBlobMode::Lz4 => {
|
||||
enable_blobdb_current(opts);
|
||||
opts.set_blob_compression_type(DBCompressionType::Lz4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn cf_opts(blob_mode: WorkDbBlobMode) -> Options {
|
||||
let mut opts = Options::default();
|
||||
configure_work_db_options(&mut opts, blob_mode);
|
||||
opts
|
||||
}
|
||||
|
||||
pub fn column_family_descriptors() -> Vec<ColumnFamilyDescriptor> {
|
||||
column_family_descriptors_for_blob_mode(work_db_blob_mode_from_env())
|
||||
}
|
||||
|
||||
pub(super) fn column_family_descriptors_for_blob_mode(
|
||||
blob_mode: WorkDbBlobMode,
|
||||
) -> Vec<ColumnFamilyDescriptor> {
|
||||
ALL_COLUMN_FAMILY_NAMES
|
||||
.iter()
|
||||
.map(|name| ColumnFamilyDescriptor::new(*name, cf_opts(blob_mode)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(super) fn enable_blobdb_current(opts: &mut Options) {
|
||||
#[allow(unused_mut)]
|
||||
let mut _enabled = false;
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn _set(opts: &mut Options) {
|
||||
opts.set_enable_blob_files(true);
|
||||
opts.set_min_blob_size(1024);
|
||||
}
|
||||
|
||||
_set(opts);
|
||||
}
|
||||
Reference in New Issue
Block a user