Refactor series lookup

This commit is contained in:
Dominik Werder
2024-05-16 23:33:34 +02:00
parent 82455a2b16
commit 6224df534a
41 changed files with 762 additions and 562 deletions

View File

@@ -30,9 +30,9 @@ impl From<ConfigParseError> for ConfigError {
pub async fn config_entry_best_match(
range: &NanoRange,
channel: SfDbChannel,
node_config: &NodeConfigCached,
ncc: &NodeConfigCached,
) -> Result<Option<ConfigEntry>, ConfigError> {
let channel_config = match read_local_config(channel.clone(), node_config.clone()).await {
let channel_config = match read_local_config(channel.clone(), ncc.clone()).await {
Ok(x) => x,
Err(e) => match e {
ConfigParseError::FileNotFound => return Ok(None),
@@ -59,9 +59,9 @@ pub async fn channel_configs(
pub async fn channel_config_best_match(
range: NanoRange,
channel: SfDbChannel,
node_config: &NodeConfigCached,
ncc: &NodeConfigCached,
) -> Result<Option<SfDbChConf>, ConfigError> {
let best = config_entry_best_match(&range, channel.clone(), node_config).await?;
let best = config_entry_best_match(&range, channel.clone(), ncc).await?;
match best {
None => Ok(None),
Some(entry) => {

View File

@@ -255,7 +255,7 @@ async fn open_files_inner(
return Ok(());
}
for &tb in &timebins {
let ts_bin = TsNano(tb * fetch_info.bs().ns());
let ts_bin = TsNano::from_ns(tb * fetch_info.bs().ns());
if ts_bin.ns() >= range.end {
continue;
}
@@ -350,7 +350,7 @@ async fn open_expanded_files_inner(
}
let mut p1 = None;
for (i1, tb) in timebins.iter().enumerate().rev() {
let ts_bin = TsNano(tb * fetch_info.bs().ns());
let ts_bin = TsNano::from_ns(tb * fetch_info.bs().ns());
if ts_bin.ns() <= range.beg {
p1 = Some(i1);
break;

View File

@@ -385,7 +385,8 @@ impl FileContentStream2 {
fn make_reading(&mut self) {
let mut buf = Box::new(BytesMut::with_capacity(self.disk_io_tune.read_buffer_len));
let bufref = unsafe { &mut *((&mut buf as &mut BytesMut) as *mut BytesMut) };
// let bufref = unsafe { &mut *((&mut buf as &mut BytesMut) as *mut BytesMut) };
let bufref: &mut BytesMut = err::todoval();
let fileref = unsafe { &mut *((&mut self.file) as *mut Pin<Box<File>>) };
let fut = AsyncReadExt::read_buf(fileref, bufref).map_err(|e| e.into());
self.fcs = FCS2::Reading((buf, Box::pin(fut)));

View File

@@ -164,7 +164,7 @@ async fn gen_channel(chn: &ChannelGenProps, split: u32, node: &Node, ensemble: &
.await
.map_err(|k| Error::with_msg(format!("can not generate config {:?}", k)))?;
let mut evix = 0;
let mut ts = TsNano(0);
let mut ts = TsNano::from_ns(0);
let mut pulse = 0;
while ts.ns() < DAY * 3 {
let res = gen_timebin(
@@ -352,7 +352,7 @@ async fn gen_timebin(
let mut evix = evix;
let mut ts = ts;
let mut pulse = pulse;
let tsmax = TsNano((tb + 1) * config.time_bin_size.ns());
let tsmax = TsNano::from_ns((tb + 1) * config.time_bin_size.ns());
while ts.ns() < tsmax.ns() {
match gen_var {
// TODO
@@ -377,7 +377,7 @@ async fn gen_timebin(
}
}
evix += 1;
ts.0 += ts_spacing;
ts = ts.add_ns(ts_spacing);
pulse += 1;
}
let ret = GenTimebinRes { evix, ts, pulse };

View File

@@ -197,7 +197,7 @@ pub fn parse_event(buf: &[u8]) -> Result<(u32, TsNano), Error> {
return Err(Error::with_msg(format!("len mismatch len1: {} len2: {}", len1, len2)));
}
let ts = u64::from_be_bytes(*array_ref![buf, 12, 8]);
Ok((len1 as u32, TsNano(ts)))
Ok((len1 as u32, TsNano::from_ns(ts)))
}
pub async fn read_event_at(pos: u64, file: &mut File) -> Result<(u32, TsNano), Error> {

View File

@@ -98,12 +98,12 @@ pub fn make_event_blobs_stream(
event_chunker_conf: EventChunkerConf,
disk_io_tune: DiskIoTune,
reqctx: ReqCtxArc,
node_config: &NodeConfigCached,
ncc: &NodeConfigCached,
) -> Result<EventChunkerMultifile, Error> {
debug!("make_local_event_blobs_stream {fetch_info:?} disk_io_tune {disk_io_tune:?}");
// TODO should not need this for correctness.
// Should limit based on return size and latency.
let out_max_len = if node_config.node_config.cluster.is_central_storage {
let out_max_len = if ncc.node_config.cluster.is_central_storage {
128
} else {
128
@@ -111,8 +111,8 @@ pub fn make_event_blobs_stream(
let event_blobs = EventChunkerMultifile::new(
range,
fetch_info.clone(),
node_config.node.clone(),
node_config.ix,
ncc.node.clone(),
ncc.ix,
disk_io_tune,
event_chunker_conf,
expand,
@@ -126,7 +126,7 @@ pub fn make_event_blobs_pipe_real(
subq: &EventsSubQuery,
fetch_info: &SfChFetchInfo,
reqctx: ReqCtxArc,
node_config: &NodeConfigCached,
ncc: &NodeConfigCached,
) -> Result<Pin<Box<dyn Stream<Item = Sitemty<EventFull>> + Send>>, Error> {
let expand = subq.transform().need_one_before_range();
let range = subq.range();
@@ -138,7 +138,7 @@ pub fn make_event_blobs_pipe_real(
event_chunker_conf,
subq.disk_io_tune(),
reqctx,
node_config,
ncc,
)?;
let pipe = Box::pin(event_blobs) as _;
Ok(pipe)
@@ -191,12 +191,12 @@ pub fn make_event_blobs_pipe(
subq: &EventsSubQuery,
fetch_info: &SfChFetchInfo,
reqctx: ReqCtxArc,
node_config: &NodeConfigCached,
ncc: &NodeConfigCached,
) -> Result<Pin<Box<dyn Stream<Item = Sitemty<EventFull>> + Send>>, Error> {
debug!("make_event_blobs_pipe {subq:?}");
if subq.backend() == TEST_BACKEND {
make_event_blobs_pipe_test(subq, node_config)
make_event_blobs_pipe_test(subq, ncc)
} else {
make_event_blobs_pipe_real(subq, fetch_info, reqctx, node_config)
make_event_blobs_pipe_real(subq, fetch_info, reqctx, ncc)
}
}