From 5f4c0818beafefba52934cc0f92ce5dc66a77c21 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Sun, 17 Dec 2023 19:22:42 +0530 Subject: [PATCH] feat: introduce self to introducer node on app startup --- src/app.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/app.rs b/src/app.rs index 4e23395..e5fec4a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -15,10 +15,17 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +use std::collections::BTreeMap; use std::sync::Arc; +use std::time::Duration; +use openraft::error::RaftError; +use openraft::BasicNode; use openraft::Config; +use crate::network::raft_network_impl::DcacheNetwork; +//use crate::network::raft_network_impl::HealthLedger; +use crate::typ::InitializeError; use crate::DcacheNodeId; use crate::DcacheRaft; use crate::DcacheStore; @@ -31,4 +38,45 @@ pub struct DcacheApp { pub raft: DcacheRaft, pub store: Arc, pub config: Arc, + pub network: Arc, +} + +impl DcacheApp { + // // pub async fn introduce(&self) { + // // for (node_id, http_addr) = + // // + // // let req: (DcacheNodeId, String) = (node_id, http_addr); + // // let c =reqwest::Client::new(); + // // c.post( + // // format!("http://{}/add-learner", introducer_addr)).json(&req).send().await.unwrap(); + // // + // // } + // + // // pub async fn change_membership(&self) { + // // let r= self.network.online.read().unwrap(); + // // self.raft.change_membership(&*r, false).await + // // } + // // + // // pub fn mark_node_online(&self, + // // + // // (node_id, node_addr): (DcacheNodeId, String) + // // ) { + // // let mut w= self.network.online.write().unwrap(); + // // if w.get(node_id).is_some() { + // // return; + // // } + // // + // // w.insert(node_id, node_addr); + // // } + // + pub async fn init(&self) -> Result<(), RaftError> { + let mut nodes = BTreeMap::new(); + nodes.insert( + self.id, + BasicNode { + addr: self.addr.clone(), + }, + ); + self.raft.initialize(nodes).await + } }