debuggage des stream
This commit is contained in:
@@ -70,7 +70,8 @@ pub struct Cache<C: CacheConfig> {
|
||||
impl<C: CacheConfig> Cache<C> {
|
||||
/// Retourne le chemin du fichier marker de complétion
|
||||
fn get_completion_marker_path(&self, pk: &str) -> PathBuf {
|
||||
self.get_file_path(pk).with_extension(format!("{}.complete", C::file_extension()))
|
||||
self.get_file_path(pk)
|
||||
.with_extension(format!("{}.complete", C::file_extension()))
|
||||
}
|
||||
|
||||
/// Vérifie si un fichier est en cache et complet
|
||||
@@ -118,10 +119,15 @@ impl<C: CacheConfig> Cache<C> {
|
||||
};
|
||||
|
||||
if let Some(download) = download_handle {
|
||||
tracing::debug!("Download already in progress for pk {}, waiting for prebuffering", pk);
|
||||
tracing::debug!(
|
||||
"Download already in progress for pk {}, waiting for prebuffering",
|
||||
pk
|
||||
);
|
||||
|
||||
if self.min_prebuffer_size > 0 {
|
||||
download.wait_until_min_size(self.min_prebuffer_size).await
|
||||
download
|
||||
.wait_until_min_size(self.min_prebuffer_size)
|
||||
.await
|
||||
.map_err(|e| anyhow!("Prebuffering failed: {}", e))?;
|
||||
tracing::debug!("Prebuffering complete for pk {}", pk);
|
||||
}
|
||||
@@ -138,9 +144,15 @@ impl<C: CacheConfig> Cache<C> {
|
||||
async fn finalize_download(&self, pk: &str, download: Arc<Download>) -> Result<String> {
|
||||
// Attendre le prébuffering (pour le cache progressif)
|
||||
if self.min_prebuffer_size > 0 {
|
||||
download.wait_until_min_size(self.min_prebuffer_size).await
|
||||
download
|
||||
.wait_until_min_size(self.min_prebuffer_size)
|
||||
.await
|
||||
.map_err(|e| anyhow!("Prebuffering failed: {}", e))?;
|
||||
tracing::debug!("Prebuffering complete for pk {} ({} bytes)", pk, self.min_prebuffer_size);
|
||||
tracing::debug!(
|
||||
"Prebuffering complete for pk {} ({} bytes)",
|
||||
pk,
|
||||
self.min_prebuffer_size
|
||||
);
|
||||
}
|
||||
|
||||
// Lancer une tâche de nettoyage et marquage de complétion en background
|
||||
@@ -155,7 +167,11 @@ impl<C: CacheConfig> Cache<C> {
|
||||
// Créer le fichier marker de complétion si le téléchargement a réussi
|
||||
if result.is_ok() {
|
||||
if let Err(e) = std::fs::write(&completion_marker, "") {
|
||||
tracing::warn!("Failed to create completion marker for pk {}: {}", pk_clone, e);
|
||||
tracing::warn!(
|
||||
"Failed to create completion marker for pk {}: {}",
|
||||
pk_clone,
|
||||
e
|
||||
);
|
||||
} else {
|
||||
tracing::debug!("Created completion marker for pk {}", pk_clone);
|
||||
}
|
||||
@@ -368,7 +384,8 @@ impl<C: CacheConfig> Cache<C> {
|
||||
where
|
||||
R: AsyncRead + Send + Unpin + 'static,
|
||||
{
|
||||
self.add_from_reader_with_pk(source_uri, reader, length, collection, None).await
|
||||
self.add_from_reader_with_pk(source_uri, reader, length, collection, None)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Ajoute un fichier à partir d'un flux avec un pk explicite optionnel.
|
||||
|
||||
@@ -163,20 +163,29 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
|
||||
}
|
||||
|
||||
if !file_path.exists() {
|
||||
tracing::warn!("is_valid_pk({}): File not created after 1s despite DB entry existing", pk);
|
||||
tracing::warn!(
|
||||
"is_valid_pk({}): File not created after 1s despite DB entry existing",
|
||||
pk
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
tracing::debug!("is_valid_pk({}): File created after {}ms", pk, attempts * 10);
|
||||
tracing::debug!(
|
||||
"is_valid_pk({}): File created after {}ms",
|
||||
pk,
|
||||
attempts * 10
|
||||
);
|
||||
}
|
||||
|
||||
// Vérifier d'abord si le marker de completion existe
|
||||
let completion_marker = file_path.with_extension(
|
||||
format!("{}.complete", C::file_extension())
|
||||
);
|
||||
let completion_marker =
|
||||
file_path.with_extension(format!("{}.complete", C::file_extension()));
|
||||
|
||||
if completion_marker.exists() {
|
||||
tracing::debug!("is_valid_pk({}): Completion marker found, file is complete", pk);
|
||||
tracing::debug!(
|
||||
"is_valid_pk({}): Completion marker found, file is complete",
|
||||
pk
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -190,7 +199,11 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
|
||||
tracing::debug!("is_valid_pk({}): No marker but file is recent ({}s), download in progress", pk, age_secs);
|
||||
return true;
|
||||
} else {
|
||||
tracing::debug!("is_valid_pk({}): No marker and file is old ({}s), incomplete download", pk, age_secs);
|
||||
tracing::debug!(
|
||||
"is_valid_pk({}): No marker and file is old ({}s), incomplete download",
|
||||
pk,
|
||||
age_secs
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +211,10 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
|
||||
}
|
||||
|
||||
// Ne peut pas vérifier le statut - rejeter par sécurité
|
||||
tracing::debug!("is_valid_pk({}): Could not check file status, rejecting", pk);
|
||||
tracing::debug!(
|
||||
"is_valid_pk({}): Could not check file status, rejecting",
|
||||
pk
|
||||
);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,14 +295,28 @@ fn test_metadata_types() {
|
||||
db.add(pk, None, None).unwrap();
|
||||
|
||||
// Tester les différents types de métadonnées
|
||||
db.set_a_metadata(pk, "string_val", Value::String("test".to_string())).unwrap();
|
||||
db.set_a_metadata(pk, "string_val", Value::String("test".to_string()))
|
||||
.unwrap();
|
||||
db.set_a_metadata(pk, "number_val", json!(42)).unwrap();
|
||||
db.set_a_metadata(pk, "bool_val", Value::Bool(true)).unwrap();
|
||||
db.set_a_metadata(pk, "bool_val", Value::Bool(true))
|
||||
.unwrap();
|
||||
db.set_a_metadata(pk, "null_val", Value::Null).unwrap();
|
||||
|
||||
// Vérifier les valeurs
|
||||
assert_eq!(db.get_metadata_value(pk, "string_val").unwrap(), Some(Value::String("test".to_string())));
|
||||
assert_eq!(db.get_metadata_value(pk, "number_val").unwrap(), Some(json!(42)));
|
||||
assert_eq!(db.get_metadata_value(pk, "bool_val").unwrap(), Some(Value::Bool(true)));
|
||||
assert_eq!(db.get_metadata_value(pk, "null_val").unwrap(), Some(Value::Null));
|
||||
assert_eq!(
|
||||
db.get_metadata_value(pk, "string_val").unwrap(),
|
||||
Some(Value::String("test".to_string()))
|
||||
);
|
||||
assert_eq!(
|
||||
db.get_metadata_value(pk, "number_val").unwrap(),
|
||||
Some(json!(42))
|
||||
);
|
||||
assert_eq!(
|
||||
db.get_metadata_value(pk, "bool_val").unwrap(),
|
||||
Some(Value::Bool(true))
|
||||
);
|
||||
assert_eq!(
|
||||
db.get_metadata_value(pk, "null_val").unwrap(),
|
||||
Some(Value::Null)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user