Use a different R/W lock implementation

next
Sayan Nandan 4 years ago
parent 16945337fa
commit d926e35e22
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

135
Cargo.lock generated

@ -40,6 +40,15 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cloudabi"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467"
dependencies = [
"bitflags",
]
[[package]]
name = "corelib"
version = "0.2.0"
@ -47,6 +56,12 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "devtimer"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6035b7b9244bf9637cd7ef80b5e1c54404bef92cccd34738c85c45f04ae8b244"
[[package]]
name = "fnv"
version = "1.0.7"
@ -75,6 +90,17 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399"
[[package]]
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hermit-abi"
version = "0.1.15"
@ -84,6 +110,12 @@ dependencies = [
"libc",
]
[[package]]
name = "instant"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485"
[[package]]
name = "iovec"
version = "0.1.4"
@ -115,6 +147,15 @@ version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
[[package]]
name = "lock_api"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c"
dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.8"
@ -215,12 +256,44 @@ dependencies = [
"libc",
]
[[package]]
name = "parking_lot"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b"
dependencies = [
"cfg-if",
"cloudabi",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi 0.3.9",
]
[[package]]
name = "pin-project-lite"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715"
[[package]]
name = "ppv-lite86"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
[[package]]
name = "proc-macro2"
version = "1.0.18"
@ -239,12 +312,59 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom",
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.114"
@ -267,6 +387,12 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "smallvec"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
[[package]]
name = "socket2"
version = "0.3.12"
@ -297,6 +423,7 @@ dependencies = [
"bincode",
"bytes",
"corelib",
"parking_lot",
"tokio",
]
@ -340,6 +467,8 @@ name = "tsh"
version = "0.2.0"
dependencies = [
"corelib",
"devtimer",
"rand",
"tokio",
]
@ -349,6 +478,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "winapi"
version = "0.2.8"

@ -10,4 +10,5 @@ edition = "2018"
tokio = { version = "0.2.22", features = ["full"] }
bytes = "0.5.6"
corelib = {path ="../corelib"}
bincode = "1.3.1"
bincode = "1.3.1"
parking_lot = "0.11.0"

@ -23,10 +23,11 @@ use crate::protocol::QueryDataframe;
use bincode;
use corelib::terrapipe::{tags, ActionType, RespBytes, RespCodes, ResponseBuilder};
use corelib::TResult;
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use std::collections::{hash_map::Entry, HashMap};
use std::fs;
use std::io::{ErrorKind, Write};
use std::sync::{self, Arc, RwLock};
use std::sync::Arc;
/// Results from actions on the Database
pub type ActionResult<T> = Result<T, RespCodes>;
@ -206,12 +207,12 @@ impl CoreDB {
}
}
/// Acquire a write lock
fn acquire_write(&self) -> sync::RwLockWriteGuard<'_, HashMap<String, String>> {
self.shared.coremap.write().unwrap()
fn acquire_write(&self) -> RwLockWriteGuard<'_, HashMap<String, String>> {
self.shared.coremap.write()
}
/// Acquire a read lock
fn acquire_read(&self) -> sync::RwLockReadGuard<'_, HashMap<String, String>> {
self.shared.coremap.read().unwrap()
fn acquire_read(&self) -> RwLockReadGuard<'_, HashMap<String, String>> {
self.shared.coremap.read()
}
pub fn flush_db(&self) -> TResult<()> {
let encoded = bincode::serialize(&*self.acquire_read())?;
@ -238,7 +239,7 @@ impl Drop for CoreDB {
fn drop(&mut self) {
if Arc::strong_count(&self.shared) == 1 {
// Acquire a lock to prevent anyone from writing something
let coremap = self.shared.coremap.write().unwrap();
let coremap = self.shared.coremap.write();
self.terminate = true;
drop(coremap);
}

@ -172,7 +172,7 @@ pub async fn run(listener: TcpListener, sig: impl Future) {
let mut server = Listener {
listener,
db,
climit: Arc::new(Semaphore::new(10000)),
climit: Arc::new(Semaphore::new(50000)),
signal,
terminate_tx,
terminate_rx,

Loading…
Cancel
Save