Skip to content

Commit 28a64af

Browse files
ldanilekConvex, Inc.
authored and
Convex, Inc.
committed
stop writing to _module_versions (#27059)
We're no longer reading from the `_module_versions` table in prod, so we don't have to write it. <img src="https://media3.giphy.com/media/c6XTJeqP0mMpjEmd94/giphy.gif"/> GitOrigin-RevId: 32bdf169a1ee374f8a5b8b071a6ce5029129f34c
1 parent 86ca391 commit 28a64af

File tree

2 files changed

+4
-113
lines changed

2 files changed

+4
-113
lines changed

crates/model/src/modules/metrics.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,3 @@ register_convex_histogram!(
1212
pub fn get_module_metadata_timer() -> StatusTimer {
1313
StatusTimer::new(&DATABASE_GET_MODULES_METADATA_SECONDS)
1414
}
15-
16-
register_convex_histogram!(
17-
DATABASE_GET_MODULES_VERSION_SECONDS,
18-
"Time to get module versions",
19-
&STATUS_LABEL
20-
);
21-
pub fn get_module_version_timer() -> StatusTimer {
22-
StatusTimer::new(&DATABASE_GET_MODULES_VERSION_SECONDS)
23-
}

crates/model/src/modules/mod.rs

Lines changed: 4 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use common::{
3131
value::{
3232
ConvexValue,
3333
ResolvedDocumentId,
34-
VALUE_TOO_LARGE_SHORT_MSG,
3534
},
3635
};
3736
use database::{
@@ -42,14 +41,8 @@ use database::{
4241
SystemMetadataModel,
4342
Transaction,
4443
};
45-
use errors::{
46-
ErrorMetadata,
47-
ErrorMetadataAnyhowExt,
48-
};
49-
use metrics::{
50-
get_module_metadata_timer,
51-
get_module_version_timer,
52-
};
44+
use errors::ErrorMetadata;
45+
use metrics::get_module_metadata_timer;
5346
use sync_types::CanonicalizedModulePath;
5447
use value::{
5548
sha256::{
@@ -309,39 +302,6 @@ impl<'a, RT: Runtime> ModuleModel<'a, RT> {
309302
Ok(modules)
310303
}
311304

312-
pub async fn get_version(
313-
&mut self,
314-
module_id: ResolvedDocumentId,
315-
version: Option<ModuleVersion>,
316-
) -> anyhow::Result<Option<ParsedDocument<ModuleVersionMetadata>>> {
317-
let timer = get_module_version_timer();
318-
let module_id_value: ConvexValue = module_id.into();
319-
let index_range = IndexRange {
320-
index_name: MODULE_VERSION_INDEX.clone(),
321-
range: vec![IndexRangeExpression::Eq(
322-
MODULE_ID_FIELD.clone(),
323-
module_id_value.into(),
324-
)],
325-
order: Order::Asc,
326-
};
327-
let module_query = Query::index_range(index_range);
328-
let namespace = self
329-
.tx
330-
.table_mapping()
331-
.tablet_namespace(module_id.table().tablet_id)?;
332-
let mut query_stream = ResolvedQuery::new(self.tx, namespace, module_query)?;
333-
let module_version: Option<ParsedDocument<ModuleVersionMetadata>> = query_stream
334-
.expect_at_most_one(self.tx)
335-
.await?
336-
.map(TryFrom::try_from)
337-
.transpose()?;
338-
if let Some(module_version) = &module_version {
339-
anyhow::ensure!(module_version.version == version);
340-
}
341-
timer.finish();
342-
Ok(module_version)
343-
}
344-
345305
pub async fn get_metadata_for_function(
346306
&mut self,
347307
path: CanonicalizedComponentFunctionPath,
@@ -392,13 +352,10 @@ impl<'a, RT: Runtime> ModuleModel<'a, RT> {
392352
path.module_path.is_deps() || analyze_result.is_some(),
393353
"AnalyzedModule is required for non-dependency modules"
394354
);
395-
let component = path.component;
396355
let sha256 = hash_module_source(&source, source_map.as_ref());
397-
let (module_id, version) = self
398-
.put_module_metadata(path, source_package_id, analyze_result, environment, sha256)
356+
self.put_module_metadata(path, source_package_id, analyze_result, environment, sha256)
399357
.await?;
400-
self.put_module_source_into_db(module_id, version, source, source_map, component)
401-
.await
358+
Ok(())
402359
}
403360

404361
async fn put_module_metadata(
@@ -413,12 +370,6 @@ impl<'a, RT: Runtime> ModuleModel<'a, RT> {
413370
Some(module_metadata) => {
414371
let previous_version = module_metadata.latest_version;
415372

416-
// Delete the old module version since it has no more references.
417-
let previous_version_id = self
418-
.get_version(module_metadata.id(), previous_version)
419-
.await?
420-
.map(|version| version.id());
421-
422373
let latest_version = previous_version.map(|v| v + 1);
423374
let new_metadata = ModuleMetadata {
424375
path: path.module_path,
@@ -432,12 +383,6 @@ impl<'a, RT: Runtime> ModuleModel<'a, RT> {
432383
.replace(module_metadata.id(), new_metadata.try_into()?)
433384
.await?;
434385

435-
if let Some(previous_version_id) = previous_version_id {
436-
SystemMetadataModel::new(self.tx, path.component.into())
437-
.delete(previous_version_id)
438-
.await?;
439-
}
440-
441386
(module_metadata.id(), latest_version)
442387
},
443388
None => {
@@ -460,41 +405,6 @@ impl<'a, RT: Runtime> ModuleModel<'a, RT> {
460405
Ok((module_id, version))
461406
}
462407

463-
async fn put_module_source_into_db(
464-
&mut self,
465-
module_id: ResolvedDocumentId,
466-
version: Option<ModuleVersion>,
467-
source: ModuleSource,
468-
source_map: Option<SourceMap>,
469-
component: ComponentId,
470-
) -> anyhow::Result<()> {
471-
let new_version = ModuleVersionMetadata {
472-
module_id: module_id.into(),
473-
source,
474-
source_map,
475-
version,
476-
}.try_into()
477-
.map_err(|e: anyhow::Error| e.map_error_metadata(|em| {
478-
if em.short_msg == VALUE_TOO_LARGE_SHORT_MSG {
479-
// Remap the ValueTooLargeError message to something more specific
480-
// to the modules use case.
481-
let message = format!(
482-
"The functions, source maps, and their dependencies in \"convex/\" are too large. See our docs (https://docs.convex.dev/using/writing-convex-functions#using-libraries) for more details. You can also run `npx convex deploy -v` to print out each source file's bundled size.\n{}", em.msg
483-
);
484-
ErrorMetadata::bad_request(
485-
"ModulesTooLarge",
486-
message,
487-
)
488-
} else {
489-
em
490-
}
491-
}))?;
492-
SystemMetadataModel::new(self.tx, component.into())
493-
.insert(&MODULE_VERSIONS_TABLE, new_version)
494-
.await?;
495-
Ok(())
496-
}
497-
498408
/// Delete a module, making it inaccessible for subsequent transactions.
499409
pub async fn delete(&mut self, path: CanonicalizedComponentModulePath) -> anyhow::Result<()> {
500410
if !(self.tx.identity().is_admin() || self.tx.identity().is_system()) {
@@ -506,16 +416,6 @@ impl<'a, RT: Runtime> ModuleModel<'a, RT> {
506416
SystemMetadataModel::new(self.tx, namespace)
507417
.delete(module_id)
508418
.await?;
509-
510-
// Delete the module version since it has no more references.
511-
if let Some(module_version) = self
512-
.get_version(module_id, module_metadata.latest_version)
513-
.await?
514-
{
515-
SystemMetadataModel::new(self.tx, namespace)
516-
.delete(module_version.id())
517-
.await?;
518-
}
519419
}
520420
Ok(())
521421
}

0 commit comments

Comments
 (0)