Remove Arc from config structs to make them Serialize
This commit is contained in:
+1
-2
@@ -1,10 +1,9 @@
|
|||||||
use err::Error;
|
use err::Error;
|
||||||
use netpod::log::*;
|
use netpod::log::*;
|
||||||
use netpod::{Channel, NodeConfig};
|
use netpod::{Channel, NodeConfig};
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio_postgres::NoTls;
|
use tokio_postgres::NoTls;
|
||||||
|
|
||||||
pub async fn channel_exists(channel: &Channel, node_config: Arc<NodeConfig>) -> Result<bool, Error> {
|
pub async fn channel_exists(channel: &Channel, node_config: &NodeConfig) -> Result<bool, Error> {
|
||||||
let d = &node_config.cluster.database;
|
let d = &node_config.cluster.database;
|
||||||
let uri = format!("postgresql://{}:{}@{}:{}/{}", d.user, d.pass, d.host, 5432, d.name);
|
let uri = format!("postgresql://{}:{}@{}:{}/{}", d.user, d.pass, d.host, 5432, d.name);
|
||||||
let (cl, conn) = tokio_postgres::connect(&uri, NoTls).await?;
|
let (cl, conn) = tokio_postgres::connect(&uri, NoTls).await?;
|
||||||
|
|||||||
+1
-1
@@ -442,7 +442,7 @@ where
|
|||||||
|
|
||||||
pub fn make_test_node(id: u32) -> Node {
|
pub fn make_test_node(id: u32) -> Node {
|
||||||
Node {
|
Node {
|
||||||
id,
|
id: format!("{:02}", id),
|
||||||
host: "localhost".into(),
|
host: "localhost".into(),
|
||||||
listen: "0.0.0.0".into(),
|
listen: "0.0.0.0".into(),
|
||||||
port: 8800 + id as u16,
|
port: 8800 + id as u16,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use futures_util::StreamExt;
|
|||||||
use netpod::timeunits::*;
|
use netpod::timeunits::*;
|
||||||
use netpod::{BinSpecDimT, Channel, ChannelConfig, NanoRange, ScalarType, Shape};
|
use netpod::{BinSpecDimT, Channel, ChannelConfig, NanoRange, ScalarType, Shape};
|
||||||
use std::future::ready;
|
use std::future::ready;
|
||||||
use std::sync::Arc;
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use tracing::{debug, error, info, trace, warn};
|
use tracing::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
@@ -22,7 +21,6 @@ fn agg_x_dim_0() {
|
|||||||
|
|
||||||
async fn agg_x_dim_0_inner() {
|
async fn agg_x_dim_0_inner() {
|
||||||
let node = make_test_node(0);
|
let node = make_test_node(0);
|
||||||
let node = Arc::new(node);
|
|
||||||
let query = netpod::AggQuerySingleChannel {
|
let query = netpod::AggQuerySingleChannel {
|
||||||
channel_config: ChannelConfig {
|
channel_config: ChannelConfig {
|
||||||
channel: Channel {
|
channel: Channel {
|
||||||
@@ -93,7 +91,6 @@ async fn agg_x_dim_1_inner() {
|
|||||||
// /data/sf-databuffer/daq_swissfel/daq_swissfel_3/byTime/S10BC01-DBAM070\:BAM_CH1_NORM/*
|
// /data/sf-databuffer/daq_swissfel/daq_swissfel_3/byTime/S10BC01-DBAM070\:BAM_CH1_NORM/*
|
||||||
// S10BC01-DBAM070:BAM_CH1_NORM
|
// S10BC01-DBAM070:BAM_CH1_NORM
|
||||||
let node = make_test_node(0);
|
let node = make_test_node(0);
|
||||||
let node = Arc::new(node);
|
|
||||||
let query = netpod::AggQuerySingleChannel {
|
let query = netpod::AggQuerySingleChannel {
|
||||||
channel_config: ChannelConfig {
|
channel_config: ChannelConfig {
|
||||||
channel: Channel {
|
channel: Channel {
|
||||||
@@ -179,7 +176,6 @@ async fn merge_0_inner() {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|k| make_test_node(k))
|
.map(|k| make_test_node(k))
|
||||||
.map(|node| {
|
.map(|node| {
|
||||||
let node = Arc::new(node);
|
|
||||||
super::eventblobs::EventBlobsComplete::new(
|
super::eventblobs::EventBlobsComplete::new(
|
||||||
range.clone(),
|
range.clone(),
|
||||||
query.channel_config.clone(),
|
query.channel_config.clone(),
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use netpod::{AggKind, Channel, NodeConfig, PreBinnedPatchIterator};
|
|||||||
use netpod::{NanoRange, RetStreamExt};
|
use netpod::{NanoRange, RetStreamExt};
|
||||||
use std::future::ready;
|
use std::future::ready;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
pub struct BinnedStream {
|
pub struct BinnedStream {
|
||||||
@@ -22,7 +21,7 @@ impl BinnedStream {
|
|||||||
channel: Channel,
|
channel: Channel,
|
||||||
range: NanoRange,
|
range: NanoRange,
|
||||||
agg_kind: AggKind,
|
agg_kind: AggKind,
|
||||||
node_config: Arc<NodeConfig>,
|
node_config: &NodeConfig,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let patches: Vec<_> = patch_it.collect();
|
let patches: Vec<_> = patch_it.collect();
|
||||||
warn!("BinnedStream will open a PreBinnedValueStream");
|
warn!("BinnedStream will open a PreBinnedValueStream");
|
||||||
@@ -30,8 +29,9 @@ impl BinnedStream {
|
|||||||
info!("BinnedStream -> patch {:?}", p);
|
info!("BinnedStream -> patch {:?}", p);
|
||||||
}
|
}
|
||||||
let inp = futures_util::stream::iter(patches.into_iter())
|
let inp = futures_util::stream::iter(patches.into_iter())
|
||||||
.map(move |coord| {
|
.map({
|
||||||
PreBinnedValueFetchedStream::new(coord, channel.clone(), agg_kind.clone(), node_config.clone())
|
let node_config = node_config.clone();
|
||||||
|
move |coord| PreBinnedValueFetchedStream::new(coord, channel.clone(), agg_kind.clone(), &node_config)
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.only_first_error()
|
.only_first_error()
|
||||||
|
|||||||
+10
-9
@@ -12,13 +12,12 @@ use futures_core::Stream;
|
|||||||
use futures_util::{pin_mut, StreamExt};
|
use futures_util::{pin_mut, StreamExt};
|
||||||
use hyper::Response;
|
use hyper::Response;
|
||||||
use netpod::{
|
use netpod::{
|
||||||
AggKind, Channel, Cluster, NanoRange, NodeConfig, PreBinnedPatchCoord, PreBinnedPatchIterator, PreBinnedPatchRange,
|
AggKind, Channel, Cluster, NanoRange, Node, NodeConfig, PreBinnedPatchCoord, PreBinnedPatchIterator,
|
||||||
ToNanos,
|
PreBinnedPatchRange, ToNanos,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tiny_keccak::Hasher;
|
use tiny_keccak::Hasher;
|
||||||
use tokio::io::{AsyncRead, ReadBuf};
|
use tokio::io::{AsyncRead, ReadBuf};
|
||||||
@@ -66,11 +65,12 @@ impl Query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn binned_bytes_for_http(
|
pub async fn binned_bytes_for_http(
|
||||||
node_config: Arc<NodeConfig>,
|
node_config: &NodeConfig,
|
||||||
|
node: &Node,
|
||||||
query: &Query,
|
query: &Query,
|
||||||
) -> Result<BinnedBytesForHttpStream, Error> {
|
) -> Result<BinnedBytesForHttpStream, Error> {
|
||||||
let range = &query.range;
|
let range = &query.range;
|
||||||
let channel_config = read_local_config(&query.channel, node_config.clone()).await?;
|
let channel_config = read_local_config(&query.channel, node).await?;
|
||||||
let entry = extract_matching_config_entry(range, &channel_config);
|
let entry = extract_matching_config_entry(range, &channel_config);
|
||||||
info!("found config entry {:?}", entry);
|
info!("found config entry {:?}", entry);
|
||||||
let grid = PreBinnedPatchRange::covering_range(query.range.clone(), query.count);
|
let grid = PreBinnedPatchRange::covering_range(query.range.clone(), query.count);
|
||||||
@@ -83,7 +83,7 @@ pub async fn binned_bytes_for_http(
|
|||||||
query.channel.clone(),
|
query.channel.clone(),
|
||||||
query.range.clone(),
|
query.range.clone(),
|
||||||
query.agg_kind.clone(),
|
query.agg_kind.clone(),
|
||||||
node_config.clone(),
|
node_config,
|
||||||
);
|
);
|
||||||
let ret = BinnedBytesForHttpStream::new(s1);
|
let ret = BinnedBytesForHttpStream::new(s1);
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
@@ -170,10 +170,11 @@ impl PreBinnedQuery {
|
|||||||
// A user must first make sure that the grid spec is valid, and that this node is responsible for it.
|
// A user must first make sure that the grid spec is valid, and that this node is responsible for it.
|
||||||
// Otherwise it is an error.
|
// Otherwise it is an error.
|
||||||
pub fn pre_binned_bytes_for_http(
|
pub fn pre_binned_bytes_for_http(
|
||||||
node_config: Arc<NodeConfig>,
|
node_config: &NodeConfig,
|
||||||
|
node: &Node,
|
||||||
query: &PreBinnedQuery,
|
query: &PreBinnedQuery,
|
||||||
) -> Result<PreBinnedValueByteStream, Error> {
|
) -> Result<PreBinnedValueByteStream, Error> {
|
||||||
info!("pre_binned_bytes_for_http {:?} {:?}", query, node_config.node);
|
info!("pre_binned_bytes_for_http {:?} {:?}", query, node);
|
||||||
let ret = PreBinnedValueByteStream::new(
|
let ret = PreBinnedValueByteStream::new(
|
||||||
query.patch.clone(),
|
query.patch.clone(),
|
||||||
query.channel.clone(),
|
query.channel.clone(),
|
||||||
@@ -254,7 +255,7 @@ pub struct MergedFromRemotes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MergedFromRemotes {
|
impl MergedFromRemotes {
|
||||||
pub fn new(evq: Arc<EventsQuery>, cluster: Arc<Cluster>) -> Self {
|
pub fn new(evq: EventsQuery, cluster: Cluster) -> Self {
|
||||||
let mut tcp_establish_futs = vec![];
|
let mut tcp_establish_futs = vec![];
|
||||||
for node in &cluster.nodes {
|
for node in &cluster.nodes {
|
||||||
let f = super::raw::x_processed_stream_from_node(evq.clone(), node.clone());
|
let f = super::raw::x_processed_stream_from_node(evq.clone(), node.clone());
|
||||||
|
|||||||
Vendored
+8
-10
@@ -15,7 +15,6 @@ use netpod::{
|
|||||||
};
|
};
|
||||||
use std::future::{ready, Future};
|
use std::future::{ready, Future};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
pub struct PreBinnedValueByteStream {
|
pub struct PreBinnedValueByteStream {
|
||||||
@@ -25,7 +24,7 @@ pub struct PreBinnedValueByteStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PreBinnedValueByteStream {
|
impl PreBinnedValueByteStream {
|
||||||
pub fn new(patch: PreBinnedPatchCoord, channel: Channel, agg_kind: AggKind, node_config: Arc<NodeConfig>) -> Self {
|
pub fn new(patch: PreBinnedPatchCoord, channel: Channel, agg_kind: AggKind, node_config: &NodeConfig) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inp: PreBinnedValueStream::new(patch, channel, agg_kind, node_config),
|
inp: PreBinnedValueStream::new(patch, channel, agg_kind, node_config),
|
||||||
errored: false,
|
errored: false,
|
||||||
@@ -64,7 +63,7 @@ pub struct PreBinnedValueStream {
|
|||||||
patch_coord: PreBinnedPatchCoord,
|
patch_coord: PreBinnedPatchCoord,
|
||||||
channel: Channel,
|
channel: Channel,
|
||||||
agg_kind: AggKind,
|
agg_kind: AggKind,
|
||||||
node_config: Arc<NodeConfig>,
|
node_config: NodeConfig,
|
||||||
open_check_local_file: Option<Pin<Box<dyn Future<Output = Result<tokio::fs::File, std::io::Error>> + Send>>>,
|
open_check_local_file: Option<Pin<Box<dyn Future<Output = Result<tokio::fs::File, std::io::Error>> + Send>>>,
|
||||||
fut2: Option<Pin<Box<dyn Stream<Item = Result<MinMaxAvgScalarBinBatch, Error>> + Send>>>,
|
fut2: Option<Pin<Box<dyn Stream<Item = Result<MinMaxAvgScalarBinBatch, Error>> + Send>>>,
|
||||||
}
|
}
|
||||||
@@ -74,15 +73,15 @@ impl PreBinnedValueStream {
|
|||||||
patch_coord: PreBinnedPatchCoord,
|
patch_coord: PreBinnedPatchCoord,
|
||||||
channel: Channel,
|
channel: Channel,
|
||||||
agg_kind: AggKind,
|
agg_kind: AggKind,
|
||||||
node_config: Arc<NodeConfig>,
|
node_config: &NodeConfig,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let node_ix = node_ix_for_patch(&patch_coord, &channel, &node_config.cluster);
|
// TODO check that we are the correct node.
|
||||||
assert!(node_ix == node_config.node.id);
|
let _node_ix = node_ix_for_patch(&patch_coord, &channel, &node_config.cluster);
|
||||||
Self {
|
Self {
|
||||||
patch_coord,
|
patch_coord,
|
||||||
channel,
|
channel,
|
||||||
agg_kind,
|
agg_kind,
|
||||||
node_config,
|
node_config: node_config.clone(),
|
||||||
open_check_local_file: None,
|
open_check_local_file: None,
|
||||||
fut2: None,
|
fut2: None,
|
||||||
}
|
}
|
||||||
@@ -107,7 +106,7 @@ impl PreBinnedValueStream {
|
|||||||
range
|
range
|
||||||
);
|
);
|
||||||
assert!(g / h > 1);
|
assert!(g / h > 1);
|
||||||
assert!(g / h < 20);
|
assert!(g / h < 200);
|
||||||
assert!(g % h == 0);
|
assert!(g % h == 0);
|
||||||
let bin_size = range.grid_spec.bin_t_len();
|
let bin_size = range.grid_spec.bin_t_len();
|
||||||
let channel = self.channel.clone();
|
let channel = self.channel.clone();
|
||||||
@@ -116,7 +115,7 @@ impl PreBinnedValueStream {
|
|||||||
let patch_it = PreBinnedPatchIterator::from_range(range);
|
let patch_it = PreBinnedPatchIterator::from_range(range);
|
||||||
let s = futures_util::stream::iter(patch_it)
|
let s = futures_util::stream::iter(patch_it)
|
||||||
.map(move |coord| {
|
.map(move |coord| {
|
||||||
PreBinnedValueFetchedStream::new(coord, channel.clone(), agg_kind.clone(), node_config.clone())
|
PreBinnedValueFetchedStream::new(coord, channel.clone(), agg_kind.clone(), &node_config)
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.map(move |k| {
|
.map(move |k| {
|
||||||
@@ -147,7 +146,6 @@ impl PreBinnedValueStream {
|
|||||||
ts2: self.patch_coord.patch_end(),
|
ts2: self.patch_coord.patch_end(),
|
||||||
count,
|
count,
|
||||||
};
|
};
|
||||||
let evq = Arc::new(evq);
|
|
||||||
let s1 = MergedFromRemotes::new(evq, self.node_config.cluster.clone());
|
let s1 = MergedFromRemotes::new(evq, self.node_config.cluster.clone());
|
||||||
let s2 = s1
|
let s2 = s1
|
||||||
.map(|k| {
|
.map(|k| {
|
||||||
|
|||||||
Vendored
+1
-2
@@ -9,7 +9,6 @@ use futures_util::{pin_mut, FutureExt};
|
|||||||
use netpod::log::*;
|
use netpod::log::*;
|
||||||
use netpod::{AggKind, Channel, NodeConfig, PreBinnedPatchCoord};
|
use netpod::{AggKind, Channel, NodeConfig, PreBinnedPatchCoord};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
pub struct PreBinnedValueFetchedStream {
|
pub struct PreBinnedValueFetchedStream {
|
||||||
@@ -23,7 +22,7 @@ impl PreBinnedValueFetchedStream {
|
|||||||
patch_coord: PreBinnedPatchCoord,
|
patch_coord: PreBinnedPatchCoord,
|
||||||
channel: Channel,
|
channel: Channel,
|
||||||
agg_kind: AggKind,
|
agg_kind: AggKind,
|
||||||
node_config: Arc<NodeConfig>,
|
node_config: &NodeConfig,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let nodeix = node_ix_for_patch(&patch_coord, &channel, &node_config.cluster);
|
let nodeix = node_ix_for_patch(&patch_coord, &channel, &node_config.cluster);
|
||||||
let node = &node_config.cluster.nodes[nodeix as usize];
|
let node = &node_config.cluster.nodes[nodeix as usize];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use err::Error;
|
use err::Error;
|
||||||
use netpod::{Channel, NanoRange, NodeConfig};
|
use netpod::{Channel, NanoRange, Node};
|
||||||
use nom::number::complete::{be_i16, be_i32, be_i64, be_i8, be_u8};
|
use nom::number::complete::{be_i16, be_i32, be_i64, be_i8, be_u8};
|
||||||
use nom::Needed;
|
use nom::Needed;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
@@ -11,7 +11,6 @@ use nom::{
|
|||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::sync::Arc;
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use tracing::{debug, error, info, trace, warn};
|
use tracing::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
@@ -264,9 +263,8 @@ pub fn parse_config(inp: &[u8]) -> NRes<Config> {
|
|||||||
Ok((inp, ret))
|
Ok((inp, ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_local_config(channel: &Channel, node_config: Arc<NodeConfig>) -> Result<Config, Error> {
|
pub async fn read_local_config(channel: &Channel, node: &Node) -> Result<Config, Error> {
|
||||||
let path = node_config
|
let path = node
|
||||||
.node
|
|
||||||
.data_base_path
|
.data_base_path
|
||||||
.join("config")
|
.join("config")
|
||||||
.join(&channel.name)
|
.join(&channel.name)
|
||||||
|
|||||||
@@ -5,14 +5,13 @@ use futures_util::StreamExt;
|
|||||||
use netpod::log::*;
|
use netpod::log::*;
|
||||||
use netpod::{ChannelConfig, NanoRange, Nanos, Node};
|
use netpod::{ChannelConfig, NanoRange, Nanos, Node};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::fs::{File, OpenOptions};
|
use tokio::fs::{File, OpenOptions};
|
||||||
use tokio::io::{AsyncReadExt, AsyncSeekExt, ErrorKind, SeekFrom};
|
use tokio::io::{AsyncReadExt, AsyncSeekExt, ErrorKind, SeekFrom};
|
||||||
|
|
||||||
pub fn open_files(
|
pub fn open_files(
|
||||||
range: &NanoRange,
|
range: &NanoRange,
|
||||||
channel_config: &ChannelConfig,
|
channel_config: &ChannelConfig,
|
||||||
node: Arc<Node>,
|
node: Node,
|
||||||
) -> async_channel::Receiver<Result<File, Error>> {
|
) -> async_channel::Receiver<Result<File, Error>> {
|
||||||
let (chtx, chrx) = async_channel::bounded(2);
|
let (chtx, chrx) = async_channel::bounded(2);
|
||||||
let range = range.clone();
|
let range = range.clone();
|
||||||
@@ -35,7 +34,7 @@ async fn open_files_inner(
|
|||||||
chtx: &async_channel::Sender<Result<File, Error>>,
|
chtx: &async_channel::Sender<Result<File, Error>>,
|
||||||
range: &NanoRange,
|
range: &NanoRange,
|
||||||
channel_config: &ChannelConfig,
|
channel_config: &ChannelConfig,
|
||||||
node: Arc<Node>,
|
node: Node,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let channel_config = channel_config.clone();
|
let channel_config = channel_config.clone();
|
||||||
// TODO reduce usage of `query` and see what we actually need.
|
// TODO reduce usage of `query` and see what we actually need.
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use futures_core::Stream;
|
|||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use netpod::{ChannelConfig, NanoRange, Node};
|
use netpod::{ChannelConfig, NanoRange, Node};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
|
|
||||||
@@ -19,9 +18,9 @@ pub struct EventBlobsComplete {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EventBlobsComplete {
|
impl EventBlobsComplete {
|
||||||
pub fn new(range: NanoRange, channel_config: ChannelConfig, node: Arc<Node>, buffer_size: usize) -> Self {
|
pub fn new(range: NanoRange, channel_config: ChannelConfig, node: Node, buffer_size: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
file_chan: open_files(&range, &channel_config, node.clone()),
|
file_chan: open_files(&range, &channel_config, node),
|
||||||
evs: None,
|
evs: None,
|
||||||
buffer_size,
|
buffer_size,
|
||||||
channel_config,
|
channel_config,
|
||||||
@@ -67,12 +66,12 @@ impl Stream for EventBlobsComplete {
|
|||||||
|
|
||||||
pub fn event_blobs_complete(
|
pub fn event_blobs_complete(
|
||||||
query: &netpod::AggQuerySingleChannel,
|
query: &netpod::AggQuerySingleChannel,
|
||||||
node: Arc<Node>,
|
node: Node,
|
||||||
) -> impl Stream<Item = Result<EventFull, Error>> + Send {
|
) -> impl Stream<Item = Result<EventFull, Error>> + Send {
|
||||||
let query = query.clone();
|
let query = query.clone();
|
||||||
let node = node.clone();
|
let node = node.clone();
|
||||||
async_stream::stream! {
|
async_stream::stream! {
|
||||||
let filerx = open_files(err::todoval(), err::todoval(), node.clone());
|
let filerx = open_files(err::todoval(), err::todoval(), node);
|
||||||
while let Ok(fileres) = filerx.recv().await {
|
while let Ok(fileres) = filerx.recv().await {
|
||||||
match fileres {
|
match fileres {
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ pub async fn gen_test_data() -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
for i1 in 0..3 {
|
for i1 in 0..3 {
|
||||||
let node = Node {
|
let node = Node {
|
||||||
id: i1,
|
id: format!("{:02}", i1),
|
||||||
host: "localhost".into(),
|
host: "localhost".into(),
|
||||||
listen: "0.0.0.0".into(),
|
listen: "0.0.0.0".into(),
|
||||||
port: 7780 + i1 as u16,
|
port: 7780 + i1 as u16,
|
||||||
|
|||||||
+4
-7
@@ -270,14 +270,14 @@ pub fn raw_concat_channel_read_stream_try_open_in_background(
|
|||||||
pub fn raw_concat_channel_read_stream_file_pipe(
|
pub fn raw_concat_channel_read_stream_file_pipe(
|
||||||
range: &NanoRange,
|
range: &NanoRange,
|
||||||
channel_config: &ChannelConfig,
|
channel_config: &ChannelConfig,
|
||||||
node: Arc<Node>,
|
node: Node,
|
||||||
buffer_size: usize,
|
buffer_size: usize,
|
||||||
) -> impl Stream<Item = Result<BytesMut, Error>> + Send {
|
) -> impl Stream<Item = Result<BytesMut, Error>> + Send {
|
||||||
let range = range.clone();
|
let range = range.clone();
|
||||||
let channel_config = channel_config.clone();
|
let channel_config = channel_config.clone();
|
||||||
let node = node.clone();
|
let node = node.clone();
|
||||||
async_stream::stream! {
|
async_stream::stream! {
|
||||||
let chrx = open_files(&range, &channel_config, node.clone());
|
let chrx = open_files(&range, &channel_config, node);
|
||||||
while let Ok(file) = chrx.recv().await {
|
while let Ok(file) = chrx.recv().await {
|
||||||
let mut file = match file {
|
let mut file = match file {
|
||||||
Ok(k) => k,
|
Ok(k) => k,
|
||||||
@@ -319,14 +319,11 @@ pub fn file_content_stream(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parsed1(
|
pub fn parsed1(query: &netpod::AggQuerySingleChannel, node: &Node) -> impl Stream<Item = Result<Bytes, Error>> + Send {
|
||||||
query: &netpod::AggQuerySingleChannel,
|
|
||||||
node: Arc<Node>,
|
|
||||||
) -> impl Stream<Item = Result<Bytes, Error>> + Send {
|
|
||||||
let query = query.clone();
|
let query = query.clone();
|
||||||
let node = node.clone();
|
let node = node.clone();
|
||||||
async_stream::stream! {
|
async_stream::stream! {
|
||||||
let filerx = open_files(err::todoval(), err::todoval(), node.clone());
|
let filerx = open_files(err::todoval(), err::todoval(), node);
|
||||||
while let Ok(fileres) = filerx.recv().await {
|
while let Ok(fileres) = filerx.recv().await {
|
||||||
match fileres {
|
match fileres {
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
|
|||||||
+3
-4
@@ -14,7 +14,6 @@ use futures_core::Stream;
|
|||||||
use netpod::{AggKind, Channel, NanoRange, Node};
|
use netpod::{AggKind, Channel, NanoRange, Node};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
@@ -37,11 +36,11 @@ pub struct EventsQuery {
|
|||||||
pub struct EventQueryJsonStringFrame(String);
|
pub struct EventQueryJsonStringFrame(String);
|
||||||
|
|
||||||
pub async fn x_processed_stream_from_node(
|
pub async fn x_processed_stream_from_node(
|
||||||
query: Arc<EventsQuery>,
|
query: EventsQuery,
|
||||||
node: Arc<Node>,
|
node: Node,
|
||||||
) -> Result<Pin<Box<dyn Stream<Item = Result<MinMaxAvgScalarEventBatch, Error>> + Send>>, Error> {
|
) -> Result<Pin<Box<dyn Stream<Item = Result<MinMaxAvgScalarEventBatch, Error>> + Send>>, Error> {
|
||||||
let net = TcpStream::connect(format!("{}:{}", node.host, node.port_raw)).await?;
|
let net = TcpStream::connect(format!("{}:{}", node.host, node.port_raw)).await?;
|
||||||
let qjs = serde_json::to_string(query.as_ref())?;
|
let qjs = serde_json::to_string(&query)?;
|
||||||
let (netin, mut netout) = net.into_split();
|
let (netin, mut netout) = net.into_split();
|
||||||
let buf = make_frame(&EventQueryJsonStringFrame(qjs))?;
|
let buf = make_frame(&EventQueryJsonStringFrame(qjs))?;
|
||||||
netout.write_all(&buf).await?;
|
netout.write_all(&buf).await?;
|
||||||
|
|||||||
+23
-21
@@ -11,31 +11,36 @@ use futures_util::StreamExt;
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use netpod::log::*;
|
use netpod::log::*;
|
||||||
use netpod::timeunits::SEC;
|
use netpod::timeunits::SEC;
|
||||||
use netpod::{NodeConfig, ScalarType, Shape};
|
use netpod::{Node, NodeConfig, ScalarType, Shape};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
use tokio::net::tcp::OwnedWriteHalf;
|
use tokio::net::tcp::OwnedWriteHalf;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
use tracing::Instrument;
|
use tracing::Instrument;
|
||||||
|
|
||||||
pub async fn raw_service(node_config: Arc<NodeConfig>) -> Result<(), Error> {
|
pub async fn raw_service(node_config: NodeConfig, node: Node) -> Result<(), Error> {
|
||||||
let addr = format!("{}:{}", node_config.node.listen, node_config.node.port_raw);
|
let addr = format!("{}:{}", node.listen, node.port_raw);
|
||||||
let lis = tokio::net::TcpListener::bind(addr).await?;
|
let lis = tokio::net::TcpListener::bind(addr).await?;
|
||||||
loop {
|
loop {
|
||||||
match lis.accept().await {
|
match lis.accept().await {
|
||||||
Ok((stream, addr)) => {
|
Ok((stream, addr)) => {
|
||||||
taskrun::spawn(raw_conn_handler(stream, addr, node_config.clone()));
|
let node = node.clone();
|
||||||
|
taskrun::spawn(raw_conn_handler(stream, addr, node_config.clone(), node));
|
||||||
}
|
}
|
||||||
Err(e) => Err(e)?,
|
Err(e) => Err(e)?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn raw_conn_handler(stream: TcpStream, addr: SocketAddr, node_config: Arc<NodeConfig>) -> Result<(), Error> {
|
async fn raw_conn_handler(
|
||||||
|
stream: TcpStream,
|
||||||
|
addr: SocketAddr,
|
||||||
|
node_config: NodeConfig,
|
||||||
|
node: Node,
|
||||||
|
) -> Result<(), Error> {
|
||||||
//use tracing_futures::Instrument;
|
//use tracing_futures::Instrument;
|
||||||
let span1 = span!(Level::INFO, "raw::raw_conn_handler");
|
let span1 = span!(Level::INFO, "raw::raw_conn_handler");
|
||||||
let r = raw_conn_handler_inner(stream, addr, node_config)
|
let r = raw_conn_handler_inner(stream, addr, &node_config, &node)
|
||||||
.instrument(span1)
|
.instrument(span1)
|
||||||
.await;
|
.await;
|
||||||
match r {
|
match r {
|
||||||
@@ -52,9 +57,10 @@ pub type RawConnOut = Result<MinMaxAvgScalarEventBatch, Error>;
|
|||||||
async fn raw_conn_handler_inner(
|
async fn raw_conn_handler_inner(
|
||||||
stream: TcpStream,
|
stream: TcpStream,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
node_config: Arc<NodeConfig>,
|
node_config: &NodeConfig,
|
||||||
|
node: &Node,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
match raw_conn_handler_inner_try(stream, addr, node_config).await {
|
match raw_conn_handler_inner_try(stream, addr, node_config, node).await {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(mut ce) => {
|
Err(mut ce) => {
|
||||||
/*error!(
|
/*error!(
|
||||||
@@ -88,7 +94,8 @@ impl<E: Into<Error>> From<(E, OwnedWriteHalf)> for ConnErr {
|
|||||||
async fn raw_conn_handler_inner_try(
|
async fn raw_conn_handler_inner_try(
|
||||||
stream: TcpStream,
|
stream: TcpStream,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
node_config: Arc<NodeConfig>,
|
node_config: &NodeConfig,
|
||||||
|
node: &Node,
|
||||||
) -> Result<(), ConnErr> {
|
) -> Result<(), ConnErr> {
|
||||||
info!("raw_conn_handler SPAWNED for {:?}", addr);
|
info!("raw_conn_handler SPAWNED for {:?}", addr);
|
||||||
let (netin, mut netout) = stream.into_split();
|
let (netin, mut netout) = stream.into_split();
|
||||||
@@ -126,13 +133,13 @@ async fn raw_conn_handler_inner_try(
|
|||||||
return Err((Error::with_msg("can not parse request json"), netout))?;
|
return Err((Error::with_msg("can not parse request json"), netout))?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match dbconn::channel_exists(&evq.channel, node_config.clone()).await {
|
match dbconn::channel_exists(&evq.channel, &node_config).await {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => return Err((e, netout))?,
|
Err(e) => return Err((e, netout))?,
|
||||||
}
|
}
|
||||||
debug!("REQUEST {:?}", evq);
|
debug!("REQUEST {:?}", evq);
|
||||||
let range = &evq.range;
|
let range = &evq.range;
|
||||||
let channel_config = match read_local_config(&evq.channel, node_config.clone()).await {
|
let channel_config = match read_local_config(&evq.channel, node).await {
|
||||||
Ok(k) => k,
|
Ok(k) => k,
|
||||||
Err(e) => return Err((e, netout))?,
|
Err(e) => return Err((e, netout))?,
|
||||||
};
|
};
|
||||||
@@ -173,21 +180,16 @@ async fn raw_conn_handler_inner_try(
|
|||||||
buffer_size: 1024 * 4,
|
buffer_size: 1024 * 4,
|
||||||
};
|
};
|
||||||
let buffer_size = 1024 * 4;
|
let buffer_size = 1024 * 4;
|
||||||
let mut s1 = EventBlobsComplete::new(
|
let mut s1 = EventBlobsComplete::new(range.clone(), query.channel_config.clone(), node.clone(), buffer_size)
|
||||||
range.clone(),
|
.into_dim_1_f32_stream()
|
||||||
query.channel_config.clone(),
|
.into_binned_x_bins_1();
|
||||||
node_config.node.clone(),
|
|
||||||
buffer_size,
|
|
||||||
)
|
|
||||||
.into_dim_1_f32_stream()
|
|
||||||
.into_binned_x_bins_1();
|
|
||||||
let mut e = 0;
|
let mut e = 0;
|
||||||
while let Some(item) = s1.next().await {
|
while let Some(item) = s1.next().await {
|
||||||
if let Ok(k) = &item {
|
if let Ok(k) = &item {
|
||||||
e += 1;
|
e += 1;
|
||||||
trace!(
|
trace!(
|
||||||
"emit items sp {:2} e {:3} len {:3} {:10?} {:10?}",
|
"emit items sp {:2} e {:3} len {:3} {:10?} {:10?}",
|
||||||
node_config.node.split,
|
node.split,
|
||||||
e,
|
e,
|
||||||
k.tss.len(),
|
k.tss.len(),
|
||||||
k.tss.first().map(|k| k / SEC),
|
k.tss.first().map(|k| k / SEC),
|
||||||
|
|||||||
+24
-20
@@ -9,28 +9,30 @@ use http::{HeaderMap, Method, StatusCode};
|
|||||||
use hyper::service::{make_service_fn, service_fn};
|
use hyper::service::{make_service_fn, service_fn};
|
||||||
use hyper::{server::Server, Body, Request, Response};
|
use hyper::{server::Server, Body, Request, Response};
|
||||||
use net::SocketAddr;
|
use net::SocketAddr;
|
||||||
use netpod::NodeConfig;
|
use netpod::{Node, NodeConfig};
|
||||||
use panic::{AssertUnwindSafe, UnwindSafe};
|
use panic::{AssertUnwindSafe, UnwindSafe};
|
||||||
use pin::Pin;
|
use pin::Pin;
|
||||||
use std::{future, net, panic, pin, sync, task};
|
use std::{future, net, panic, pin, task};
|
||||||
use sync::Arc;
|
|
||||||
use task::{Context, Poll};
|
use task::{Context, Poll};
|
||||||
use tracing::field::Empty;
|
use tracing::field::Empty;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use tracing::{debug, error, info, span, trace, warn, Level};
|
use tracing::{debug, error, info, span, trace, warn, Level};
|
||||||
|
|
||||||
pub async fn host(node_config: Arc<NodeConfig>) -> Result<(), Error> {
|
pub async fn host(node_config: NodeConfig, node: Node) -> Result<(), Error> {
|
||||||
let rawjh = taskrun::spawn(raw_service(node_config.clone()));
|
let node_config = node_config.clone();
|
||||||
|
let node = node.clone();
|
||||||
|
let rawjh = taskrun::spawn(raw_service(node_config.clone(), node.clone()));
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
let addr = SocketAddr::from_str(&format!("{}:{}", node_config.node.listen, node_config.node.port))?;
|
let addr = SocketAddr::from_str(&format!("{}:{}", node.listen, node.port))?;
|
||||||
let make_service = make_service_fn({
|
let make_service = make_service_fn({
|
||||||
move |conn| {
|
move |conn| {
|
||||||
info!("new raw {:?}", conn);
|
info!("new raw {:?}", conn);
|
||||||
let node_config = node_config.clone();
|
let node_config = node_config.clone();
|
||||||
|
let node = node.clone();
|
||||||
async move {
|
async move {
|
||||||
Ok::<_, Error>(service_fn({
|
Ok::<_, Error>(service_fn({
|
||||||
move |req| {
|
move |req| {
|
||||||
let f = data_api_proxy(req, node_config.clone());
|
let f = data_api_proxy(req, node_config.clone(), node.clone());
|
||||||
Cont { f: Box::pin(f) }
|
Cont { f: Box::pin(f) }
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
@@ -42,8 +44,8 @@ pub async fn host(node_config: Arc<NodeConfig>) -> Result<(), Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn data_api_proxy(req: Request<Body>, node_config: Arc<NodeConfig>) -> Result<Response<Body>, Error> {
|
async fn data_api_proxy(req: Request<Body>, node_config: NodeConfig, node: Node) -> Result<Response<Body>, Error> {
|
||||||
match data_api_proxy_try(req, node_config).await {
|
match data_api_proxy_try(req, &node_config, &node).await {
|
||||||
Ok(k) => Ok(k),
|
Ok(k) => Ok(k),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("{:?}", e);
|
error!("{:?}", e);
|
||||||
@@ -82,24 +84,28 @@ where
|
|||||||
|
|
||||||
impl<F> UnwindSafe for Cont<F> {}
|
impl<F> UnwindSafe for Cont<F> {}
|
||||||
|
|
||||||
async fn data_api_proxy_try(req: Request<Body>, node_config: Arc<NodeConfig>) -> Result<Response<Body>, Error> {
|
async fn data_api_proxy_try(
|
||||||
|
req: Request<Body>,
|
||||||
|
node_config: &NodeConfig,
|
||||||
|
node: &Node,
|
||||||
|
) -> Result<Response<Body>, Error> {
|
||||||
let uri = req.uri().clone();
|
let uri = req.uri().clone();
|
||||||
let path = uri.path();
|
let path = uri.path();
|
||||||
if path == "/api/1/parsed_raw" {
|
if path == "/api/1/parsed_raw" {
|
||||||
if req.method() == Method::POST {
|
if req.method() == Method::POST {
|
||||||
Ok(parsed_raw(req, node_config.clone()).await?)
|
Ok(parsed_raw(req, node).await?)
|
||||||
} else {
|
} else {
|
||||||
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
|
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
|
||||||
}
|
}
|
||||||
} else if path == "/api/1/binned" {
|
} else if path == "/api/1/binned" {
|
||||||
if req.method() == Method::GET {
|
if req.method() == Method::GET {
|
||||||
Ok(binned(req, node_config.clone()).await?)
|
Ok(binned(req, &node_config, node).await?)
|
||||||
} else {
|
} else {
|
||||||
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
|
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
|
||||||
}
|
}
|
||||||
} else if path == "/api/1/prebinned" {
|
} else if path == "/api/1/prebinned" {
|
||||||
if req.method() == Method::GET {
|
if req.method() == Method::GET {
|
||||||
Ok(prebinned(req, node_config.clone()).await?)
|
Ok(prebinned(req, &node_config, node).await?)
|
||||||
} else {
|
} else {
|
||||||
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
|
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
|
||||||
}
|
}
|
||||||
@@ -119,8 +125,7 @@ where
|
|||||||
.header("access-control-allow-headers", "*")
|
.header("access-control-allow-headers", "*")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn parsed_raw(req: Request<Body>, node_config: Arc<NodeConfig>) -> Result<Response<Body>, Error> {
|
async fn parsed_raw(req: Request<Body>, node: &Node) -> Result<Response<Body>, Error> {
|
||||||
let node = node_config.node.clone();
|
|
||||||
use netpod::AggQuerySingleChannel;
|
use netpod::AggQuerySingleChannel;
|
||||||
let reqbody = req.into_body();
|
let reqbody = req.into_body();
|
||||||
let bodyslice = hyper::body::to_bytes(reqbody).await?;
|
let bodyslice = hyper::body::to_bytes(reqbody).await?;
|
||||||
@@ -219,11 +224,10 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn binned(req: Request<Body>, node_config: Arc<NodeConfig>) -> Result<Response<Body>, Error> {
|
async fn binned(req: Request<Body>, node_config: &NodeConfig, node: &Node) -> Result<Response<Body>, Error> {
|
||||||
info!("-------------------------------------------------------- BINNED");
|
|
||||||
let (head, _body) = req.into_parts();
|
let (head, _body) = req.into_parts();
|
||||||
let query = disk::cache::Query::from_request(&head)?;
|
let query = disk::cache::Query::from_request(&head)?;
|
||||||
let ret = match disk::cache::binned_bytes_for_http(node_config, &query).await {
|
let ret = match disk::cache::binned_bytes_for_http(node_config, node, &query).await {
|
||||||
Ok(s) => response(StatusCode::OK).body(BodyStream::wrapped(s, format!("desc-BINNED")))?,
|
Ok(s) => response(StatusCode::OK).body(BodyStream::wrapped(s, format!("desc-BINNED")))?,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("{:?}", e);
|
error!("{:?}", e);
|
||||||
@@ -233,14 +237,14 @@ async fn binned(req: Request<Body>, node_config: Arc<NodeConfig>) -> Result<Resp
|
|||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn prebinned(req: Request<Body>, node_config: Arc<NodeConfig>) -> Result<Response<Body>, Error> {
|
async fn prebinned(req: Request<Body>, node_config: &NodeConfig, node: &Node) -> Result<Response<Body>, Error> {
|
||||||
let (head, _body) = req.into_parts();
|
let (head, _body) = req.into_parts();
|
||||||
let q = PreBinnedQuery::from_request(&head)?;
|
let q = PreBinnedQuery::from_request(&head)?;
|
||||||
let desc = format!("pre-b-{}", q.patch.bin_t_len() / 1000000000);
|
let desc = format!("pre-b-{}", q.patch.bin_t_len() / 1000000000);
|
||||||
let span1 = span!(Level::INFO, "httpret::prebinned", desc = &desc.as_str());
|
let span1 = span!(Level::INFO, "httpret::prebinned", desc = &desc.as_str());
|
||||||
span1.in_scope(|| {
|
span1.in_scope(|| {
|
||||||
trace!("prebinned");
|
trace!("prebinned");
|
||||||
let ret = match disk::cache::pre_binned_bytes_for_http(node_config, &q) {
|
let ret = match disk::cache::pre_binned_bytes_for_http(node_config, node, &q) {
|
||||||
Ok(s) => response(StatusCode::OK).body(BodyStream::wrapped(
|
Ok(s) => response(StatusCode::OK).body(BodyStream::wrapped(
|
||||||
s,
|
s,
|
||||||
format!(
|
format!(
|
||||||
|
|||||||
+19
-9
@@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use timeunits::*;
|
use timeunits::*;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
@@ -94,9 +93,9 @@ impl ScalarType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct Node {
|
pub struct Node {
|
||||||
pub id: u32,
|
pub id: String,
|
||||||
pub host: String,
|
pub host: String,
|
||||||
pub listen: String,
|
pub listen: String,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
@@ -112,7 +111,7 @@ impl Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub host: String,
|
pub host: String,
|
||||||
@@ -120,16 +119,27 @@ pub struct Database {
|
|||||||
pub pass: String,
|
pub pass: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct Cluster {
|
pub struct Cluster {
|
||||||
pub nodes: Vec<Arc<Node>>,
|
pub nodes: Vec<Node>,
|
||||||
pub database: Database,
|
pub database: Database,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct NodeConfig {
|
pub struct NodeConfig {
|
||||||
pub node: Arc<Node>,
|
pub nodeid: String,
|
||||||
pub cluster: Arc<Cluster>,
|
pub cluster: Cluster,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NodeConfig {
|
||||||
|
pub fn get_node(&self) -> Option<&Node> {
|
||||||
|
for n in &self.cluster.nodes {
|
||||||
|
if n.id == self.nodeid {
|
||||||
|
return Some(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use err::Error;
|
use err::Error;
|
||||||
use netpod::{timeunits::*, Channel, ChannelConfig, Cluster, Database, Node, NodeConfig, ScalarType, Shape};
|
use netpod::NodeConfig;
|
||||||
use std::sync::Arc;
|
use tokio::io::AsyncReadExt;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use tracing::{debug, error, info, trace, warn};
|
use tracing::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
@@ -20,10 +20,18 @@ async fn go() -> Result<(), Error> {
|
|||||||
use retrieval::cli::{Opts, SubCmd};
|
use retrieval::cli::{Opts, SubCmd};
|
||||||
let opts = Opts::parse();
|
let opts = Opts::parse();
|
||||||
match opts.subcmd {
|
match opts.subcmd {
|
||||||
SubCmd::Retrieval(_subcmd) => {
|
SubCmd::Retrieval(subcmd) => {
|
||||||
trace!("testout");
|
trace!("testout");
|
||||||
info!("testout");
|
info!("testout");
|
||||||
error!("testout");
|
error!("testout");
|
||||||
|
let mut config_file = tokio::fs::File::open(subcmd.config).await?;
|
||||||
|
let mut buf = vec![];
|
||||||
|
config_file.read_to_end(&mut buf).await?;
|
||||||
|
let node_config: NodeConfig = serde_json::from_slice(&buf)?;
|
||||||
|
let node = node_config
|
||||||
|
.get_node()
|
||||||
|
.ok_or(Error::with_msg(format!("nodeid config error")))?;
|
||||||
|
retrieval::run_node(node_config.clone(), node.clone()).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -31,10 +39,11 @@ async fn go() -> Result<(), Error> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple_fetch() {
|
fn simple_fetch() {
|
||||||
|
use netpod::{timeunits::*, Channel, ChannelConfig, Cluster, Database, Node, NodeConfig, ScalarType, Shape};
|
||||||
taskrun::run(async {
|
taskrun::run(async {
|
||||||
let t1 = chrono::Utc::now();
|
let t1 = chrono::Utc::now();
|
||||||
let node = Node {
|
let node = Node {
|
||||||
id: 0,
|
id: format!("{:02}", 0),
|
||||||
host: "localhost".into(),
|
host: "localhost".into(),
|
||||||
listen: "0.0.0.0".into(),
|
listen: "0.0.0.0".into(),
|
||||||
port: 8360,
|
port: 8360,
|
||||||
@@ -43,7 +52,6 @@ fn simple_fetch() {
|
|||||||
ksprefix: "daq_swissfel".into(),
|
ksprefix: "daq_swissfel".into(),
|
||||||
split: 0,
|
split: 0,
|
||||||
};
|
};
|
||||||
let node = Arc::new(node);
|
|
||||||
let query = netpod::AggQuerySingleChannel {
|
let query = netpod::AggQuerySingleChannel {
|
||||||
channel_config: ChannelConfig {
|
channel_config: ChannelConfig {
|
||||||
channel: Channel {
|
channel: Channel {
|
||||||
@@ -71,14 +79,13 @@ fn simple_fetch() {
|
|||||||
pass: "daqbuffer".into(),
|
pass: "daqbuffer".into(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let cluster = Arc::new(cluster);
|
|
||||||
let node_config = NodeConfig {
|
let node_config = NodeConfig {
|
||||||
node: cluster.nodes[0].clone(),
|
nodeid: cluster.nodes[0].id.clone(),
|
||||||
cluster: cluster,
|
cluster,
|
||||||
};
|
};
|
||||||
let node_config = Arc::new(node_config);
|
let node = node_config.get_node().unwrap();
|
||||||
let query_string = serde_json::to_string(&query).unwrap();
|
let query_string = serde_json::to_string(&query).unwrap();
|
||||||
let host = tokio::spawn(httpret::host(node_config));
|
let host = tokio::spawn(httpret::host(node_config.clone(), node.clone()));
|
||||||
let req = hyper::Request::builder()
|
let req = hyper::Request::builder()
|
||||||
.method(http::Method::POST)
|
.method(http::Method::POST)
|
||||||
.uri("http://localhost:8360/api/1/parsed_raw")
|
.uri("http://localhost:8360/api/1/parsed_raw")
|
||||||
|
|||||||
@@ -15,4 +15,7 @@ pub enum SubCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clap)]
|
#[derive(Debug, Clap)]
|
||||||
pub struct Retrieval {}
|
pub struct Retrieval {
|
||||||
|
#[clap(long)]
|
||||||
|
pub config: String,
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use err::Error;
|
use err::Error;
|
||||||
use netpod::{Cluster, NodeConfig};
|
use netpod::{Cluster, Node, NodeConfig};
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use tracing::{debug, error, info, trace, warn};
|
use tracing::{debug, error, info, trace, warn};
|
||||||
@@ -9,15 +8,20 @@ pub mod cli;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod test;
|
pub mod test;
|
||||||
|
|
||||||
pub fn spawn_test_hosts(cluster: Arc<Cluster>) -> Vec<JoinHandle<Result<(), Error>>> {
|
pub fn spawn_test_hosts(cluster: Cluster) -> Vec<JoinHandle<Result<(), Error>>> {
|
||||||
let mut ret = vec![];
|
let mut ret = vec![];
|
||||||
for node in &cluster.nodes {
|
for node in &cluster.nodes {
|
||||||
let node_config = NodeConfig {
|
let node_config = NodeConfig {
|
||||||
cluster: cluster.clone(),
|
cluster: cluster.clone(),
|
||||||
node: node.clone(),
|
nodeid: node.id.clone(),
|
||||||
};
|
};
|
||||||
let h = tokio::spawn(httpret::host(Arc::new(node_config)));
|
let h = tokio::spawn(httpret::host(node_config, node.clone()));
|
||||||
ret.push(h);
|
ret.push(h);
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn run_node(node_config: NodeConfig, node: Node) -> Result<(), Error> {
|
||||||
|
httpret::host(node_config, node).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
+10
-14
@@ -6,25 +6,21 @@ use err::Error;
|
|||||||
use futures_util::TryStreamExt;
|
use futures_util::TryStreamExt;
|
||||||
use hyper::Body;
|
use hyper::Body;
|
||||||
use netpod::{Cluster, Database, Node};
|
use netpod::{Cluster, Database, Node};
|
||||||
use std::sync::Arc;
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use tracing::{debug, error, info, trace, warn};
|
use tracing::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
fn test_cluster() -> Cluster {
|
fn test_cluster() -> Cluster {
|
||||||
let nodes = (0..3)
|
let nodes = (0..3)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|id| {
|
.map(|id| Node {
|
||||||
let node = Node {
|
id: format!("{:02}", id),
|
||||||
id,
|
host: "localhost".into(),
|
||||||
host: "localhost".into(),
|
listen: "0.0.0.0".into(),
|
||||||
listen: "0.0.0.0".into(),
|
port: 8360 + id as u16,
|
||||||
port: 8360 + id as u16,
|
port_raw: 8360 + id as u16 + 100,
|
||||||
port_raw: 8360 + id as u16 + 100,
|
data_base_path: format!("../tmpdata/node{:02}", id).into(),
|
||||||
data_base_path: format!("../tmpdata/node{:02}", id).into(),
|
ksprefix: "ks".into(),
|
||||||
ksprefix: "ks".into(),
|
split: id,
|
||||||
split: id,
|
|
||||||
};
|
|
||||||
Arc::new(node)
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Cluster {
|
Cluster {
|
||||||
@@ -45,7 +41,7 @@ fn get_cached_0() {
|
|||||||
|
|
||||||
async fn get_cached_0_inner() -> Result<(), Error> {
|
async fn get_cached_0_inner() -> Result<(), Error> {
|
||||||
let t1 = chrono::Utc::now();
|
let t1 = chrono::Utc::now();
|
||||||
let cluster = Arc::new(test_cluster());
|
let cluster = test_cluster();
|
||||||
let node0 = &cluster.nodes[0];
|
let node0 = &cluster.nodes[0];
|
||||||
let hosts = spawn_test_hosts(cluster.clone());
|
let hosts = spawn_test_hosts(cluster.clone());
|
||||||
let beg_date: chrono::DateTime<Utc> = "1970-01-01T00:20:10.000Z".parse()?;
|
let beg_date: chrono::DateTime<Utc> = "1970-01-01T00:20:10.000Z".parse()?;
|
||||||
|
|||||||
Reference in New Issue
Block a user