This commit is contained in:
Dominik Werder
2023-03-30 17:04:11 +02:00
parent c09c5be926
commit a2e17848ba
28 changed files with 924 additions and 827 deletions

View File

@@ -45,7 +45,7 @@ pub async fn chconf_from_scylla_type_backend(channel: &Channel, ncc: &NodeConfig
let shape = Shape::from_scylla_shape_dims(&row.get::<_, Vec<i32>>(2))?;
let ret = ChConf {
backend,
series,
series: Some(series),
name,
scalar_type,
shape,
@@ -78,7 +78,7 @@ pub async fn chconf_from_scylla_type_backend(channel: &Channel, ncc: &NodeConfig
let shape = Shape::from_scylla_shape_dims(&row.get::<_, Vec<i32>>(3))?;
let ret = ChConf {
backend,
series,
series: Some(series),
name,
scalar_type,
shape,

View File

@@ -1,31 +1,50 @@
use crate::create_connection;
use crate::ErrConv;
use err::Error;
use netpod::log::*;
use netpod::Channel;
use netpod::NodeConfigCached;
// For sf-databuffer backend, given a Channel, try to complete the information if only id is given.
pub async fn sf_databuffer_fetch_channel_by_series(channel: Channel, ncc: &NodeConfigCached) -> Result<Channel, Error> {
info!("sf_databuffer_fetch_channel_by_series");
// TODO should not be needed at some point.
if channel.backend().is_empty() || channel.name().is_empty() {
let series = channel
.series()
.ok_or_else(|| Error::with_msg_no_trace("no series id given"))? as i64;
let pgcon = create_connection(&ncc.node_config.cluster.database).await?;
let mut rows = pgcon
.query("select name from channels where rowid = $1", &[&series])
.await
.err_conv()?;
if let Some(row) = rows.pop() {
let name: String = row.get(0);
let channel = Channel {
series: channel.series,
backend: ncc.node_config.cluster.backend.clone(),
name,
};
Ok(channel)
if let Some(series) = channel.series() {
if series < 1 {
error!("sf_databuffer_fetch_channel_by_series bad input: {channel:?}");
Err(Error::with_msg_no_trace(format!(
"sf_databuffer_fetch_channel_by_series bad input: {channel:?}"
)))
} else {
info!("sf_databuffer_fetch_channel_by_series do the lookup");
let series = channel
.series()
.ok_or_else(|| Error::with_msg_no_trace("no series id given"))? as i64;
let pgcon = create_connection(&ncc.node_config.cluster.database).await?;
let mut rows = pgcon
.query("select name from channels where rowid = $1", &[&series])
.await
.err_conv()?;
if let Some(row) = rows.pop() {
info!("sf_databuffer_fetch_channel_by_series got a row {row:?}");
let name: String = row.get(0);
let channel = Channel {
series: channel.series,
backend: ncc.node_config.cluster.backend.clone(),
name,
};
info!("sf_databuffer_fetch_channel_by_series return {channel:?}");
Ok(channel)
} else {
info!("sf_databuffer_fetch_channel_by_series nothing found");
Err(Error::with_msg_no_trace("can not find series"))
}
}
} else {
Err(Error::with_msg_no_trace("can not find series"))
Err(Error::with_msg_no_trace(format!(
"sf_databuffer_fetch_channel_by_series bad input: {channel:?}"
)))
}
} else {
Ok(channel)