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
6 changes: 3 additions & 3 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.13"
version = "0.8.15"
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.6" }
worktable_codegen = { path = "codegen", version = "0.8.14" }

eyre = "0.6.12"
derive_more = { version = "2.0.1", features = ["from", "error", "display", "into"] }
Expand All @@ -29,7 +29,7 @@ futures = "0.3.30"
uuid = { version = "1.10.0", features = ["v4", "v7"] }
data_bucket = "0.3.6"
# data_bucket = { git = "https://github.com/pathscale/DataBucket", branch = "page_cdc_correction", version = "0.2.7" }
# data_bucket = { path = "../DataBucket", version = "0.3.4" }
# data_bucket = { path = "../DataBucket", version = "0.3.6" }
performance_measurement_codegen = { path = "performance_measurement/codegen", version = "0.1.0", optional = true }
performance_measurement = { path = "performance_measurement", version = "0.1.0", optional = true }
# indexset = { version = "0.12.3", features = ["concurrent", "cdc", "multimap"] }
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.6"
version = "0.8.14"
edition = "2024"
license = "MIT"
description = "WorkTable codegeneration crate"
Expand Down
42 changes: 30 additions & 12 deletions codegen/src/worktable/generator/queries/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Generator {
fn gen_full_row_delete(&mut self) -> TokenStream {
let name_generator = WorktableNameGenerator::from_table_name(self.name.to_string());
let pk_ident = name_generator.get_primary_key_type_ident();
let delete_logic = self.gen_delete_logic();
let delete_logic = self.gen_delete_logic(true);
let full_row_lock = self.gen_full_lock_for_update();

quote! {
Expand All @@ -58,7 +58,7 @@ impl Generator {
fn gen_full_row_delete_without_lock(&mut self) -> TokenStream {
let name_generator = WorktableNameGenerator::from_table_name(self.name.to_string());
let pk_ident = name_generator.get_primary_key_type_ident();
let delete_logic = self.gen_delete_logic();
let delete_logic = self.gen_delete_logic(false);

quote! {
pub fn delete_without_lock(&self, pk: #pk_ident) -> core::result::Result<(), WorkTableError> {
Expand All @@ -68,7 +68,7 @@ impl Generator {
}
}

fn gen_delete_logic(&self) -> TokenStream {
fn gen_delete_logic(&self, is_locked: bool) -> TokenStream {
let name_generator = WorktableNameGenerator::from_table_name(self.name.to_string());
let pk_ident = name_generator.get_primary_key_type_ident();
let secondary_events_ident = name_generator.get_space_secondary_index_events_ident();
Expand Down Expand Up @@ -97,15 +97,33 @@ impl Generator {
self.0.data.delete(link).map_err(WorkTableError::PagesError)?;
}
};

quote! {
let link = self.0
.pk_map
.get(&pk)
.map(|v| v.get().value)
.ok_or(WorkTableError::NotFound)?;
let row = self.select(pk.clone()).unwrap();
#process
if is_locked {
quote! {
let link = match self.0
.pk_map
.get(&pk)
.map(|v| v.get().value)
.ok_or(WorkTableError::NotFound) {
Ok(l) => l,
Err(e) => {
lock.unlock(); // Releases locks
self.0.lock_map.remove_with_lock_check(&pk).await; // Removes locks
return Err(e);
}
};
let row = self.select(pk.clone()).unwrap();
#process
}
} else {
quote! {
let link = self.0
.pk_map
.get(&pk)
.map(|v| v.get().value)
.ok_or(WorkTableError::NotFound)?;
let row = self.select(pk.clone()).unwrap();
#process
}
}
}

Expand Down
36 changes: 30 additions & 6 deletions codegen/src/worktable/generator/queries/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,19 @@ impl Generator {
#full_row_lock
};

let link = self.0
let link = match self.0
.pk_map
.get(&pk)
.map(|v| v.get().value)
.ok_or(WorkTableError::NotFound)?;
.ok_or(WorkTableError::NotFound) {
Ok(l) => l,
Err(e) => {
lock.unlock();
self.0.lock_map.remove_with_lock_check(&pk).await;

return Err(e);
}
};

let row_old = self.0.data.select_non_ghosted(link)?;
self.0.update_state.insert(pk.clone(), row_old);
Expand Down Expand Up @@ -469,11 +477,19 @@ impl Generator {
#custom_lock
};

let link = self.0
let link = match self.0
.pk_map
.get(&pk)
.map(|v| v.get().value)
.ok_or(WorkTableError::NotFound)?;
.ok_or(WorkTableError::NotFound) {
Ok(l) => l,
Err(e) => {
lock.unlock();
self.0.lock_map.remove_with_lock_check(&pk).await;

return Err(e);
}
};

let mut bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&row).map_err(|_| WorkTableError::SerializeError)?;
let mut archived_row = unsafe { rkyv::access_unchecked_mut::<<#query_ident as rkyv::Archive>::Archived>(&mut bytes[..]).unseal_unchecked() };
Expand Down Expand Up @@ -702,10 +718,18 @@ impl Generator {
#custom_lock
};

let link = self.0.indexes.#index
let link = match self.0.indexes.#index
.get(#by)
.map(|kv| kv.get().value)
.ok_or(WorkTableError::NotFound)?;
.ok_or(WorkTableError::NotFound) {
Ok(l) => l,
Err(e) => {
lock.unlock();
self.0.lock_map.remove_with_lock_check(&pk).await;

return Err(e);
}
};

let op_id = OperationId::Single(uuid::Uuid::now_v7());
#size_check
Expand Down
37 changes: 37 additions & 0 deletions src/in_memory/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,43 @@ impl<Row, const DATA_LENGTH: usize> Data<Row, DATA_LENGTH> {
Ok(link)
}

#[allow(clippy::missing_safety_doc)]
pub unsafe fn try_save_row_by_link(
&self,
row: &Row,
mut link: Link,
) -> Result<(Link, Option<Link>), ExecutionError>
where
Row: Archive
+ for<'a> Serialize<
Strategy<Serializer<AlignedVec, ArenaHandle<'a>, Share>, rkyv::rancor::Error>,
>,
{
let bytes = rkyv::to_bytes(row).map_err(|_| ExecutionError::SerializeError)?;
let length = bytes.len() as u32;
if length > link.length {
return Err(ExecutionError::InvalidLink);
}

let link_diff = link.length - length;
let link_left = if link_diff > 0 {
link.length -= link_diff;
Some(Link {
page_id: link.page_id,
offset: link.offset + link.length,
length: link_diff,
})
} else {
None
};

let inner_data = unsafe { &mut *self.inner_data.get() };
inner_data[link.offset as usize..][..link.length as usize]
.copy_from_slice(bytes.as_slice());

Ok((link, link_left))
}

/// # Safety
/// This function is `unsafe` because it returns a mutable reference to an archived row.
/// The caller must ensure that there are no other references to the same data
Expand Down
Loading
Loading