Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["codegen", "examples", "performance_measurement", "performance_measur

[package]
name = "worktable"
version = "0.8.20"
version = "0.8.21"
edition = "2024"
authors = ["Handy-caT"]
license = "MIT"
Expand All @@ -16,7 +16,7 @@ perf_measurements = ["dep:performance_measurement", "dep:performance_measurement
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
worktable_codegen = { path = "codegen", version = "=0.8.20" }
worktable_codegen = { path = "codegen", version = "=0.8.21" }

async-trait = "0.1.89"
eyre = "0.6.12"
Expand Down
2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "worktable_codegen"
version = "0.8.20"
version = "0.8.21"
edition = "2024"
license = "MIT"
description = "WorkTable codegeneration crate"
Expand Down
16 changes: 11 additions & 5 deletions codegen/src/worktable/generator/queries/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ impl Generator {
let full_row_lock = self.gen_full_lock_for_update();

quote! {
pub async fn delete(&self, pk: #pk_ident) -> core::result::Result<(), WorkTableError> {
pub async fn delete<Pk>(&self, pk: Pk) -> core::result::Result<(), WorkTableError>
where #pk_ident: From<Pk>
{
let pk: #pk_ident = pk.into();
let lock = {
#full_row_lock
};
Expand All @@ -61,7 +64,10 @@ impl Generator {
let delete_logic = self.gen_delete_logic(false);

quote! {
pub async fn delete_without_lock(&self, pk: #pk_ident) -> core::result::Result<(), WorkTableError> {
pub async fn delete_without_lock<Pk>(&self, pk: Pk) -> core::result::Result<(), WorkTableError>
where #pk_ident: From<Pk>
{
let pk: #pk_ident = pk.into();
#delete_logic
core::result::Result::Ok(())
}
Expand Down Expand Up @@ -112,7 +118,7 @@ impl Generator {
return Err(e);
}
};
let row = self.select(pk.clone()).unwrap();
let row = self.0.select(pk.clone()).unwrap();
#process
}
} else {
Expand All @@ -123,7 +129,7 @@ impl Generator {
.get(&pk)
.map(|v| v.get().value.into())
.ok_or(WorkTableError::NotFound)?;
let row = self.select(pk.clone()).unwrap();
let row = self.0.select(pk.clone()).unwrap();
#process
}
}
Expand Down Expand Up @@ -172,7 +178,7 @@ impl Generator {
self.iter_with_async(|row| {
if row.#field == by {
futures::future::Either::Left(async move {
self.delete(row.get_primary_key()).await
self.delete::<_>(row.get_primary_key()).await
})
} else {
futures::future::Either::Right(async {
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/operation/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ where
.select_by_operation_id(op.operation_id())
.expect("exists as all should be inserted on prepare step")
.id;
self.info_wt.delete_without_lock(pk.into()).await.unwrap();
self.info_wt.delete_without_lock::<_>(pk).await.unwrap();
let prepared_evs = self
.prepared_index_evs
.as_mut()
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ where
row.op_type = op.operation_type();
ops.push(op);
info_wt.insert(row)?;
self.queue_inner_wt.delete_without_lock(id.into()).await?
self.queue_inner_wt.delete_without_lock::<_>(id).await?
}
// println!("New wt generated {:?}", start.elapsed());
// return ops sorted by `OperationId`
Expand Down
30 changes: 15 additions & 15 deletions src/table/vacuum/vacuum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ mod tests {

let first_two_ids = ids.iter().take(2).map(|(i, _)| *i).collect::<Vec<_>>();

table.delete(first_two_ids[0].into()).await.unwrap();
table.delete(first_two_ids[1].into()).await.unwrap();
table.delete(first_two_ids[0]).await.unwrap();
table.delete(first_two_ids[1]).await.unwrap();

let vacuum = create_vacuum(&table);
vacuum.defragment().await;
Expand Down Expand Up @@ -482,8 +482,8 @@ mod tests {

let ids_to_delete = ids.keys().skip(5).take(2).cloned().collect::<Vec<_>>();

table.delete(ids_to_delete[0].into()).await.unwrap();
table.delete(ids_to_delete[1].into()).await.unwrap();
table.delete(ids_to_delete[0]).await.unwrap();
table.delete(ids_to_delete[1]).await.unwrap();

let vacuum = create_vacuum(&table);
vacuum.defragment().await;
Expand Down Expand Up @@ -516,8 +516,8 @@ mod tests {

let last_two_ids = ids.keys().skip(8).take(2).cloned().collect::<Vec<_>>();

table.delete(last_two_ids[1].into()).await.unwrap();
table.delete(last_two_ids[0].into()).await.unwrap();
table.delete(last_two_ids[1]).await.unwrap();
table.delete(last_two_ids[0]).await.unwrap();

let vacuum = create_vacuum(&table);
vacuum.defragment().await;
Expand Down Expand Up @@ -551,7 +551,7 @@ mod tests {
let ids_to_delete = [1, 3, 5, 7].map(|idx| ids.keys().cloned().nth(idx).unwrap());

for id in &ids_to_delete {
table.delete((*id).into()).await.unwrap();
table.delete(*id).await.unwrap();
}

let vacuum = create_vacuum(&table);
Expand Down Expand Up @@ -583,7 +583,7 @@ mod tests {
let remaining_id = ids[0].0;

for (id, _) in ids.iter().skip(1) {
table.delete((*id).into()).await.unwrap();
table.delete(*id).await.unwrap();
}

let vacuum = create_vacuum(&table);
Expand All @@ -610,7 +610,7 @@ mod tests {
ids.push((id, row));
}

table.delete(ids.last().unwrap().0.into()).await.unwrap();
table.delete(ids.last().unwrap().0).await.unwrap();

let vacuum = create_vacuum(&table);
vacuum.defragment().await;
Expand Down Expand Up @@ -651,7 +651,7 @@ mod tests {
let ids_to_delete = ids.keys().take(3).cloned().collect::<Vec<_>>();

for id in &ids_to_delete {
table.delete((*id).into()).await.unwrap();
table.delete(*id).await.unwrap();
}

let vacuum = create_vacuum(&table);
Expand Down Expand Up @@ -682,7 +682,7 @@ mod tests {

let ids_to_delete = original_ids.keys().take(3).cloned().collect::<Vec<_>>();
for id in &ids_to_delete {
table.delete((*id).into()).await.unwrap();
table.delete(*id).await.unwrap();
}

let vacuum = create_vacuum(&table);
Expand Down Expand Up @@ -735,7 +735,7 @@ mod tests {

let ids_to_delete: Vec<_> = ids.iter().map(|(i, _)| *i).take(20).collect();
for id in &ids_to_delete {
table.delete((*id).into()).await.unwrap();
table.delete(*id).await.unwrap();
}

let vacuum = create_vacuum(&table);
Expand Down Expand Up @@ -767,7 +767,7 @@ mod tests {

let ids_to_delete: Vec<_> = ids.iter().step_by(20).map(|(id, _)| *id).collect();
for id in &ids_to_delete {
table.delete((*id).into()).await.unwrap();
table.delete(*id).await.unwrap();
}

let vacuum = create_vacuum(&table);
Expand Down Expand Up @@ -800,7 +800,7 @@ mod tests {
ids.push((id, row));
}

table.delete(ids.last().unwrap().0.into()).await.unwrap();
table.delete(ids.last().unwrap().0).await.unwrap();

let vacuum = create_vacuum(&table);
vacuum.defragment().await;
Expand Down Expand Up @@ -833,7 +833,7 @@ mod tests {
// remove last too to trigger vacuum for last page too.
ids_to_delete.push(ids.last().unwrap().0);
for id in &ids_to_delete {
table.delete((*id).into()).await.unwrap();
table.delete(*id).await.unwrap();
}

let vacuum = create_vacuum(&table);
Expand Down
2 changes: 1 addition & 1 deletion tests/persistence/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ fn test_space_delete_sync() {
id: table.get_next_pk().0,
};
table.insert(row.clone()).unwrap();
table.delete(row.id.into()).await.unwrap();
table.delete(row.id).await.unwrap();
table.wait_for_ops().await;
row.id
};
Expand Down
2 changes: 1 addition & 1 deletion tests/persistence/sync/string_primary_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn test_space_delete_sync() {
id: "Some string".to_string(),
};
table.insert(another_row.clone()).unwrap();
table.delete(another_row.id.clone().into()).await.unwrap();
table.delete(another_row.id.clone()).await.unwrap();
table.wait_for_ops().await;
another_row.id
};
Expand Down
2 changes: 1 addition & 1 deletion tests/persistence/sync/string_secondary_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ fn test_space_delete_sync() {
id: table.get_next_pk().0,
};
table.insert(row.clone()).unwrap();
table.delete(row.id.into()).await.unwrap();
table.delete(row.id).await.unwrap();
table.wait_for_ops().await;
row.id
};
Expand Down
2 changes: 1 addition & 1 deletion tests/worktable/unsized_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ async fn delete_parallel() {
let h2 = tokio::spawn(async move {
for _ in 0..1_000 {
let id_to_update = fastrand::u64(0..1000);
let _ = shared.delete(id_to_update.into()).await;
let _ = shared.delete(id_to_update).await;
{
let mut guard = shared_deleted_state.lock();
guard.insert(id_to_update);
Expand Down
8 changes: 4 additions & 4 deletions tests/worktable/vacuum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn vacuum_parallel_with_selects() {
let task_ids = ids_to_delete.clone();
let delete_task = tokio::spawn(async move {
for id in task_ids.iter() {
delete_table.delete((*id).into()).await.unwrap();
delete_table.delete(*id).await.unwrap();
}
});

Expand Down Expand Up @@ -102,7 +102,7 @@ async fn vacuum_parallel_with_inserts() {
let task_ids = ids_to_delete.clone();
let delete_task = tokio::spawn(async move {
for id in task_ids.iter() {
delete_table.delete((*id).into()).await.unwrap();
delete_table.delete(*id).await.unwrap();
}
});

Expand Down Expand Up @@ -172,7 +172,7 @@ async fn vacuum_parallel_with_upserts() {
let task_row_state = Arc::clone(&row_state);
let delete_task = tokio::spawn(async move {
for id in task_ids.iter() {
delete_table.delete((*id).into()).await.unwrap();
delete_table.delete(*id).await.unwrap();
{
let mut g = task_row_state.lock();
g.remove(id);
Expand Down Expand Up @@ -267,7 +267,7 @@ async fn vacuum_loop_test() {
.map(|(_, l)| table.0.data.select(**l).unwrap())
.collect::<Vec<_>>();
for row in ids_to_remove {
table.delete(row.id.into()).await.unwrap()
table.delete(row.id).await.unwrap()
}
}
}
Loading