WIP best config select
This commit is contained in:
@@ -205,16 +205,16 @@ async fn update_db_with_channel_names_inner(
|
|||||||
info!("update_db_with_channel_names connection done");
|
info!("update_db_with_channel_names connection done");
|
||||||
let node_disk_ident = get_node_disk_ident(&node_config, &dbc).await?;
|
let node_disk_ident = get_node_disk_ident(&node_config, &dbc).await?;
|
||||||
info!("update_db_with_channel_names get_node_disk_ident done");
|
info!("update_db_with_channel_names get_node_disk_ident done");
|
||||||
{
|
let insert_sql = concat!(
|
||||||
let sql = concat!(
|
"insert into channels (facility, name) select facility, name from (values ($1::bigint, $2::text)) v1 (facility, name)",
|
||||||
"insert into channels (facility, name) select facility, name from (values ($1::bigint, $2::text)) v1 (facility, name)",
|
" where not exists (select 1 from channels t1 where t1.facility = v1.facility and t1.name = v1.name)",
|
||||||
" where not exists (select 1 from channels t1 where t1.facility = v1.facility and t1.name = v1.name)",
|
" on conflict do nothing",
|
||||||
" on conflict do nothing",
|
);
|
||||||
);
|
if false {
|
||||||
let fac: i64 = 1;
|
let fac: i64 = 1;
|
||||||
let ch = format!("tmp_dummy_04");
|
let ch = format!("tmp_dummy_04");
|
||||||
let ret = dbc
|
let ret = dbc
|
||||||
.query(sql, &[&fac, &ch])
|
.query(insert_sql, &[&fac, &ch])
|
||||||
.await
|
.await
|
||||||
.err_conv()
|
.err_conv()
|
||||||
.map_err(|e| format!("in channel name insert: {e}"));
|
.map_err(|e| format!("in channel name insert: {e}"));
|
||||||
@@ -234,13 +234,8 @@ async fn update_db_with_channel_names_inner(
|
|||||||
for ch in channel_names {
|
for ch in channel_names {
|
||||||
let fac = node_disk_ident.facility;
|
let fac = node_disk_ident.facility;
|
||||||
crate::delay_io_short().await;
|
crate::delay_io_short().await;
|
||||||
let sql = concat!(
|
|
||||||
"insert into channels (facility, name) select facility, name from (values ($1::bigint, $2::text)) v1 (facility, name)",
|
|
||||||
" where not exists (select 1 from channels t1 where t1.facility = v1.facility and t1.name = v1.name)",
|
|
||||||
" on conflict do nothing",
|
|
||||||
);
|
|
||||||
let ret = dbc
|
let ret = dbc
|
||||||
.query(sql, &[&fac, &ch])
|
.query(insert_sql, &[&fac, &ch])
|
||||||
.await
|
.await
|
||||||
.err_conv()
|
.err_conv()
|
||||||
.map_err(|e| format!("in channel name insert: {e}"));
|
.map_err(|e| format!("in channel name insert: {e}"));
|
||||||
|
|||||||
@@ -34,12 +34,7 @@ pub async fn channel_config_best_match(
|
|||||||
node_config: &NodeConfigCached,
|
node_config: &NodeConfigCached,
|
||||||
) -> Result<Option<SfDbChConf>, Error> {
|
) -> Result<Option<SfDbChConf>, Error> {
|
||||||
let best = config_entry_best_match(&range, channel.clone(), node_config).await?;
|
let best = config_entry_best_match(&range, channel.clone(), node_config).await?;
|
||||||
let channel_configs = read_local_config(channel.clone(), node_config.clone()).await?;
|
match best {
|
||||||
let entry_res = match extract_matching_config_entry(&range, &channel_configs) {
|
|
||||||
Ok(k) => k,
|
|
||||||
Err(e) => return Err(e),
|
|
||||||
};
|
|
||||||
match entry_res.best() {
|
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some(entry) => {
|
Some(entry) => {
|
||||||
let shape = match entry.to_shape() {
|
let shape = match entry.to_shape() {
|
||||||
|
|||||||
@@ -465,6 +465,7 @@ pub fn extract_matching_config_entry<'a>(
|
|||||||
.map({
|
.map({
|
||||||
let mut nx = None;
|
let mut nx = None;
|
||||||
move |(i, x)| {
|
move |(i, x)| {
|
||||||
|
debug!("MAP ENTRY {i:3} {:?}", x.ts);
|
||||||
let k = nx.clone();
|
let k = nx.clone();
|
||||||
nx = Some(x.ts.clone());
|
nx = Some(x.ts.clone());
|
||||||
(i, x, k)
|
(i, x, k)
|
||||||
@@ -474,11 +475,14 @@ pub fn extract_matching_config_entry<'a>(
|
|||||||
|
|
||||||
let mut c: Vec<_> = b
|
let mut c: Vec<_> = b
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
.rev()
|
||||||
.map(|(i, e, tsn)| {
|
.map(|(i, e, tsn)| {
|
||||||
if let Some(ts2) = tsn {
|
//debug!("LOOK AT CONFIG ENTRY {:3} {:?} {:?}", i, e.ts, tsn);
|
||||||
|
let ret = if let Some(ts2) = tsn.clone() {
|
||||||
if e.ts.ns() < range.end {
|
if e.ts.ns() < range.end {
|
||||||
let p = if e.ts.ns() < range.beg { range.beg } else { e.ts.ns() };
|
let p = if e.ts.ns() < range.beg { range.beg } else { e.ts.ns() };
|
||||||
let q = if ts2.ns() < range.end { ts2.ns() } else { range.end };
|
let q = if ts2.ns() < range.end { ts2.ns() } else { range.end };
|
||||||
|
//debug!("P/Q {:?} {:?}", TsNano(q - p), TsNano(p - q));
|
||||||
(i, TsNano(q - p), e)
|
(i, TsNano(q - p), e)
|
||||||
} else {
|
} else {
|
||||||
(i, TsNano(0), e)
|
(i, TsNano(0), e)
|
||||||
@@ -493,14 +497,16 @@ pub fn extract_matching_config_entry<'a>(
|
|||||||
} else {
|
} else {
|
||||||
(i, TsNano(0), e)
|
(i, TsNano(0), e)
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
debug!("LOOK AT CONFIG ENTRY {:3} {:?} {:?} {:?}", i, e.ts, tsn, ret.1);
|
||||||
|
ret
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
c.sort_unstable_by_key(|x| u64::MAX - x.1.ns());
|
c.sort_unstable_by_key(|x| u64::MAX - x.1.ns());
|
||||||
|
|
||||||
for (i, ts, e) in &c[..c.len().min(3)] {
|
for (i, dt, e) in &c[..c.len().min(3)] {
|
||||||
info!("FOUND CONFIG IN ORDER {} {:?} {:?}", i, ts, e.ts);
|
debug!("FOUND CONFIG IN ORDER {} {:?} {:?}", i, dt, e.ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(&(i, _, _)) = c.first() {
|
if let Some(&(i, _, _)) = c.first() {
|
||||||
|
|||||||
Reference in New Issue
Block a user