mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-07 22:03:14 +00:00
put_object func add lock
Signed-off-by: junxiang Mu <1948535941@qq.com>
This commit is contained in:
@@ -107,7 +107,7 @@ impl DRWMutex {
|
||||
|
||||
tolerance = locker_len - quorum;
|
||||
let mut attempt = 0;
|
||||
let mut locks = Vec::with_capacity(self.lockers.len());
|
||||
let mut locks = vec!["".to_string(); self.lockers.len()];
|
||||
|
||||
loop {
|
||||
if self.inner_lock(&mut locks, id, source, is_read_lock, tolerance, quorum).await {
|
||||
@@ -202,12 +202,12 @@ impl DRWMutex {
|
||||
|
||||
pub async fn un_lock(&mut self) {
|
||||
if self.write_locks.is_empty() || !self.write_locks.iter().any(|w_lock| is_locked(w_lock)) {
|
||||
panic!("Trying to un_lock() while no lock() is active")
|
||||
panic!("Trying to un_lock() while no lock() is active, write_locks: {:?}", self.write_locks)
|
||||
}
|
||||
|
||||
let tolerance = self.lockers.len() / 2;
|
||||
let is_read_lock = false;
|
||||
let mut locks = self.write_locks.clone();
|
||||
let mut locks = std::mem::take(&mut self.write_locks);
|
||||
let start = Instant::now();
|
||||
loop {
|
||||
if self.release_all(tolerance, &mut locks, is_read_lock).await {
|
||||
@@ -222,13 +222,13 @@ impl DRWMutex {
|
||||
}
|
||||
|
||||
pub async fn un_r_lock(&mut self) {
|
||||
if self.write_locks.is_empty() || !self.write_locks.iter().any(|w_lock| is_locked(w_lock)) {
|
||||
panic!("Trying to un_r_lock() while no r_lock() is active")
|
||||
if self.read_locks.is_empty() || !self.read_locks.iter().any(|r_lock| is_locked(r_lock)) {
|
||||
panic!("Trying to un_r_lock() while no r_lock() is active, read_locks: {:?}", self.read_locks)
|
||||
}
|
||||
|
||||
let tolerance = self.lockers.len() / 2;
|
||||
let is_read_lock = true;
|
||||
let mut locks = self.write_locks.clone();
|
||||
let mut locks = std::mem::take(&mut self.read_locks);
|
||||
let start = Instant::now();
|
||||
loop {
|
||||
if self.release_all(tolerance, &mut locks, is_read_lock).await {
|
||||
@@ -249,7 +249,7 @@ impl DRWMutex {
|
||||
}
|
||||
}
|
||||
|
||||
check_failed_unlocks(&locks, tolerance)
|
||||
!check_failed_unlocks(&locks, tolerance)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
@@ -5,7 +7,7 @@ use common::error::Result;
|
||||
use lazy_static::lazy_static;
|
||||
use local_locker::LocalLocker;
|
||||
use lock_args::LockArgs;
|
||||
use remote_client::RemoteClinet;
|
||||
use remote_client::RemoteClient;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub mod drwmutex;
|
||||
@@ -37,7 +39,7 @@ pub trait Locker {
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum LockApi {
|
||||
Local,
|
||||
Remote(RemoteClinet),
|
||||
Remote(RemoteClient),
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -111,5 +113,5 @@ pub fn new_lock_api(is_local: bool, url: Option<url::Url>) -> LockApi {
|
||||
return LockApi::Local;
|
||||
}
|
||||
|
||||
LockApi::Remote(RemoteClinet::new(url.unwrap()))
|
||||
LockApi::Remote(RemoteClient::new(url.unwrap()))
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ impl Locker for LocalLocker {
|
||||
|
||||
// TODO: need add timeout mechanism
|
||||
async fn force_unlock(&mut self, args: &LockArgs) -> Result<bool> {
|
||||
let mut reply = false;
|
||||
let mut reply: bool;
|
||||
if args.uid.is_empty() {
|
||||
args.resources.iter().for_each(|resource| match self.lock_map.get(resource) {
|
||||
Some(lris) => {
|
||||
|
||||
@@ -34,6 +34,13 @@ pub struct NsLockMap {
|
||||
}
|
||||
|
||||
impl NsLockMap {
|
||||
pub fn new(is_dist_erasure: bool) -> Self {
|
||||
Self {
|
||||
is_dist_erasure,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
async fn lock(
|
||||
&mut self,
|
||||
volume: &String,
|
||||
|
||||
@@ -7,11 +7,11 @@ use tracing::info;
|
||||
use crate::{lock_args::LockArgs, Locker};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RemoteClinet {
|
||||
pub struct RemoteClient {
|
||||
url: url::Url,
|
||||
}
|
||||
|
||||
impl RemoteClinet {
|
||||
impl RemoteClient {
|
||||
pub fn new(url: url::Url) -> Self {
|
||||
Self { url }
|
||||
}
|
||||
@@ -24,7 +24,7 @@ impl RemoteClinet {
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Locker for RemoteClinet {
|
||||
impl Locker for RemoteClient {
|
||||
async fn lock(&mut self, args: &LockArgs) -> Result<bool> {
|
||||
info!("remote lock");
|
||||
let args = serde_json::to_string(args)?;
|
||||
|
||||
Reference in New Issue
Block a user