feat: use faster counter impl

This commit is contained in:
Aravinth Manivannan 2023-12-29 20:09:48 +05:30
parent 45a49288b7
commit 20296d5a70
Signed by: realaravinth
GPG key ID: F8F50389936984FF
4 changed files with 411 additions and 459 deletions

806
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,8 +13,8 @@ openraft = { version = "0.8.8", features = ["serde", "single-term-leader"]}
#libmcaptcha = { path="/src/atm/code/mcaptcha/libmcaptcha", features=["full"] } #libmcaptcha = { path="/src/atm/code/mcaptcha/libmcaptcha", features=["full"] }
libmcaptcha = { git = "https://github.com/mcaptcha/libmcaptcha", branch = "feat-dcache", features = ["full"]} libmcaptcha = { git = "https://github.com/mcaptcha/libmcaptcha", branch = "feat-dcache", features = ["full"]}
tracing = { version = "0.1.37", features = ["log"] } tracing = { version = "0.1.37", features = ["log"] }
serde_json = "1.0.96" serde_json = "1"
serde = { version = "1.0.163", features = ["derive"] } serde = { version = "1", features = ["derive"] }
byteorder = "1.4.3" byteorder = "1.4.3"
futures-util = { version = "0.3.17", default-features = false, features = ["std"] } futures-util = { version = "0.3.17", default-features = false, features = ["std"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"
@ -26,7 +26,7 @@ derive_more = "0.99.17"
url = { version = "2.2.2", features = ["serde"]} url = { version = "2.2.2", features = ["serde"]}
async-trait = "0.1.36" async-trait = "0.1.36"
clap = { version = "4.1.11", features = ["derive", "env"] } clap = { version = "4.1.11", features = ["derive", "env"] }
tokio = { version = "1.0", default-features = false, features = ["sync", "macros", "rt-multi-thread"] } tokio = { version = "1.0", default-features = false, features = ["sync", "macros", "rt-multi-thread", "time"] }
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] } tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
actix = "0.13.0" actix = "0.13.0"
tonic = { version = "0.10.2", features = ["transport", "channel"] } tonic = { version = "0.10.2", features = ["transport", "channel"] }
@ -34,6 +34,9 @@ prost = "0.12.3"
tokio-stream = "0.1.14" tokio-stream = "0.1.14"
async-stream = "0.3.5" async-stream = "0.3.5"
actix-rt = "2.9.0" actix-rt = "2.9.0"
futures = "0.3.30"
tower-service = "0.3.2"
dashmap = { version = "5.5.3", features = ["serde"] }
[build-dependencies] [build-dependencies]
@ -44,3 +47,6 @@ tonic-build = "0.10.2"
base64 = "0.13.0" base64 = "0.13.0"
anyhow = "1.0.63" anyhow = "1.0.63"
maplit = "1.0.2" maplit = "1.0.2"
[profile.release]
debug = true

View file

@ -36,7 +36,9 @@ use crate::store::DcacheResponse;
use crate::store::DcacheStore; use crate::store::DcacheStore;
pub mod app; pub mod app;
mod mcaptcha;
pub mod network; pub mod network;
mod pool;
mod protobuf; mod protobuf;
pub mod store; pub mod store;

View file

@ -95,6 +95,7 @@ pub struct DcacheStateMachine {
/// Application data. /// Application data.
pub data: Arc<System<HashCache, EmbeddedMaster>>, pub data: Arc<System<HashCache, EmbeddedMaster>>,
pub new_data: crate::mcaptcha::mcaptcha::Manager,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone)]
@ -129,16 +130,13 @@ impl PersistableStateMachine {
self, self,
data: Arc<System<HashCache, EmbeddedMaster>>, data: Arc<System<HashCache, EmbeddedMaster>>,
) -> DcacheStateMachine { ) -> DcacheStateMachine {
data.master let new_data = crate::mcaptcha::mcaptcha::Manager::new(30);
.send(SetInternalData { new_data.set_internal_data(self.data.clone());
mcaptcha: self.data,
})
.await
.unwrap();
DcacheStateMachine { DcacheStateMachine {
last_applied_log: self.last_applied_log, last_applied_log: self.last_applied_log,
last_membership: self.last_membership, last_membership: self.last_membership,
data, data,
new_data,
} }
} }
} }
@ -166,6 +164,7 @@ impl DcacheStore {
last_applied_log: Default::default(), last_applied_log: Default::default(),
last_membership: Default::default(), last_membership: Default::default(),
data: system::init_system(salt), data: system::init_system(salt),
new_data: crate::mcaptcha::mcaptcha::Manager::new(30),
}); });
Self { Self {
@ -391,49 +390,22 @@ impl RaftStorage<DcacheTypeConfig> for Arc<DcacheStore> {
EntryPayload::Blank => res.push(DcacheResponse::Empty), EntryPayload::Blank => res.push(DcacheResponse::Empty),
EntryPayload::Normal(ref req) => match req { EntryPayload::Normal(ref req) => match req {
DcacheRequest::AddVisitor(msg) => { DcacheRequest::AddVisitor(msg) => {
let r = sm let r = sm.new_data.add_visitor(msg);
.data
.master
.send(msg.clone())
.await
.unwrap()
.await
.unwrap()
.unwrap();
res.push(DcacheResponse::AddVisitorResult(r)); res.push(DcacheResponse::AddVisitorResult(r));
} }
DcacheRequest::AddCaptcha(msg) => { DcacheRequest::AddCaptcha(msg) => {
sm.data sm.new_data
.master .add_captcha(Arc::new((&msg.mcaptcha).into()), msg.id.clone());
.send(msg.clone())
.await
.unwrap()
.await
.unwrap()
.unwrap();
res.push(DcacheResponse::Empty); res.push(DcacheResponse::Empty);
} }
DcacheRequest::RenameCaptcha(msg) => { DcacheRequest::RenameCaptcha(msg) => {
sm.data sm.new_data.rename(&msg.name, msg.rename_to.clone());
.master
.send(msg.clone())
.await
.unwrap()
.await
.unwrap()
.unwrap();
res.push(DcacheResponse::Empty); res.push(DcacheResponse::Empty);
} }
DcacheRequest::RemoveCaptcha(msg) => { DcacheRequest::RemoveCaptcha(msg) => {
sm.data sm.new_data.rm_captcha(&msg.0);
.master
.send(msg.clone())
.await
.unwrap()
.await
.unwrap()
.unwrap();
res.push(DcacheResponse::Empty); res.push(DcacheResponse::Empty);
} }