Skip to content

Commit 9064bf6

Browse files
goffrieConvex, Inc.
authored andcommitted
Use CreateFunctionHandle callback in actions (#36362)
GitOrigin-RevId: 71dadabdf60a1bc8ae06f2be4b761cf70504a71d
1 parent d48d85e commit 9064bf6

File tree

5 files changed

+6
-58
lines changed

5 files changed

+6
-58
lines changed

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ use errors::{
1717
ErrorMetadataAnyhowExt,
1818
};
1919
use model::{
20-
components::{
21-
auth::propagate_component_auth,
22-
handles::function_handle_not_found,
23-
},
20+
components::auth::propagate_component_auth,
2421
file_storage::FileStorageId,
2522
};
2623
use serde::{
@@ -462,15 +459,10 @@ impl<RT: Runtime> TaskExecutor<RT> {
462459
self.resolve_function(&reference)?
463460
},
464461
};
465-
// TODO(lee) remove preloaded function handles and call action callback instead,
466-
// after the callback is deployed to backend & usher.
467-
let handle = {
468-
let function_handles = self.function_handles.lock();
469-
function_handles.get(&function_path).cloned()
470-
};
471-
let Some(handle) = handle else {
472-
anyhow::bail!(function_handle_not_found());
473-
};
462+
let handle = self
463+
.action_callbacks
464+
.create_function_handle(self.identity.clone(), function_path)
465+
.await?;
474466
Ok(serde_json::to_value(String::from(handle))?)
475467
}
476468
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ impl<RT: Runtime> ActionEnvironment<RT> {
259259
let syscall_trace = Arc::new(Mutex::new(SyscallTrace::new()));
260260
let (task_retval_sender, task_responses) = mpsc::unbounded_channel();
261261
let resources = Arc::new(Mutex::new(BTreeMap::new()));
262-
let function_handles = Arc::new(Mutex::new(BTreeMap::new()));
263262
let convex_origin_override = Arc::new(Mutex::new(None));
264263
let task_executor = TaskExecutor {
265264
rt: rt.clone(),
@@ -276,7 +275,6 @@ impl<RT: Runtime> ActionEnvironment<RT> {
276275
context,
277276
resources: resources.clone(),
278277
component_id: component,
279-
function_handles: function_handles.clone(),
280278
convex_origin_override: convex_origin_override.clone(),
281279
};
282280
let (pending_task_sender, pending_task_receiver) = spsc::unbounded_channel();
@@ -300,7 +298,6 @@ impl<RT: Runtime> ActionEnvironment<RT> {
300298
module_loader,
301299
default_system_env_vars,
302300
resources,
303-
function_handles,
304301
convex_origin_override,
305302
),
306303
syscall_trace,

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use std::{
66

77
use anyhow::Context;
88
use common::{
9-
bootstrap_model::components::handles::FunctionHandle,
109
components::{
11-
CanonicalizedComponentFunctionPath,
1210
ComponentId,
1311
Reference,
1412
Resource,
@@ -30,10 +28,7 @@ use database::{
3028
use errors::ErrorMetadata;
3129
use model::{
3230
canonical_urls::CanonicalUrlsModel,
33-
components::{
34-
handles::FunctionHandlesModel,
35-
ComponentsModel,
36-
},
31+
components::ComponentsModel,
3732
config::module_loader::ModuleLoader,
3833
environment_variables::{
3934
types::{
@@ -98,7 +93,6 @@ enum ActionPreloaded<RT: Runtime> {
9893
module_loader: Arc<dyn ModuleLoader<RT>>,
9994
default_system_env_vars: BTreeMap<EnvVarName, EnvVarValue>,
10095
resources: Arc<Mutex<BTreeMap<Reference, Resource>>>,
101-
function_handles: Arc<Mutex<BTreeMap<CanonicalizedComponentFunctionPath, FunctionHandle>>>,
10296
convex_origin_override: Arc<Mutex<Option<ConvexOrigin>>>,
10397
},
10498
Preloading,
@@ -119,7 +113,6 @@ impl<RT: Runtime> ActionPhase<RT> {
119113
module_loader: Arc<dyn ModuleLoader<RT>>,
120114
default_system_env_vars: BTreeMap<EnvVarName, EnvVarValue>,
121115
resources: Arc<Mutex<BTreeMap<Reference, Resource>>>,
122-
function_handles: Arc<Mutex<BTreeMap<CanonicalizedComponentFunctionPath, FunctionHandle>>>,
123116
convex_origin_override: Arc<Mutex<Option<ConvexOrigin>>>,
124117
) -> Self {
125118
Self {
@@ -131,7 +124,6 @@ impl<RT: Runtime> ActionPhase<RT> {
131124
module_loader,
132125
default_system_env_vars,
133126
resources,
134-
function_handles,
135127
convex_origin_override,
136128
},
137129
}
@@ -151,7 +143,6 @@ impl<RT: Runtime> ActionPhase<RT> {
151143
module_loader,
152144
default_system_env_vars,
153145
resources,
154-
function_handles,
155146
convex_origin_override,
156147
} = preloaded
157148
else {
@@ -247,16 +238,6 @@ impl<RT: Runtime> ActionPhase<RT> {
247238
)
248239
};
249240

250-
{
251-
let handles = with_release_permit(
252-
timeout,
253-
permit_slot,
254-
FunctionHandlesModel::new(&mut tx).preload(),
255-
)
256-
.await?;
257-
*function_handles.lock() = handles;
258-
}
259-
260241
self.preloaded = ActionPreloaded::Ready {
261242
modules,
262243
env_vars,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::{
55
};
66

77
use common::{
8-
bootstrap_model::components::handles::FunctionHandle,
98
components::{
109
CanonicalizedComponentFunctionPath,
1110
ComponentId,
@@ -80,7 +79,6 @@ pub struct TaskExecutor<RT: Runtime> {
8079
pub context: ExecutionContext,
8180
pub resources: Arc<Mutex<BTreeMap<Reference, Resource>>>,
8281
pub component_id: ComponentId,
83-
pub function_handles: Arc<Mutex<BTreeMap<CanonicalizedComponentFunctionPath, FunctionHandle>>>,
8482
pub convex_origin_override: Arc<Mutex<Option<ConvexOrigin>>>,
8583
}
8684

crates/model/src/components/handles.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,26 +128,6 @@ impl<'a, RT: Runtime> FunctionHandlesModel<'a, RT> {
128128
})
129129
}
130130

131-
pub async fn preload(
132-
&mut self,
133-
) -> anyhow::Result<BTreeMap<CanonicalizedComponentFunctionPath, FunctionHandle>> {
134-
let mut handles = BTreeMap::new();
135-
let index_query = Query::full_table_scan(FUNCTION_HANDLES_TABLE.clone(), Order::Asc);
136-
let mut query_stream = ResolvedQuery::new(self.tx, TableNamespace::Global, index_query)?;
137-
while let Some(doc) = query_stream.next(self.tx, None).await? {
138-
let handle: ParsedDocument<FunctionHandleMetadata> = doc.parse()?;
139-
if handle.deleted_ts.is_none() {
140-
let path = CanonicalizedComponentFunctionPath {
141-
component: BootstrapComponentsModel::new(self.tx)
142-
.must_component_path(handle.component)?,
143-
udf_path: handle.path.clone(),
144-
};
145-
handles.insert(path, FunctionHandle::new(handle.developer_id()));
146-
}
147-
}
148-
Ok(handles)
149-
}
150-
151131
pub async fn get_with_component_path(
152132
&mut self,
153133
path: CanonicalizedComponentFunctionPath,

0 commit comments

Comments
 (0)