Skip to content

Commit dc58813

Browse files
Sujay JayakarConvex, Inc.
authored andcommitted
Remove remaining Component.*TODOs (#30708)
GitOrigin-RevId: 203aaaf997f7cbaddba01dbdbb7f843cead85b02
1 parent 3626234 commit dc58813

File tree

14 files changed

+113
-94
lines changed

14 files changed

+113
-94
lines changed

crates/application/src/application_function_runner/mod.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use common::{
2727
ComponentDefinitionPath,
2828
ComponentId,
2929
ComponentName,
30+
ComponentPath,
3031
PublicFunctionPath,
3132
Resource,
3233
},
@@ -1952,23 +1953,28 @@ impl<RT: Runtime> ActionCallbacks for ApplicationFunctionRunner<RT> {
19521953
identity: Identity,
19531954
component: ComponentId,
19541955
storage_id: FileStorageId,
1955-
) -> anyhow::Result<Option<FileStorageEntry>> {
1956+
) -> anyhow::Result<Option<(ComponentPath, FileStorageEntry)>> {
19561957
let mut tx = self.database.begin(identity).await?;
19571958
self.bail_if_backend_not_running(&mut tx).await?;
1958-
self.file_storage
1959+
let Some(component_path) = tx.get_component_path(component) else {
1960+
return Ok(None);
1961+
};
1962+
let entry = self
1963+
.file_storage
19591964
.get_file_entry(&mut tx, component.into(), storage_id)
1960-
.await
1965+
.await?;
1966+
Ok(entry.map(|e| (component_path, e)))
19611967
}
19621968

19631969
async fn storage_store_file_entry(
19641970
&self,
19651971
identity: Identity,
19661972
component: ComponentId,
19671973
entry: FileStorageEntry,
1968-
) -> anyhow::Result<DeveloperDocumentId> {
1974+
) -> anyhow::Result<(ComponentPath, DeveloperDocumentId)> {
19691975
let mut tx = self.database.begin(identity.clone()).await?;
19701976
self.bail_if_backend_not_running(&mut tx).await?;
1971-
let (_ts, id, _stats) = self
1977+
let (_ts, r, _stats) = self
19721978
.database
19731979
.execute_with_occ_retries(
19741980
identity,
@@ -1977,17 +1983,20 @@ impl<RT: Runtime> ActionCallbacks for ApplicationFunctionRunner<RT> {
19771983
"app_funrun_storage_store_file_entry",
19781984
|tx| {
19791985
async {
1986+
let component_path = tx
1987+
.get_component_path(component)
1988+
.context(format!("Component {component:?} not found"))?;
19801989
let id = self
19811990
.file_storage
19821991
.store_file_entry(tx, component.into(), entry.clone())
19831992
.await?;
1984-
Ok(id)
1993+
Ok((component_path, id))
19851994
}
19861995
.into()
19871996
},
19881997
)
19891998
.await?;
1990-
Ok(id)
1999+
Ok(r)
19912000
}
19922001

19932002
async fn storage_delete(

crates/application/src/function_log.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ impl FunctionExecution {
171171
};
172172
let component_path = match &self.params {
173173
UdfParams::Function { identifier, .. } => identifier.component.clone(),
174-
UdfParams::Http { .. } => ComponentPath::TODO(),
174+
// TODO(ENG-7612): Support HTTP actions in components.
175+
UdfParams::Http { .. } => ComponentPath::root(),
175176
};
176177

177178
FunctionEventSource {
@@ -977,7 +978,8 @@ impl<RT: Runtime> FunctionExecutionLog<RT> {
977978
module_environment: ModuleEnvironment,
978979
) {
979980
let event_source = FunctionEventSource {
980-
component_path: ComponentPath::TODO(),
981+
// TODO(ENG-7612): Support HTTP actions in components.
982+
component_path: ComponentPath::root(),
981983
udf_path: identifier.to_string(),
982984
udf_type: UdfType::HttpAction,
983985
module_environment,

crates/application/src/lib.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,12 +2470,32 @@ impl<RT: Runtime> Application<RT> {
24702470
storage_id: FileStorageId,
24712471
) -> anyhow::Result<FileStream> {
24722472
self.bail_if_not_running().await?;
2473-
let file_entry = self.get_file_entry(component, storage_id).await?;
2473+
let mut file_storage_tx = self.begin(Identity::system()).await?;
2474+
let Some(file_entry) = self
2475+
.file_storage
2476+
.transactional_file_storage
2477+
// The transaction is not part of UDF so use the global usage counters.
2478+
.get_file_entry(&mut file_storage_tx, component.into(), storage_id.clone())
2479+
.await?
2480+
else {
2481+
return Err(ErrorMetadata::transient_not_found(
2482+
"FileNotFound",
2483+
format!("File {storage_id} not found"),
2484+
)
2485+
.into());
2486+
};
2487+
let Some(component_path) = file_storage_tx.get_component_path(component) else {
2488+
return Err(ErrorMetadata::transient_not_found(
2489+
"FileNotFound",
2490+
format!("Component {component:?} not found"),
2491+
)
2492+
.into());
2493+
};
24742494
self
24752495
.file_storage
24762496
.transactional_file_storage
24772497
// The transaction is not part of UDF so use the global usage counters.
2478-
.get_file_stream(file_entry, self.usage_tracking.clone())
2498+
.get_file_stream(component_path, file_entry, self.usage_tracking.clone())
24792499
.await
24802500
}
24812501

@@ -2501,12 +2521,24 @@ impl<RT: Runtime> Application<RT> {
25012521
)
25022522
.into());
25032523
};
2524+
let Some(component_path) = file_storage_tx.get_component_path(component) else {
2525+
return Err(ErrorMetadata::transient_not_found(
2526+
"FileNotFound",
2527+
format!("Component {component:?} not found"),
2528+
)
2529+
.into());
2530+
};
25042531

25052532
self
25062533
.file_storage
25072534
.transactional_file_storage
25082535
// The transaction is not part of UDF so use the global usage counters.
2509-
.get_file_range_stream(file_entry, bytes_range, self.usage_tracking.clone())
2536+
.get_file_range_stream(
2537+
component_path,
2538+
file_entry,
2539+
bytes_range,
2540+
self.usage_tracking.clone(),
2541+
)
25102542
.await
25112543
}
25122544

crates/common/src/components/component_path.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ impl ComponentPath {
8989
self.path.is_empty()
9090
}
9191

92-
/// Use ComponentPath::TODO() when the path should be passed down from a
93-
/// higher layer.
94-
#[allow(non_snake_case)]
95-
pub fn TODO() -> Self {
96-
Self::root()
97-
}
98-
9992
/// Component path to use in tests, representing a user-space component.
10093
/// Ideally this could be changed to an arbitrary path and the tests would
10194
/// still pass.

crates/common/src/components/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ impl ComponentId {
4646
matches!(self, ComponentId::Root)
4747
}
4848

49-
/// This component should be passed in somehow -- it's not always going to
50-
/// be Root.
51-
#[allow(non_snake_case)]
52-
pub const fn TODO() -> Self {
53-
ComponentId::Root
54-
}
55-
5649
/// Component for tests where we need a user component.
5750
/// Ideally we could switch this to some other component with no test
5851
/// breakage.

crates/file_storage/src/core.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,15 @@ impl<RT: Runtime> TransactionalFileStorage<RT> {
185185

186186
pub async fn get_file_stream(
187187
&self,
188+
component_path: ComponentPath,
188189
file: FileStorageEntry,
189190
usage_tracker: impl StorageUsageTracker + Clone + 'static,
190191
) -> anyhow::Result<FileStream> {
191192
let sha256 = file.sha256.clone();
192193

193194
let result = self
194195
.file_stream(
196+
component_path,
195197
file,
196198
(Bound::Included(0), Bound::Unbounded),
197199
usage_tracker,
@@ -209,16 +211,24 @@ impl<RT: Runtime> TransactionalFileStorage<RT> {
209211

210212
pub async fn get_file_range_stream(
211213
&self,
214+
component_path: ComponentPath,
212215
file: FileStorageEntry,
213216
bytes_range: (Bound<u64>, Bound<u64>),
214217
usage_tracker: impl StorageUsageTracker + Clone + 'static,
215218
) -> anyhow::Result<FileRangeStream> {
216-
self.file_stream(file, bytes_range, usage_tracker, GetFileType::Range)
217-
.await
219+
self.file_stream(
220+
component_path,
221+
file,
222+
bytes_range,
223+
usage_tracker,
224+
GetFileType::Range,
225+
)
226+
.await
218227
}
219228

220229
async fn file_stream(
221230
&self,
231+
component_path: ComponentPath,
222232
file: FileStorageEntry,
223233
bytes_range: (Bound<u64>, Bound<u64>),
224234
usage_tracker: impl StorageUsageTracker + Clone + 'static,
@@ -243,7 +253,6 @@ impl<RT: Runtime> TransactionalFileStorage<RT> {
243253
let stream = storage_get_stream.stream;
244254
let content_length = ContentLength(storage_get_stream.content_length as u64);
245255

246-
let component_path = ComponentPath::TODO();
247256
let call_tracker = usage_tracker.track_storage_call(
248257
component_path.clone(),
249258
"get range",

crates/isolate/src/client.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use common::{
3030
ComponentDefinitionPath,
3131
ComponentId,
3232
ComponentName,
33+
ComponentPath,
3334
Resource,
3435
},
3536
errors::{
@@ -336,15 +337,15 @@ pub trait ActionCallbacks: Send + Sync {
336337
identity: Identity,
337338
component: ComponentId,
338339
storage_id: FileStorageId,
339-
) -> anyhow::Result<Option<FileStorageEntry>>;
340+
) -> anyhow::Result<Option<(ComponentPath, FileStorageEntry)>>;
340341

341342
// Used to store an already uploaded file from an action running in v8.
342343
async fn storage_store_file_entry(
343344
&self,
344345
identity: Identity,
345346
component: ComponentId,
346347
entry: FileStorageEntry,
347-
) -> anyhow::Result<DeveloperDocumentId>;
348+
) -> anyhow::Result<(ComponentPath, DeveloperDocumentId)>;
348349

349350
// Scheduler
350351
async fn schedule_job(
@@ -1831,10 +1832,10 @@ impl<RT: Runtime> IsolateWorker<RT> for BackendIsolateWorker<RT> {
18311832
} => {
18321833
drop(queue_timer);
18331834
let timer = metrics::service_request_timer(&UdfType::Action);
1834-
let component_path = request.params.path_and_args.path().component;
1835+
let component_id = request.params.path_and_args.path().component;
18351836
let environment = ActionEnvironment::new(
18361837
self.rt.clone(),
1837-
component_path,
1838+
component_id,
18381839
environment_data,
18391840
request.identity,
18401841
request.transaction,

crates/isolate/src/environment/action/async_syscall.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ use model::{
2121
auth::propagate_component_auth,
2222
handles::function_handle_not_found,
2323
},
24-
file_storage::{
25-
types::FileStorageEntry,
26-
FileStorageId,
27-
},
24+
file_storage::FileStorageId,
2825
};
2926
use serde::{
3027
Deserialize,
@@ -397,23 +394,16 @@ impl<RT: Runtime> TaskExecutor<RT> {
397394
.action_callbacks
398395
.storage_get_file_entry(self.identity.clone(), self.component_id(), storage_id)
399396
.await?
400-
.map(
401-
|FileStorageEntry {
402-
storage_id,
403-
storage_key: _, // internal field that we shouldn't return in syscalls
404-
sha256,
405-
size,
406-
content_type,
407-
}| {
408-
FileMetadataJson {
409-
storage_id: storage_id.to_string(),
410-
// TODO(CX-5533) use base64 for consistency.
411-
sha256: sha256.as_hex(),
412-
size,
413-
content_type,
414-
}
415-
},
416-
);
397+
.map(|(_, entry)| {
398+
// NB: `storage_key is an internal field that we shouldn't return in syscalls.
399+
FileMetadataJson {
400+
storage_id: entry.storage_id.to_string(),
401+
// TODO(CX-5533) use base64 for consistency.
402+
sha256: entry.sha256.as_hex(),
403+
size: entry.size,
404+
content_type: entry.content_type,
405+
}
406+
});
417407
Ok(serde_json::to_value(file_metadata)?)
418408
}
419409

crates/isolate/src/environment/action/storage.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::str::FromStr;
22

33
use anyhow::Context;
44
use common::{
5-
components::ComponentPath,
65
runtime::Runtime,
76
sha256::{
87
DigestHeader,
@@ -80,12 +79,11 @@ impl<RT: Runtime> TaskExecutor<RT> {
8079
let storage_id = entry.storage_id.clone();
8180
let size = entry.size;
8281
let sha256 = entry.sha256.clone();
83-
let storage_doc_id = self
82+
let (component_path, storage_doc_id) = self
8483
.action_callbacks
8584
.storage_store_file_entry(self.identity.clone(), self.component_id(), entry)
8685
.await?;
8786

88-
let component_path = ComponentPath::TODO();
8987
self.usage_tracker
9088
.track_storage_call(
9189
component_path.clone(),
@@ -147,14 +145,13 @@ impl<RT: Runtime> TaskExecutor<RT> {
147145
.action_callbacks
148146
.storage_get_file_entry(self.identity.clone(), self.component_id(), storage_id)
149147
.await?;
150-
let file_entry = match file_entry {
148+
let (component_path, file_entry) = match file_entry {
151149
None => return Ok(None),
152150
Some(f) => f,
153151
};
154-
155152
let file_stream = self
156153
.file_storage
157-
.get_file_stream(file_entry, self.usage_tracker.clone())
154+
.get_file_stream(component_path, file_entry, self.usage_tracker.clone())
158155
.await?;
159156

160157
let stream = file_stream.stream.map_err(|e| e.into()).boxed();

crates/isolate/src/isolate2/entered_context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ impl<'enter, 'scope: 'enter> EnteredContext<'enter, 'scope> {
323323
self.execute_user_code(|s| s.perform_microtask_checkpoint())?;
324324

325325
let path = ResolvedComponentFunctionPath {
326-
component: ComponentId::TODO(),
326+
component: ComponentId::Root,
327327
udf_path: udf_path.clone(),
328-
component_path: Some(ComponentPath::TODO()),
328+
component_path: Some(ComponentPath::root()),
329329
};
330330
let evaluate_result = self.check_promise_result(&path, &promise)?;
331331
Ok((v8::Global::new(self.scope, promise), evaluate_result))
@@ -431,9 +431,9 @@ impl<'enter, 'scope: 'enter> EnteredContext<'enter, 'scope> {
431431

432432
let promise = v8::Local::new(self.scope, &pending_function.promise);
433433
let path = ResolvedComponentFunctionPath {
434-
component: ComponentId::TODO(),
434+
component: ComponentId::Root,
435435
udf_path: pending_function.udf_path.clone(),
436-
component_path: Some(ComponentPath::TODO()),
436+
component_path: Some(ComponentPath::root()),
437437
};
438438
self.check_promise_result(&path, &promise)
439439
}

0 commit comments

Comments
 (0)