forked from lavina/lavina
1
0
Fork 0
This commit is contained in:
Nikita Vilunov 2024-01-28 12:39:13 +01:00
parent fb3b2d8250
commit b9853ca74d
5 changed files with 127 additions and 2 deletions

82
Cargo.lock generated
View File

@ -99,6 +99,12 @@ version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "ascii"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16"
[[package]]
name = "assert_matches"
version = "1.5.0"
@ -307,6 +313,18 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "choice"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3b71fc821deaf602a933ada5c845d088156d0cdf2ebf43ede390afe93466553"
[[package]]
name = "chunked_transfer"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901"
[[package]]
name = "clap"
version = "4.4.11"
@ -347,6 +365,13 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "cluster-model"
version = "0.0.2-dev"
dependencies = [
"stateright",
]
[[package]]
name = "colorchoice"
version = "1.0.0"
@ -434,6 +459,19 @@ dependencies = [
"typenum",
]
[[package]]
name = "dashmap"
version = "5.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
dependencies = [
"cfg-if",
"hashbrown 0.14.3",
"lock_api",
"once_cell",
"parking_lot_core",
]
[[package]]
name = "der"
version = "0.7.8"
@ -946,6 +984,12 @@ dependencies = [
"tracing",
]
[[package]]
name = "id-set"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9633fadf6346456cf8531119ba4838bc6d82ac4ce84d9852126dd2aa34d49264"
[[package]]
name = "idna"
version = "0.5.0"
@ -1204,6 +1248,12 @@ dependencies = [
"libc",
]
[[package]]
name = "nohash-hasher"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
[[package]]
name = "nom"
version = "7.1.3"
@ -2239,6 +2289,26 @@ dependencies = [
"urlencoding",
]
[[package]]
name = "stateright"
version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "816cf2699dc5736d390feabe5da94fbce999be28d196e36a2a2c402f994f5eb1"
dependencies = [
"ahash",
"choice",
"crossbeam-utils",
"dashmap",
"id-set",
"log",
"nohash-hasher",
"parking_lot",
"rand",
"serde",
"serde_json",
"tiny_http",
]
[[package]]
name = "stringprep"
version = "0.1.4"
@ -2354,6 +2424,18 @@ dependencies = [
"once_cell",
]
[[package]]
name = "tiny_http"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "389915df6413a2e74fb181895f933386023c71110878cd0825588928e64cdc82"
dependencies = [
"ascii",
"chunked_transfer",
"httpdate",
"log",
]
[[package]]
name = "tinyvec"
version = "1.6.0"

View File

@ -8,6 +8,7 @@ members = [
"crates/mgmt-api",
"crates/sasl",
"crates/inner-api",
"crates/cluster-model",
]
[workspace.package]

View File

@ -0,0 +1,9 @@
[package]
name = "cluster-model"
edition = "2021"
version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
stateright = "0.30.1"

View File

@ -0,0 +1,28 @@
use std::collections::HashMap;
pub struct ClusterState {
nodes: HashMap<usize, NodeState>,
}
pub struct NodeState {
knowledge: HashMap<usize, NodeKnowledge>
}
pub struct NodeKnowledge {
}
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

View File

@ -11,7 +11,7 @@ use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::sync::RwLock;
use tokio::task::JoinHandle;
use tracing::{info, trace, warn};
use etcd_client::Client as EtcdClient;
use etcd_client::{Client as EtcdClient, ResignOptions};
use inner_api::proto;
use crate::prelude::Str;
@ -60,8 +60,13 @@ impl ClusterRegistry {
}));
let listener = TcpListener::bind(config.listen_on).await?;
let listener_task = start_connection_listener(listener, inner.clone()).await;
let client = EtcdClient::connect(&[config.etcd_address], None).await?;
let mut client = EtcdClient::connect(&[config.etcd_address], None).await?;
dbg!(client.maintenance_client().status().await?);
dbg!(client.leader(b"kek").await);
dbg!(client.kv_client().get(b"kek", None).await?);
let a = dbg!(client.election_client().campaign(b"kek", b"my name", 0).await?);
dbg!(client.leader(b"kek").await?);
dbg!(client.election_client().resign(Some(ResignOptions::new().with_leader(a.leader().unwrap().clone()))).await);
Ok(ClusterRegistry {