Skip to content

Commit

Permalink
file storage refactor
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 1e654aaf7ca1ea7297c37cdcea193f6aae850f1f
  • Loading branch information
gautamg795 authored and Convex, Inc. committed Jul 3, 2024
1 parent 59d4f96 commit 7011546
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
20 changes: 19 additions & 1 deletion crates/application/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ use model::{
},
ExternalPackagesModel,
},
file_storage::FileStorageId,
file_storage::{
types::FileStorageEntry,
FileStorageId,
},
modules::{
module_versions::{
AnalyzedModule,
Expand Down Expand Up @@ -2193,6 +2196,17 @@ impl<RT: Runtime> Application<RT> {
Ok(storage_id)
}

pub async fn store_file_entry(
&self,
entry: FileStorageEntry,
) -> anyhow::Result<DeveloperDocumentId> {
let storage_id = self
.file_storage
.store_entry(entry, &self.usage_tracking)
.await?;
Ok(storage_id)
}

pub async fn get_file(&self, storage_id: FileStorageId) -> anyhow::Result<FileStream> {
let mut file_storage_tx = self.begin(Identity::system()).await?;

Expand Down Expand Up @@ -2576,6 +2590,10 @@ impl<RT: Runtime> Application<RT> {
.map(|(ts, t, _)| (ts, t))
}

pub fn files_storage(&self) -> Arc<dyn Storage> {
self.files_storage.clone()
}

pub async fn shutdown(&self) -> anyhow::Result<()> {
self.log_sender.shutdown()?;
self.table_summary_worker.shutdown().await?;
Expand Down
11 changes: 10 additions & 1 deletion crates/file_storage/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,19 @@ impl<RT: Runtime> FileStorage<RT> {
.transactional_file_storage
.upload_file(content_length, content_type, file, expected_sha256)
.await?;
let size = entry.size;
self.store_entry(entry, usage_tracker).await
}

/// Record the existence of a file that has already been uploaded to the
/// underlying storage implementation.
pub async fn store_entry(
&self,
entry: FileStorageEntry,
usage_tracker: &dyn StorageUsageTracker,
) -> anyhow::Result<DeveloperDocumentId> {
// Start/Complete transaction after the slow upload process
// to avoid OCC risk.
let size = entry.size;
let mut tx = self.database.begin(Identity::system()).await?;
let virtual_id = self
.transactional_file_storage
Expand Down

0 comments on commit 7011546

Please sign in to comment.