Skip to content

Commit 2693de9

Browse files
ldanilekConvex, Inc.
authored and
Convex, Inc.
committed
refactor ResolvedDocumentId to not use references (#25374)
using references with types that implement `Copy` makes the types annoying, and you have to dereference all over the place. this allows us to later change methods like `ResolvedDocument::id` to construct a new id from its constituent parts, without changing the callers. also replace DocumentIdV6 with the equivalent DeveloperDocumentId. GitOrigin-RevId: fae8397cb5660ea40aa7b7805ad8c9fd67ca41c5
1 parent 91061e6 commit 2693de9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+426
-393
lines changed

crates/application/src/application_function_runner/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ use usage_tracking::{
165165
};
166166
use value::{
167167
heap_size::HeapSize,
168-
id_v6::DocumentIdV6,
168+
id_v6::DeveloperDocumentId,
169169
};
170170
use vector::{
171171
PublicVectorSearchQueryResult,
@@ -1979,7 +1979,7 @@ impl<RT: Runtime> ActionCallbacks for ApplicationFunctionRunner<RT> {
19791979
&self,
19801980
identity: Identity,
19811981
entry: FileStorageEntry,
1982-
) -> anyhow::Result<DocumentIdV6> {
1982+
) -> anyhow::Result<DeveloperDocumentId> {
19831983
let mut tx = self.database.begin(identity).await?;
19841984
let id = self.file_storage.store_file_entry(&mut tx, entry).await?;
19851985
self.database
@@ -2010,7 +2010,7 @@ impl<RT: Runtime> ActionCallbacks for ApplicationFunctionRunner<RT> {
20102010
udf_args: Vec<JsonValue>,
20112011
scheduled_ts: UnixTimestamp,
20122012
context: ExecutionContext,
2013-
) -> anyhow::Result<DocumentIdV6> {
2013+
) -> anyhow::Result<DeveloperDocumentId> {
20142014
let mut tx = self.database.begin(identity).await?;
20152015
let (udf_path, udf_args) = validate_schedule_args(
20162016
udf_path,
@@ -2034,7 +2034,11 @@ impl<RT: Runtime> ActionCallbacks for ApplicationFunctionRunner<RT> {
20342034
Ok(virtual_id)
20352035
}
20362036

2037-
async fn cancel_job(&self, identity: Identity, virtual_id: DocumentIdV6) -> anyhow::Result<()> {
2037+
async fn cancel_job(
2038+
&self,
2039+
identity: Identity,
2040+
virtual_id: DeveloperDocumentId,
2041+
) -> anyhow::Result<()> {
20382042
let mut tx = self.database.begin(identity).await?;
20392043
VirtualSchedulerModel::new(&mut tx)
20402044
.cancel(virtual_id)

crates/application/src/export_worker.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ use usage_tracking::{
115115
};
116116
use value::{
117117
export::ValueFormat,
118-
id_v6::DocumentIdV6,
118+
id_v6::DeveloperDocumentId,
119119
TableId,
120120
TableNumber,
121121
VirtualTableMapping,
@@ -502,8 +502,10 @@ impl<RT: Runtime> ExportWorker<RT> {
502502
pin_mut!(stream);
503503
while let Some((doc, _ts)) = stream.try_next().await? {
504504
let file_storage_entry = ParsedDocument::<FileStorageEntry>::try_from(doc)?;
505-
let virtual_storage_id =
506-
DocumentIdV6::new(virtual_table_id, file_storage_entry.id().internal_id());
505+
let virtual_storage_id = DeveloperDocumentId::new(
506+
virtual_table_id,
507+
file_storage_entry.id().internal_id(),
508+
);
507509
let creation_time = f64::from(
508510
file_storage_entry
509511
.creation_time()
@@ -528,8 +530,10 @@ impl<RT: Runtime> ExportWorker<RT> {
528530
pin_mut!(stream);
529531
while let Some((doc, _ts)) = stream.try_next().await? {
530532
let file_storage_entry = ParsedDocument::<FileStorageEntry>::try_from(doc)?;
531-
let virtual_storage_id =
532-
DocumentIdV6::new(virtual_table_id, file_storage_entry.id().internal_id());
533+
let virtual_storage_id = DeveloperDocumentId::new(
534+
virtual_table_id,
535+
file_storage_entry.id().internal_id(),
536+
);
533537
// Add an extension, which isn't necessary for anything and might be incorrect,
534538
// but allows the file to be viewed at a glance in most cases.
535539
let extension_guess = file_storage_entry
@@ -550,7 +554,7 @@ impl<RT: Runtime> ExportWorker<RT> {
550554
.with_context(|| {
551555
format!(
552556
"file missing from storage: {} with key {:?}",
553-
file_storage_entry.id_v6().encode(),
557+
file_storage_entry.developer_id().encode(),
554558
file_storage_entry.storage_key,
555559
)
556560
})?;
@@ -581,7 +585,7 @@ impl<RT: Runtime> ExportWorker<RT> {
581585
);
582586
pin_mut!(stream);
583587
while let Some((doc, _ts)) = stream.try_next().await? {
584-
generated_schema.insert(doc.value(), doc.id_v6());
588+
generated_schema.insert(doc.value(), doc.developer_id());
585589
}
586590
}
587591

@@ -985,7 +989,7 @@ mod tests {
985989
};
986990
let doc = UserFacingModel::new(&mut tx).get(id, None).await?.unwrap();
987991
let doc = doc.to_resolved(&tx.table_mapping().inject_table_id())?;
988-
let id_v6 = doc.id_v6().encode();
992+
let id_v6 = doc.developer_id().encode();
989993
expected_export_entries.insert(
990994
format!("table_{i}/documents.jsonl"),
991995
format!(

crates/application/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ use usage_tracking::{
248248
UsageCounter,
249249
};
250250
use value::{
251-
id_v6::DocumentIdV6,
251+
id_v6::DeveloperDocumentId,
252252
sha256::Sha256Digest,
253253
ConvexValue,
254254
Namespace,
@@ -681,7 +681,7 @@ impl<RT: Runtime> Application<RT> {
681681
&self,
682682
identity: Identity,
683683
snapshot: Option<Timestamp>,
684-
cursor: Option<DocumentIdV6>,
684+
cursor: Option<DeveloperDocumentId>,
685685
table_filter: Option<TableName>,
686686
) -> anyhow::Result<SnapshotPage> {
687687
self.database
@@ -1681,7 +1681,7 @@ impl<RT: Runtime> Application<RT> {
16811681
mode: ImportMode,
16821682
upload_token: ClientDrivenUploadToken,
16831683
part_tokens: Vec<ClientDrivenUploadPartToken>,
1684-
) -> anyhow::Result<DocumentIdV6> {
1684+
) -> anyhow::Result<DeveloperDocumentId> {
16851685
if !identity.is_admin() {
16861686
anyhow::bail!(ErrorMetadata::forbidden(
16871687
"InvalidImport",
@@ -2012,7 +2012,7 @@ impl<RT: Runtime> Application<RT> {
20122012
content_type: Option<ContentType>,
20132013
expected_sha256: Option<Sha256Digest>,
20142014
body: impl Stream<Item = anyhow::Result<Bytes>> + Send,
2015-
) -> anyhow::Result<DocumentIdV6> {
2015+
) -> anyhow::Result<DeveloperDocumentId> {
20162016
let storage_id = self
20172017
.file_storage
20182018
.store_file(

crates/application/src/snapshot_import.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ use usage_tracking::{
149149
UsageCounter,
150150
};
151151
use value::{
152-
id_v6::DocumentIdV6,
152+
id_v6::DeveloperDocumentId,
153153
sha256::Sha256Digest,
154154
val,
155155
ConvexObject,
@@ -776,7 +776,7 @@ enum ImportUnit {
776776
Object(JsonValue),
777777
NewTable(TableName),
778778
GeneratedSchema(TableName, GeneratedSchema<ProdConfigWithOptionalFields>),
779-
StorageFileChunk(DocumentIdV6, Bytes),
779+
StorageFileChunk(DeveloperDocumentId, Bytes),
780780
}
781781

782782
static GENERATED_SCHEMA_PATTERN: LazyLock<Regex> =
@@ -949,12 +949,13 @@ where
949949
continue;
950950
}
951951
let entry_reader = zip_reader.entry_reader(i).await?;
952-
let storage_id = DocumentIdV6::decode(storage_id_str).map_err(|e| {
953-
ErrorMetadata::bad_request(
954-
"InvalidStorageId",
955-
format!("_storage id '{storage_id_str}' invalid: {e}"),
956-
)
957-
})?;
952+
let storage_id =
953+
DeveloperDocumentId::decode(storage_id_str).map_err(|e| {
954+
ErrorMetadata::bad_request(
955+
"InvalidStorageId",
956+
format!("_storage id '{storage_id_str}' invalid: {e}"),
957+
)
958+
})?;
958959
tracing::info!(
959960
"importing zip file containing storage file {}",
960961
storage_id.encode()
@@ -1079,7 +1080,7 @@ async fn parse_generated_schema<'a, T: ShapeConfig, R: AsyncRead + Unpin>(
10791080
let export_context = ExportContext::try_from(value.clone())
10801081
.map_err(|e| ImportError::InvalidConvexValue(lineno, e))?;
10811082
overrides.insert(
1082-
DocumentIdV6::decode(key)
1083+
DeveloperDocumentId::decode(key)
10831084
.map_err(|e| ImportError::InvalidConvexValue(lineno, e.into()))?,
10841085
export_context,
10851086
);
@@ -1108,7 +1109,7 @@ pub async fn upload_import_file<RT: Runtime>(
11081109
format: ImportFormat,
11091110
mode: ImportMode,
11101111
body_stream: BoxStream<'_, anyhow::Result<Bytes>>,
1111-
) -> anyhow::Result<DocumentIdV6> {
1112+
) -> anyhow::Result<DeveloperDocumentId> {
11121113
if !identity.is_admin() {
11131114
anyhow::bail!(ImportError::Unauthorized);
11141115
}
@@ -1122,7 +1123,7 @@ pub async fn store_uploaded_import<RT: Runtime>(
11221123
format: ImportFormat,
11231124
mode: ImportMode,
11241125
object_key: ObjectKey,
1125-
) -> anyhow::Result<DocumentIdV6> {
1126+
) -> anyhow::Result<DeveloperDocumentId> {
11261127
let (_, id, _) = application
11271128
.database
11281129
.execute_with_overloaded_retries(
@@ -1147,7 +1148,7 @@ pub async fn store_uploaded_import<RT: Runtime>(
11471148
pub async fn perform_import<RT: Runtime>(
11481149
application: &Application<RT>,
11491150
identity: Identity,
1150-
import_id: DocumentIdV6,
1151+
import_id: DeveloperDocumentId,
11511152
) -> anyhow::Result<()> {
11521153
if !identity.is_admin() {
11531154
anyhow::bail!(ImportError::Unauthorized);
@@ -1186,7 +1187,7 @@ fn wrap_import_err(e: anyhow::Error) -> anyhow::Error {
11861187
async fn wait_for_import_worker<RT: Runtime>(
11871188
application: &Application<RT>,
11881189
identity: Identity,
1189-
import_id: DocumentIdV6,
1190+
import_id: DeveloperDocumentId,
11901191
) -> anyhow::Result<ParsedDocument<SnapshotImport>> {
11911192
let snapshot_import = loop {
11921193
let mut tx = application.begin(identity.clone()).await?;
@@ -1669,7 +1670,7 @@ async fn import_storage_table<RT: Runtime>(
16691670
lineno += 1;
16701671
let metadata: FileStorageZipMetadata = serde_json::from_value(exported_value)
16711672
.map_err(|e| ImportError::InvalidConvexValue(lineno, e.into()))?;
1672-
let id = DocumentIdV6::decode(&metadata.id)
1673+
let id = DeveloperDocumentId::decode(&metadata.id)
16731674
.map_err(|e| ImportError::InvalidConvexValue(lineno, e.into()))?;
16741675
anyhow::ensure!(
16751676
*id.table() == virtual_table_number,
@@ -2206,7 +2207,7 @@ async fn table_number_for_import(
22062207
let JsonValue::String(id) = first_id else {
22072208
return None;
22082209
};
2209-
let id_v6 = DocumentIdV6::decode(id).ok()?;
2210+
let id_v6 = DeveloperDocumentId::decode(id).ok()?;
22102211
Some(*id_v6.table())
22112212
},
22122213
ImportUnit::NewTable(_) => None,
@@ -2351,7 +2352,7 @@ mod tests {
23512352
use value::{
23522353
assert_obj,
23532354
assert_val,
2354-
id_v6::DocumentIdV6,
2355+
id_v6::DeveloperDocumentId,
23552356
ConvexObject,
23562357
FieldName,
23572358
TableName,
@@ -2987,7 +2988,7 @@ a
29872988
let identity = new_admin_id();
29882989

29892990
let storage_id = "kg21pzwemsm55e1fnt2kcsvgjh6h6gtf";
2990-
let storage_idv6 = DocumentIdV6::decode(storage_id)?;
2991+
let storage_idv6 = DeveloperDocumentId::decode(storage_id)?;
29912992

29922993
let objects = stream::iter(vec![
29932994
Ok(ImportUnit::NewTable("_storage".parse()?)),

crates/common/src/bootstrap_model/schema.rs

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

33
use errors::ErrorMetadata;
44
use value::{
5-
id_v6::DocumentIdV6,
5+
id_v6::DeveloperDocumentId,
66
GenericDocumentId,
77
ResolvedDocumentId,
88
TableId,
@@ -23,7 +23,7 @@ pub fn parse_schema_id(
2323
Ok(s) => s.map_table(table_mapping.inject_table_number()),
2424
Err(_) => {
2525
// Try parsing as an IDv6 ID
26-
let id = DocumentIdV6::decode(schema_id)?;
26+
let id = DeveloperDocumentId::decode(schema_id)?;
2727
id.to_resolved(&table_mapping.inject_table_id())
2828
},
2929
}

0 commit comments

Comments
 (0)