Insert bool set
This commit is contained in:
@@ -1024,13 +1024,12 @@ impl CaConn {
|
||||
ev: proto::EventAddRes,
|
||||
item_queue: &mut VecDeque<QueryItem>,
|
||||
ts_msp_last: u64,
|
||||
inserted_in_ts_msp: u64,
|
||||
ts_msp_grid: Option<u32>,
|
||||
stats: Arc<CaConnStats>,
|
||||
) -> Result<(), Error> {
|
||||
// TODO decide on better msp/lsp: random offset!
|
||||
// As long as one writer is active, the msp is arbitrary.
|
||||
let (ts_msp, ts_msp_changed) = if inserted_in_ts_msp >= 64000 || st.ts_msp_last + HOUR <= ts {
|
||||
let (ts_msp, ts_msp_changed) = if st.inserted_in_ts_msp >= 64000 || st.ts_msp_last + HOUR <= ts {
|
||||
let div = SEC * 10;
|
||||
let ts_msp = ts / div * div;
|
||||
if ts_msp == st.ts_msp_last {
|
||||
@@ -1085,7 +1084,6 @@ impl CaConn {
|
||||
.checked_add(Duration::from_micros((dt * 1e6) as u64))
|
||||
.ok_or_else(|| Error::with_msg_no_trace("time overflow in next insert"))?;
|
||||
let ts_msp_last = st.ts_msp_last;
|
||||
let inserted_in_ts_msp = st.inserted_in_ts_msp;
|
||||
// TODO get event timestamp from channel access field
|
||||
let ts_msp_grid = (ts / TS_MSP_GRID_UNIT / TS_MSP_GRID_SPACING * TS_MSP_GRID_SPACING) as u32;
|
||||
let ts_msp_grid = if st.ts_msp_grid_last != ts_msp_grid {
|
||||
@@ -1105,7 +1103,6 @@ impl CaConn {
|
||||
ev.clone(),
|
||||
item_queue,
|
||||
ts_msp_last,
|
||||
inserted_in_ts_msp,
|
||||
ts_msp_grid,
|
||||
stats.clone(),
|
||||
)?;
|
||||
@@ -1120,7 +1117,6 @@ impl CaConn {
|
||||
ev,
|
||||
item_queue,
|
||||
ts_msp_last,
|
||||
inserted_in_ts_msp,
|
||||
ts_msp_grid,
|
||||
stats,
|
||||
)?;
|
||||
|
||||
@@ -162,6 +162,8 @@ pub enum CaDataScalarValue {
|
||||
F64(f64),
|
||||
Enum(i16),
|
||||
String(String),
|
||||
// TODO remove, CA has no bool, make new enum for other use cases.
|
||||
Bool(bool),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -171,6 +173,8 @@ pub enum CaDataArrayValue {
|
||||
I32(Vec<i32>),
|
||||
F32(Vec<f32>),
|
||||
F64(Vec<f64>),
|
||||
// TODO remove, CA has no bool, make new enum for other use cases.
|
||||
Bool(Vec<bool>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -137,6 +137,7 @@ impl DbUpdateWorker {
|
||||
|
||||
pub async fn ca_search(opts: CaIngestOpts, channels: &Vec<String>) -> Result<(), Error> {
|
||||
info!("ca_search begin");
|
||||
crate::dbpg::schema_check(opts.postgresql()).await?;
|
||||
let mut addrs = Vec::new();
|
||||
for s in opts.search() {
|
||||
match resolve_address(s).await {
|
||||
@@ -191,7 +192,7 @@ pub async fn ca_search(opts: CaIngestOpts, channels: &Vec<String>) -> Result<(),
|
||||
let dbtx: Sender<_> = dbtx;
|
||||
|
||||
let mut ts_last = Instant::now();
|
||||
loop {
|
||||
'outer: loop {
|
||||
let ts_now = Instant::now();
|
||||
if ts_now.duration_since(ts_last) >= Duration::from_millis(2000) {
|
||||
ts_last = ts_now;
|
||||
@@ -240,7 +241,7 @@ pub async fn ca_search(opts: CaIngestOpts, channels: &Vec<String>) -> Result<(),
|
||||
Ok(_) => {}
|
||||
Err(_) => {
|
||||
error!("dbtx broken");
|
||||
break;
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use err::Error;
|
||||
use futures_util::StreamExt;
|
||||
use netpod::ScyllaConfig;
|
||||
use scylla::prepared_statement::PreparedStatement;
|
||||
use scylla::statement::Consistency;
|
||||
@@ -20,6 +21,7 @@ pub struct DataStore {
|
||||
pub qu_insert_array_i32: Arc<PreparedStatement>,
|
||||
pub qu_insert_array_f32: Arc<PreparedStatement>,
|
||||
pub qu_insert_array_f64: Arc<PreparedStatement>,
|
||||
pub qu_insert_array_bool: Arc<PreparedStatement>,
|
||||
pub qu_insert_muted: Arc<PreparedStatement>,
|
||||
pub qu_insert_item_recv_ivl: Arc<PreparedStatement>,
|
||||
pub qu_insert_connection_status: Arc<PreparedStatement>,
|
||||
@@ -29,6 +31,31 @@ pub struct DataStore {
|
||||
}
|
||||
|
||||
impl DataStore {
|
||||
async fn has_table(name: &str, scy: &ScySession, scyconf: &ScyllaConfig) -> Result<bool, Error> {
|
||||
let mut res = scy
|
||||
.query_iter(
|
||||
"select table_name from system_schema.tables where keyspace_name = ?",
|
||||
(&scyconf.keyspace,),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
.map_err(Error::from)?;
|
||||
while let Some(k) = res.next().await {
|
||||
let row = k.map_err(|e| e.to_string()).map_err(Error::from)?;
|
||||
if let Some(table_name) = row.columns[0].as_ref().unwrap().as_text() {
|
||||
if table_name == name {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
async fn migrate_00(scy: &ScySession, scyconf: &ScyllaConfig) -> Result<(), Error> {
|
||||
if !Self::has_table("somename", scy, scyconf).await? {}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn new(scyconf: &ScyllaConfig) -> Result<Self, Error> {
|
||||
let scy = scylla::SessionBuilder::new()
|
||||
.known_nodes(&scyconf.hosts)
|
||||
@@ -38,6 +65,9 @@ impl DataStore {
|
||||
.await
|
||||
.map_err(|e| Error::with_msg_no_trace(format!("{e:?}")))?;
|
||||
let scy = Arc::new(scy);
|
||||
|
||||
Self::migrate_00(&scy, scyconf).await?;
|
||||
|
||||
let q = scy
|
||||
.prepare("insert into ts_msp (series, ts_msp) values (?, ?) using ttl ?")
|
||||
.await
|
||||
@@ -111,6 +141,11 @@ impl DataStore {
|
||||
.await
|
||||
.map_err(|e| Error::with_msg_no_trace(format!("{e:?}")))?;
|
||||
let qu_insert_array_f64 = Arc::new(q);
|
||||
let q = scy
|
||||
.prepare("insert into events_array_bool (series, ts_msp, ts_lsp, pulse, value) values (?, ?, ?, ?, ?) using ttl ?")
|
||||
.await
|
||||
.map_err(|e| Error::with_msg_no_trace(format!("{e:?}")))?;
|
||||
let qu_insert_array_bool = Arc::new(q);
|
||||
// Others:
|
||||
let q = scy
|
||||
.prepare("insert into muted (part, series, ts, ema, emd) values (?, ?, ?, ?, ?) using ttl ?")
|
||||
@@ -160,6 +195,7 @@ impl DataStore {
|
||||
qu_insert_array_i32,
|
||||
qu_insert_array_f32,
|
||||
qu_insert_array_f64,
|
||||
qu_insert_array_bool,
|
||||
qu_insert_muted,
|
||||
qu_insert_item_recv_ivl,
|
||||
qu_insert_connection_status,
|
||||
|
||||
Reference in New Issue
Block a user