Skip to content

Commit 93c1e6f

Browse files
ldanilekConvex, Inc.
authored andcommitted
[components] fix TODOs related to source packages (#26994)
enable looking up source packages and udf config within components GitOrigin-RevId: acdb963dbdd7963de0f2f9d26bc359f16d1a3cc0
1 parent 576f108 commit 93c1e6f

File tree

15 files changed

+182
-118
lines changed

15 files changed

+182
-118
lines changed

crates/application/src/application_function_runner/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ use usage_tracking::{
187187
use value::{
188188
heap_size::HeapSize,
189189
id_v6::DeveloperDocumentId,
190-
TableNamespace,
191190
};
192191
use vector::{
193192
PublicVectorSearchQueryResult,
@@ -1019,10 +1018,11 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
10191018
FunctionOutcome::Mutation(o) => o,
10201019
_ => anyhow::bail!("Received non-mutation outcome for mutation"),
10211020
};
1021+
let (_, component) = BootstrapComponentsModel::new(&mut tx)
1022+
.component_path_to_ids(path.component.clone())
1023+
.await?;
10221024

1023-
let table_mapping = tx
1024-
.table_mapping()
1025-
.namespace(TableNamespace::by_component_TODO());
1025+
let table_mapping = tx.table_mapping().namespace(component.into());
10261026
let virtual_table_mapping = tx.virtual_table_mapping().clone();
10271027

10281028
let outcome = ValidatedUdfOutcome::new(
@@ -1162,6 +1162,9 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
11621162
UdfType::Action,
11631163
)
11641164
.await?;
1165+
let (_, component) = BootstrapComponentsModel::new(&mut tx)
1166+
.component_path_to_ids(path.component.clone())
1167+
.await?;
11651168

11661169
// Fetch the returns_validator now to be used at a later ts.
11671170
let (path_and_args, returns_validator) = match validate_result {
@@ -1189,9 +1192,7 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
11891192

11901193
// We should use table mappings from the same transaction as the output
11911194
// validator was retrieved.
1192-
let table_mapping = tx
1193-
.table_mapping()
1194-
.namespace(TableNamespace::by_component_TODO());
1195+
let table_mapping = tx.table_mapping().namespace(component.into());
11951196
let virtual_table_mapping = tx.virtual_table_mapping().clone();
11961197
let udf_server_version = path_and_args.npm_version().clone();
11971198
// We should not be missing the module given we validated the path above
@@ -1273,11 +1274,10 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
12731274
}
12741275

12751276
let source_package_id = module.source_package_id;
1276-
let source_package =
1277-
SourcePackageModel::new(&mut tx, TableNamespace::by_component_TODO())
1278-
.get(source_package_id)
1279-
.await?
1280-
.into_value();
1277+
let source_package = SourcePackageModel::new(&mut tx, component.into())
1278+
.get(source_package_id)
1279+
.await?
1280+
.into_value();
12811281
let mut environment_variables =
12821282
EnvironmentVariablesModel::new(&mut tx).get_all().await?;
12831283
// Insert special environment variables if not already provided by user

crates/application/src/cache/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use common::{
4141
RequestId,
4242
};
4343
use database::{
44+
BootstrapComponentsModel,
4445
Database,
4546
Token,
4647
};
@@ -80,7 +81,6 @@ use usage_tracking::FunctionUsageTracker;
8081
use value::{
8182
heap_size::HeapSize,
8283
ConvexValue,
83-
TableNamespace,
8484
};
8585

8686
use crate::{
@@ -471,9 +471,10 @@ impl<RT: Runtime> CacheManager<RT> {
471471
};
472472
if let Ok(ref json_packed_value) = &query_outcome.result {
473473
let output: ConvexValue = json_packed_value.unpack();
474-
let table_mapping = tx
475-
.table_mapping()
476-
.namespace(TableNamespace::by_component_TODO());
474+
let (_, component) = BootstrapComponentsModel::new(&mut tx)
475+
.component_path_to_ids(path.component.clone())
476+
.await?;
477+
let table_mapping = tx.table_mapping().namespace(component.into());
477478
let virtual_table_mapping = tx.virtual_table_mapping().clone();
478479
let returns_validation_error = returns_validator.check_output(
479480
&output,

crates/application/src/tests/source_package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub async fn assemble_package<RT: Runtime>(
6969
modifications: BTreeMap<CanonicalizedModulePath, Option<ModuleConfig>>,
7070
) -> anyhow::Result<Vec<ModuleConfig>> {
7171
let existing_modules = ModuleModel::new(tx)
72-
.get_application_modules(ComponentId::TODO(), module_loader)
72+
.get_application_modules(ComponentId::test_user(), module_loader)
7373
.await?;
7474
let mut modules = BTreeMap::new();
7575
for (path, module) in existing_modules {

crates/common/src/shapes/dashboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ mod tests {
180180
ShapeEnumJson::Id { table_name } => {
181181
let name: TableName = table_name.parse()?;
182182
ReducedShape::Id(all_tables_name_to_number(
183-
TableNamespace::by_component_TODO(),
183+
TableNamespace::test_user(),
184184
mapping,
185185
virtual_mapping,
186186
)(name)?)

crates/database/src/bootstrap_model/schema/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ impl<'a, RT: Runtime> SchemaModel<'a, RT> {
127127
}
128128

129129
pub async fn enforce(&mut self, document: &ResolvedDocument) -> anyhow::Result<()> {
130-
let schema_table_mapping = self
131-
.tx
132-
.table_mapping()
133-
.namespace(TableNamespace::by_component_TODO());
130+
let schema_table_mapping = self.tx.table_mapping().namespace(self.namespace);
134131
self.enforce_with_table_mapping(document, &schema_table_mapping)
135132
.await
136133
}
@@ -249,9 +246,9 @@ impl<'a, RT: Runtime> SchemaModel<'a, RT> {
249246
) -> anyhow::Result<(ResolvedDocumentId, SchemaState)> {
250247
let mut table_model = TableModel::new(self.tx);
251248
for name in schema.tables.keys() {
252-
if !table_model.table_exists(TableNamespace::by_component_TODO(), name) {
249+
if !table_model.table_exists(self.namespace, name) {
253250
table_model
254-
.insert_table_metadata(TableNamespace::by_component_TODO(), name)
251+
.insert_table_metadata(self.namespace, name)
255252
.await?;
256253
}
257254
}

crates/database/src/query/search_query.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,18 @@ impl SearchQuery {
9797
.into_iter()
9898
.filter(|(_, index_key)| self.cursor_interval.contains(index_key))
9999
.collect();
100+
let namespace = match self.stable_index_name.tablet_index_name() {
101+
Some(index_name) => tx.table_mapping().tablet_namespace(*index_name.table())?,
102+
None => TableNamespace::Global,
103+
};
100104
let table_number = tx
101105
.table_mapping()
102-
.namespace(TableNamespace::by_component_TODO())
106+
.namespace(namespace)
103107
.id(&self.query.table)?
104108
.table_number;
105109
Ok(SearchResultIterator::new(
106110
revisions_in_range,
111+
namespace,
107112
table_number,
108113
self.version.clone(),
109114
))
@@ -178,6 +183,7 @@ impl QueryStream for SearchQuery {
178183

179184
#[derive(Clone)]
180185
struct SearchResultIterator {
186+
namespace: TableNamespace,
181187
table_number: TableNumber,
182188
candidates: Vec<(CandidateRevision, IndexKeyBytes)>,
183189
next_index: usize,
@@ -188,10 +194,12 @@ struct SearchResultIterator {
188194
impl SearchResultIterator {
189195
fn new(
190196
candidates: Vec<(CandidateRevision, IndexKeyBytes)>,
197+
namespace: TableNamespace,
191198
table_number: TableNumber,
192199
version: Option<Version>,
193200
) -> Self {
194201
Self {
202+
namespace,
195203
table_number,
196204
candidates,
197205
next_index: 0,
@@ -232,13 +240,12 @@ impl SearchResultIterator {
232240
self.next_index += 1;
233241

234242
let id = self.table_number.id(candidate.id);
235-
let (document, existing_doc_ts) =
236-
UserFacingModel::new(tx, TableNamespace::by_component_TODO())
237-
.get_with_ts(id, self.version.clone())
238-
.await?
239-
.ok_or_else(|| {
240-
anyhow::anyhow!("Unable to load search result {id}@{:?}", candidate.ts)
241-
})?;
243+
let (document, existing_doc_ts) = UserFacingModel::new(tx, self.namespace)
244+
.get_with_ts(id, self.version.clone())
245+
.await?
246+
.ok_or_else(|| {
247+
anyhow::anyhow!("Unable to load search result {id}@{:?}", candidate.ts)
248+
})?;
242249

243250
self.bytes_read += document.size();
244251

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ use std::{
44
sync::Arc,
55
};
66

7-
use anyhow::Context;
87
use common::{
98
components::{
10-
ComponentDefinitionId,
119
ComponentId,
1210
ComponentPath,
1311
Reference,
@@ -52,7 +50,6 @@ use sync_types::{
5250
CanonicalizedModulePath,
5351
ModulePath,
5452
};
55-
use value::TableNamespace;
5653

5754
use crate::{
5855
concurrency_limiter::ConcurrencyPermit,
@@ -137,10 +134,18 @@ impl<RT: Runtime> ActionPhase<RT> {
137134
anyhow::bail!("ActionPhase initialized twice");
138135
};
139136

137+
let component_id = with_release_permit(timeout, permit_slot, async {
138+
let (_, component) = BootstrapComponentsModel::new(&mut tx)
139+
.component_path_to_ids(self.component.clone())
140+
.await?;
141+
anyhow::Ok(component)
142+
})
143+
.await?;
144+
140145
let udf_config = with_release_permit(
141146
timeout,
142147
permit_slot,
143-
UdfConfigModel::new(&mut tx, TableNamespace::TODO()).get(),
148+
UdfConfigModel::new(&mut tx, component_id.into()).get(),
144149
)
145150
.await?;
146151

@@ -156,18 +161,6 @@ impl<RT: Runtime> ActionPhase<RT> {
156161
.get_all_metadata(ComponentId::Root)
157162
.await?
158163
} else {
159-
let metadata = BootstrapComponentsModel::new(&mut tx)
160-
.resolve_path(self.component.clone())
161-
.await?
162-
.context("Failed to find component")?;
163-
let (component_id, _) = if self.component.is_root() {
164-
(ComponentId::Root, ComponentDefinitionId::Root)
165-
} else {
166-
(
167-
ComponentId::Child(metadata.id().internal_id()),
168-
ComponentDefinitionId::Child(metadata.definition_id),
169-
)
170-
};
171164
let module_metadata = ModuleModel::new(&mut tx)
172165
.get_all_metadata(component_id)
173166
.await?;

crates/isolate/src/environment/helpers/validation.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use common::{
33
components::{
44
CanonicalizedComponentFunctionPath,
55
ComponentFunctionPath,
6+
ComponentId,
67
ComponentPath,
78
},
89
errors::JsError,
@@ -24,6 +25,7 @@ use common::{
2425
};
2526
use database::{
2627
unauthorized_error,
28+
BootstrapComponentsModel,
2729
Transaction,
2830
};
2931
use errors::ErrorMetadata;
@@ -56,7 +58,6 @@ use value::{
5658
ConvexArray,
5759
ConvexValue,
5860
NamespacedTableMapping,
59-
TableNamespace,
6061
VirtualTableMapping,
6162
};
6263

@@ -146,11 +147,10 @@ fn missing_or_internal_error(path: &CanonicalizedComponentFunctionPath) -> anyho
146147

147148
async fn udf_version<RT: Runtime>(
148149
path: &CanonicalizedComponentFunctionPath,
150+
component: ComponentId,
149151
tx: &mut Transaction<RT>,
150152
) -> anyhow::Result<Result<Version, JsError>> {
151-
let udf_config = UdfConfigModel::new(tx, TableNamespace::TODO())
152-
.get()
153-
.await?;
153+
let udf_config = UdfConfigModel::new(tx, component.into()).get().await?;
154154

155155
let udf_version = match udf_config {
156156
Some(udf_config) if udf_config.server_version > DEPRECATION_THRESHOLD.npm.unsupported => {
@@ -259,6 +259,10 @@ impl ValidatedPathAndArgs {
259259
return Ok(result);
260260
}
261261

262+
let (_, component) = BootstrapComponentsModel::new(tx)
263+
.component_path_to_ids(path.component.clone())
264+
.await?;
265+
262266
let mut backend_state_model = BackendStateModel::new(tx);
263267
let backend_state = backend_state_model.get_backend_state().await?;
264268
match backend_state {
@@ -273,7 +277,7 @@ impl ValidatedPathAndArgs {
273277
},
274278
}
275279

276-
let udf_version = match udf_version(&path, tx).await? {
280+
let udf_version = match udf_version(&path, component, tx).await? {
277281
Ok(udf_version) => udf_version,
278282
Err(e) => return Ok(Err(e)),
279283
};
@@ -289,6 +293,7 @@ impl ValidatedPathAndArgs {
289293
allowed_visibility,
290294
tx,
291295
path,
296+
component,
292297
args,
293298
expected_udf_type,
294299
analyzed_function,
@@ -338,7 +343,11 @@ impl ValidatedPathAndArgs {
338343
},
339344
}
340345

341-
let udf_version = match udf_version(&path, tx).await? {
346+
let (_, component) = BootstrapComponentsModel::new(tx)
347+
.component_path_to_ids(path.component.clone())
348+
.await?;
349+
350+
let udf_version = match udf_version(&path, component, tx).await? {
342351
Ok(udf_version) => udf_version,
343352
Err(e) => return Ok(Err(e)),
344353
};
@@ -362,6 +371,7 @@ impl ValidatedPathAndArgs {
362371
allowed_visibility,
363372
tx,
364373
path,
374+
component,
365375
args,
366376
expected_udf_type,
367377
analyzed_function,
@@ -378,6 +388,7 @@ impl ValidatedPathAndArgs {
378388
allowed_visibility: AllowedVisibility,
379389
tx: &mut Transaction<RT>,
380390
path: CanonicalizedComponentFunctionPath,
391+
component: ComponentId,
381392
args: ConvexArray,
382393
expected_udf_type: UdfType,
383394
analyzed_function: AnalyzedFunction,
@@ -420,9 +431,7 @@ impl ValidatedPathAndArgs {
420431
Err(err) => return Ok(Err(err)),
421432
}
422433

423-
let table_mapping = &tx
424-
.table_mapping()
425-
.namespace(TableNamespace::by_component_TODO());
434+
let table_mapping = &tx.table_mapping().namespace(component.into());
426435
let virtual_table_mapping = &tx.virtual_table_mapping().clone();
427436

428437
// If the UDF has an args validator, check that these args match.
@@ -565,7 +574,10 @@ impl ValidatedHttpPath {
565574
.fail_while_paused_or_disabled()
566575
.await?;
567576
}
568-
let udf_version = match udf_version(&path, tx).await? {
577+
let (_, component) = BootstrapComponentsModel::new(tx)
578+
.component_path_to_ids(path.component.clone())
579+
.await?;
580+
let udf_version = match udf_version(&path, component, tx).await? {
569581
Ok(udf_version) => udf_version,
570582
Err(e) => return Ok(Err(e)),
571583
};

0 commit comments

Comments
 (0)