diff options
author | Alex Auvolat <alex@adnab.me> | 2024-02-22 12:28:21 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2024-02-22 12:28:21 +0100 |
commit | cff702a951cb5bb193c7a891ababfd1d962ae9ed (patch) | |
tree | f7747f950672246c1ecc079e50222a07d23bc635 /src/model/garage.rs | |
parent | 7e212e20e02b9cdced52ce23111214c6285a095a (diff) | |
download | garage-cff702a951cb5bb193c7a891ababfd1d962ae9ed.tar.gz garage-cff702a951cb5bb193c7a891ababfd1d962ae9ed.zip |
[lock-createbucket] Add node-global lock for bucket/key operations (fix #723)lock-createbucket
Diffstat (limited to 'src/model/garage.rs')
-rw-r--r-- | src/model/garage.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/model/garage.rs b/src/model/garage.rs index c10d64c5..fe38a760 100644 --- a/src/model/garage.rs +++ b/src/model/garage.rs @@ -56,6 +56,9 @@ pub struct Garage { /// Table containing api keys pub key_table: Arc<Table<KeyTable, TableFullReplication>>, + /// Lock to prevent concurrent modification of buckets and access keys + bucket_lock: tokio::sync::Mutex<()>, + /// Table containing S3 objects pub object_table: Arc<Table<ObjectTable, TableShardedReplication>>, /// Counting table containing object counters @@ -343,6 +346,7 @@ impl Garage { bucket_table, bucket_alias_table, key_table, + bucket_lock: tokio::sync::Mutex::new(()), object_table, object_counter_table, mpu_table, @@ -385,6 +389,11 @@ impl Garage { pub fn key_helper(&self) -> helper::key::KeyHelper { helper::key::KeyHelper(self) } + + pub async fn locked_helper(&self) -> helper::locked::LockedHelper { + let lock = self.bucket_lock.lock().await; + helper::locked::LockedHelper(self, lock) + } } #[cfg(feature = "k2v")] |