feat: introduce self to introducer node on app startup

This commit is contained in:
Aravinth Manivannan 2023-12-17 19:22:42 +05:30
parent d74e3f9824
commit 5f4c0818be
Signed by: realaravinth
GPG key ID: F8F50389936984FF

View file

@ -15,10 +15,17 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
use std::collections::BTreeMap;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration;
use openraft::error::RaftError;
use openraft::BasicNode;
use openraft::Config; 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::DcacheNodeId;
use crate::DcacheRaft; use crate::DcacheRaft;
use crate::DcacheStore; use crate::DcacheStore;
@ -31,4 +38,45 @@ pub struct DcacheApp {
pub raft: DcacheRaft, pub raft: DcacheRaft,
pub store: Arc<DcacheStore>, pub store: Arc<DcacheStore>,
pub config: Arc<Config>, pub config: Arc<Config>,
pub network: Arc<DcacheNetwork>,
}
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<u64, InitializeError>> {
let mut nodes = BTreeMap::new();
nodes.insert(
self.id,
BasicNode {
addr: self.addr.clone(),
},
);
self.raft.initialize(nodes).await
}
} }