Disentangle deps, typechecks
This commit is contained in:
@@ -22,9 +22,6 @@ use serde::Serialize;
|
||||
use std::fmt;
|
||||
use std::time::Duration;
|
||||
use std::time::SystemTime;
|
||||
use tokio::io::ErrorKind;
|
||||
|
||||
const TEST_BACKEND: &str = "testbackend-00";
|
||||
|
||||
#[derive(Debug, ThisError)]
|
||||
#[cstm(name = "ConfigParse")]
|
||||
@@ -302,118 +299,6 @@ pub fn parse_config(inp: &[u8]) -> Result<ChannelConfigs, ConfigParseError> {
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
async fn read_local_config_real(
|
||||
channel: SfDbChannel,
|
||||
ncc: &NodeConfigCached,
|
||||
) -> Result<ChannelConfigs, ConfigParseError> {
|
||||
let path = ncc
|
||||
.node
|
||||
.sf_databuffer
|
||||
.as_ref()
|
||||
.ok_or_else(|| ConfigParseError::NotSupportedOnNode)?
|
||||
.data_base_path
|
||||
.join("config")
|
||||
.join(channel.name())
|
||||
.join("latest")
|
||||
.join("00000_Config");
|
||||
match tokio::fs::read(&path).await {
|
||||
Ok(buf) => parse_config(&buf),
|
||||
Err(e) => match e.kind() {
|
||||
ErrorKind::NotFound => Err(ConfigParseError::FileNotFound),
|
||||
ErrorKind::PermissionDenied => Err(ConfigParseError::PermissionDenied),
|
||||
e => {
|
||||
error!("read_local_config_real {e:?}");
|
||||
Err(ConfigParseError::IO)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async fn read_local_config_test(
|
||||
channel: SfDbChannel,
|
||||
ncc: &NodeConfigCached,
|
||||
) -> Result<ChannelConfigs, ConfigParseError> {
|
||||
if channel.name() == "test-gen-i32-dim0-v00" {
|
||||
let ts = 0;
|
||||
let ret = ChannelConfigs {
|
||||
format_version: 0,
|
||||
channel_name: channel.name().into(),
|
||||
entries: vec![ConfigEntry {
|
||||
ts: TsNano::from_ns(ts),
|
||||
ts_human: SystemTime::UNIX_EPOCH + Duration::from_nanos(ts as u64),
|
||||
pulse: 0,
|
||||
ks: 2,
|
||||
bs: DtNano::from_ns(DAY),
|
||||
split_count: ncc.node_config.cluster.nodes.len() as _,
|
||||
status: -1,
|
||||
bb: -1,
|
||||
modulo: -1,
|
||||
offset: -1,
|
||||
precision: -1,
|
||||
scalar_type: ScalarType::I32,
|
||||
is_compressed: false,
|
||||
is_shaped: false,
|
||||
is_array: false,
|
||||
byte_order: ByteOrder::Big,
|
||||
compression_method: None,
|
||||
shape: None,
|
||||
source_name: None,
|
||||
unit: None,
|
||||
description: None,
|
||||
optional_fields: None,
|
||||
value_converter: None,
|
||||
}],
|
||||
};
|
||||
Ok(ret)
|
||||
} else if channel.name() == "test-gen-i32-dim0-v01" {
|
||||
let ts = 0;
|
||||
let ret = ChannelConfigs {
|
||||
format_version: 0,
|
||||
channel_name: channel.name().into(),
|
||||
entries: vec![ConfigEntry {
|
||||
ts: TsNano::from_ns(ts),
|
||||
ts_human: SystemTime::UNIX_EPOCH + Duration::from_nanos(ts as u64),
|
||||
pulse: 0,
|
||||
ks: 2,
|
||||
bs: DtNano::from_ns(DAY),
|
||||
split_count: ncc.node_config.cluster.nodes.len() as _,
|
||||
status: -1,
|
||||
bb: -1,
|
||||
modulo: -1,
|
||||
offset: -1,
|
||||
precision: -1,
|
||||
scalar_type: ScalarType::I32,
|
||||
is_compressed: false,
|
||||
is_shaped: false,
|
||||
is_array: false,
|
||||
byte_order: ByteOrder::Big,
|
||||
compression_method: None,
|
||||
shape: None,
|
||||
source_name: None,
|
||||
unit: None,
|
||||
description: None,
|
||||
optional_fields: None,
|
||||
value_converter: None,
|
||||
}],
|
||||
};
|
||||
Ok(ret)
|
||||
} else {
|
||||
Err(ConfigParseError::NotSupported)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO can I take parameters as ref, even when used in custom streams?
|
||||
pub async fn read_local_config(
|
||||
channel: SfDbChannel,
|
||||
ncc: NodeConfigCached,
|
||||
) -> Result<ChannelConfigs, ConfigParseError> {
|
||||
if channel.backend() == TEST_BACKEND {
|
||||
read_local_config_test(channel, &ncc).await
|
||||
} else {
|
||||
read_local_config_real(channel, &ncc).await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum MatchingConfigEntry<'a> {
|
||||
None,
|
||||
|
||||
Reference in New Issue
Block a user