Remove in-memory locks from distribution database (#11412)

## Summary

I believe these are not necessary... They're currently used in two
places:

1. When building wheels. But that's already wrapped in an in-flight map,
which does the same thing.
2. When fetching source distribution metadata. But every route there
uses it's own `flock` to coordinate across processes, so this seems
redundant?
This commit is contained in:
Charlie Marsh 2025-02-20 20:57:31 -08:00 committed by GitHub
parent b4ba78e53b
commit 6bef1a32b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 2 additions and 31 deletions

View file

@ -2,7 +2,6 @@ use std::future::Future;
use std::io;
use std::path::Path;
use std::pin::Pin;
use std::rc::Rc;
use std::sync::Arc;
use std::task::{Context, Poll};
@ -31,7 +30,6 @@ use uv_pypi_types::HashDigest;
use uv_types::{BuildContext, BuildStack};
use crate::archive::Archive;
use crate::locks::Locks;
use crate::metadata::{ArchiveMetadata, Metadata};
use crate::source::SourceDistributionBuilder;
use crate::{Error, LocalWheel, Reporter, RequiresDist};
@ -51,7 +49,6 @@ use crate::{Error, LocalWheel, Reporter, RequiresDist};
pub struct DistributionDatabase<'a, Context: BuildContext> {
build_context: &'a Context,
builder: SourceDistributionBuilder<'a, Context>,
locks: Rc<Locks>,
client: ManagedClient<'a>,
reporter: Option<Arc<dyn Reporter>>,
}
@ -65,7 +62,6 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
Self {
build_context,
builder: SourceDistributionBuilder::new(build_context),
locks: Rc::new(Locks::default()),
client: ManagedClient::new(client, concurrent_downloads),
reporter: None,
}
@ -347,9 +343,6 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
tags: &Tags,
hashes: HashPolicy<'_>,
) -> Result<LocalWheel, Error> {
let lock = self.locks.acquire(dist).await;
let _guard = lock.lock().await;
let built_wheel = self
.builder
.download_and_build(&BuildableSource::Dist(dist), tags, hashes, &self.client)
@ -496,9 +489,6 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
}
}
let lock = self.locks.acquire(source).await;
let _guard = lock.lock().await;
let metadata = self
.builder
.download_and_build_metadata(source, hashes, &self.client)

View file

@ -14,7 +14,6 @@ mod distribution_database;
mod download;
mod error;
mod index;
mod locks;
mod metadata;
mod reporter;
mod source;

View file

@ -1,20 +0,0 @@
use std::rc::Rc;
use rustc_hash::FxHashMap;
use tokio::sync::Mutex;
use uv_distribution_types::{Identifier, ResourceId};
/// A set of locks used to prevent concurrent access to the same resource.
#[derive(Debug, Default)]
pub(crate) struct Locks(Mutex<FxHashMap<ResourceId, Rc<Mutex<()>>>>);
impl Locks {
/// Acquire a lock on the given resource.
pub(crate) async fn acquire(&self, dist: &impl Identifier) -> Rc<Mutex<()>> {
let mut map = self.0.lock().await;
map.entry(dist.resource_id())
.or_insert_with(|| Rc::new(Mutex::new(())))
.clone()
}
}