Skip to content
Closed
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: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ keywords = ["database", "embedded", "in-memory", "index", "storage"]
categories = ["database-implementations", "data-structures", "caching"]

[features]
default = ["wti-predictable-search"]
default = ["std", "wti-predictable-search"]
std = []
perf_measurements = ["dep:performance_measurement", "dep:performance_measurement_codegen"]
s3-support = ["dep:rusty-s3", "dep:url", "dep:reqwest", "dep:walkdir", "worktable_codegen/s3-support"]
# Moves unique WorkTablesIndex structural CDC work out of the table mutation
Expand Down Expand Up @@ -45,6 +46,7 @@ data_bucket = { version = "^0.5, >=0.5.7" }
derive_more = { version = "2", features = ["from", "error", "display", "debug", "into"] }
eyre = "0.6"
fastrand = "2"
hashbrown = "0.15"
futures = "0.3"
indexset = { package = "WorkTablesIndex", version = "^0.0, >=0.0.12", default-features = false, features = ["concurrent", "cdc", "multimap"] }
vanilla_indexset = { package = "indexset", version = "0.15", features = ["concurrent", "cdc", "multimap"] }
Expand Down
4 changes: 2 additions & 2 deletions codegen/src/generators/in_memory/index/cdc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl InMemoryGenerator {
fn process_difference_remove_cdc(
&self,
link: Link,
difference: std::collections::HashMap<&str, Difference<#avt_type_ident>>
difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>>
) -> (#events_ident, Result<(), IndexError<#available_index_ident>>) {
#(#process_difference_rows)*
(#events_ident {
Expand Down Expand Up @@ -381,7 +381,7 @@ impl InMemoryGenerator {
fn process_difference_insert_cdc(
&self,
link: Link,
difference: std::collections::HashMap<&str, Difference<#avt_type_ident>>
difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>>
) -> (#events_ident, Result<(), IndexError<#available_index_ident>>) {
let mut inserted_indexes: Vec<#available_index_ident> = vec![];
let mut partial_events = #events_ident::default();
Expand Down
4 changes: 2 additions & 2 deletions codegen/src/generators/in_memory/index/usual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl InMemoryGenerator {
fn process_difference_remove(
&self,
link: Link,
difference: std::collections::HashMap<&str, Difference<#avt_type_ident>>
difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>>
) -> core::result::Result<(), IndexError<#avt_index_ident>> {
#(#process_difference_remove_rows)*
core::result::Result::Ok(())
Expand Down Expand Up @@ -304,7 +304,7 @@ impl InMemoryGenerator {
fn process_difference_insert(
&self,
link: Link,
difference: std::collections::HashMap<&str, Difference<#avt_type_ident>>
difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>>
) -> core::result::Result<(), IndexError<#avt_index_ident>> {
let mut inserted_indexes: Vec<#avt_index_ident> = vec![];
#(#process_difference_insert_rows)*
Expand Down
16 changes: 8 additions & 8 deletions codegen/src/generators/in_memory/locks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl InMemoryGenerator {
.keys()
.map(|i| {
let name = Ident::new(format!("{i}_lock").as_str(), Span::mixed_site());
quote! { #name: Option<std::sync::Arc<Lock>>, }
quote! { #name: Option<worktable::prelude::Arc<Lock>>, }
})
.collect();

Expand Down Expand Up @@ -124,8 +124,8 @@ impl InMemoryGenerator {
.collect();

quote! {
fn with_lock(id: u16) -> (Self, std::sync::Arc<Lock>) {
let lock = std::sync::Arc::new(Lock::new(id));
fn with_lock(id: u16) -> (Self, worktable::prelude::Arc<Lock>) {
let lock = worktable::prelude::Arc::new(Lock::new(id));
(
Self {
#(#rows),*
Expand Down Expand Up @@ -154,9 +154,9 @@ impl InMemoryGenerator {

quote! {
#[allow(clippy::mutable_key_type)]
fn lock(&mut self, id: u16) -> (std::collections::HashSet<std::sync::Arc<Lock>>, std::sync::Arc<Lock>) {
let mut set = std::collections::HashSet::new();
let lock = std::sync::Arc::new(Lock::new(id));
fn lock(&mut self, id: u16) -> (worktable::prelude::HashSet<worktable::prelude::Arc<Lock>>, worktable::prelude::Arc<Lock>) {
let mut set = worktable::prelude::HashSet::new();
let lock = worktable::prelude::Arc::new(Lock::new(id));
#(#rows)*

(set, lock)
Expand Down Expand Up @@ -186,8 +186,8 @@ impl InMemoryGenerator {

quote! {
#[allow(clippy::mutable_key_type)]
fn merge(&mut self, other: &mut Self) -> std::collections::HashSet<std::sync::Arc<Lock>> {
let mut set = std::collections::HashSet::new();
fn merge(&mut self, other: &mut Self) -> worktable::prelude::HashSet<worktable::prelude::Arc<Lock>> {
let mut set = worktable::prelude::HashSet::new();
#(#rows)*
set
}
Expand Down
16 changes: 8 additions & 8 deletions codegen/src/generators/in_memory/primary_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ impl InMemoryGenerator {
/// atomic of primitive.
fn get_generator_from_type(type_: &TokenStream, i: &Ident) -> syn::Result<TokenStream> {
Ok(match type_.to_string().as_str() {
"u8" => quote! { std::sync::atomic::AtomicU8 },
"u16" => quote! { std::sync::atomic::AtomicU16 },
"u32" => quote! { std::sync::atomic::AtomicU32 },
"u64" => quote! { std::sync::atomic::AtomicU64 },
"i8" => quote! { std::sync::atomic::AtomicI8 },
"i16" => quote! { std::sync::atomic::AtomicI16 },
"i32" => quote! { std::sync::atomic::AtomicI32 },
"i64" => quote! { std::sync::atomic::AtomicI64 },
"u8" => quote! { core::sync::atomic::AtomicU8 },
"u16" => quote! { core::sync::atomic::AtomicU16 },
"u32" => quote! { core::sync::atomic::AtomicU32 },
"u64" => quote! { core::sync::atomic::AtomicU64 },
"i8" => quote! { core::sync::atomic::AtomicI8 },
"i16" => quote! { core::sync::atomic::AtomicI16 },
"i32" => quote! { core::sync::atomic::AtomicI32 },
"i64" => quote! { core::sync::atomic::AtomicI64 },
// The accepted set is `worktable_dsl::AUTOINCREMENT_TYPES`, and the
// arms above must stay equal to it. `check` uses that list to
// answer "would the macro accept this", so a second copy drifting
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/generators/in_memory/queries/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl InMemoryGenerator {
quote! {
pub async fn #name(&self, by: #type_) -> core::result::Result<(), WorkTableError> {
let _bulk_mutation = self.0.lock_manager.bulk_mutation_guard();
let pks = std::cell::RefCell::new(Vec::new());
let pks = core::cell::RefCell::new(Vec::new());
self.iter_with(|row| {
if row.#field == by {
pks.borrow_mut().push(row.get_primary_key());
Expand Down
6 changes: 3 additions & 3 deletions codegen/src/generators/in_memory/queries/locks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ impl InMemoryGenerator {

quote! {
#[allow(clippy::mutable_key_type)]
pub fn #ident(&mut self, id: u16) -> (std::collections::HashSet<std::sync::Arc<Lock>>, std::sync::Arc<Lock>) {
let mut set = std::collections::HashSet::new();
let new_lock = std::sync::Arc::new(Lock::new(id));
pub fn #ident(&mut self, id: u16) -> (worktable::prelude::HashSet<worktable::prelude::Arc<Lock>>, worktable::prelude::Arc<Lock>) {
let mut set = worktable::prelude::HashSet::new();
let new_lock = worktable::prelude::Arc::new(Lock::new(id));
#(#inner)*
(set, new_lock)
}
Expand Down
4 changes: 2 additions & 2 deletions codegen/src/generators/in_memory/queries/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl InMemoryGenerator {
// Acquire the grace-period guard only when iteration starts.
// Merely constructing and retaining a query builder must not
// stall retired-link reclamation.
let iter = std::iter::once_with(move || {
let iter = core::iter::once_with(move || {
let read_guard = self.0.data.read_guard();
self.0.primary_index.pk_map
.iter_values()
Expand All @@ -55,7 +55,7 @@ impl InMemoryGenerator {
return None;
}
current_link = replacement;
std::hint::spin_loop();
core::hint::spin_loop();
}
None
})
Expand Down
16 changes: 8 additions & 8 deletions codegen/src/generators/in_memory/queries/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl InMemoryGenerator {
.keys()
.map(|i| {
quote! {
std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i);
core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i);
}
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -273,8 +273,8 @@ impl InMemoryGenerator {
let avt_type_ident = name_generator.get_available_type_ident();
quote! {
if let core::result::Result::Err(e) = #write {
let mut reversed_diffs: std::collections::HashMap<&str, Difference<#avt_type_ident>> =
std::collections::HashMap::new();
let mut reversed_diffs: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> =
worktable::prelude::HashMap::new();
for (key, diff) in diffs {
reversed_diffs.insert(key, Difference { old: diff.new, new: diff.old });
}
Expand Down Expand Up @@ -460,7 +460,7 @@ impl InMemoryGenerator {
let row_old = self.0.data.select_non_ghosted(link)?;
let row_new = row.clone();
let updated_bytes: Vec<u8> = vec![];
let mut diffs: std::collections::HashMap<&str, Difference<#avt_type_ident>> = std::collections::HashMap::new();
let mut diffs: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> = worktable::prelude::HashMap::new();
}
} else {
quote! {
Expand Down Expand Up @@ -605,7 +605,7 @@ impl InMemoryGenerator {
.iter()
.map(|i| {
quote! {
std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i);
core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i);
}
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -680,7 +680,7 @@ impl InMemoryGenerator {
.iter()
.map(|i| {
quote! {
std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i);
core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i);
}
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -830,7 +830,7 @@ impl InMemoryGenerator {
pks.sort_unstable();
pks.dedup();

let mut guards: std::collections::HashMap<_, _> = std::collections::HashMap::new();
let mut guards: worktable::prelude::HashMap<_, _> = worktable::prelude::HashMap::new();
// Full-row locks, not per-column custom locks: each row's
// unsized reinsert path mutates the whole row under these
// guards, and one uniform lock kind keeps every concurrent
Expand Down Expand Up @@ -902,7 +902,7 @@ impl InMemoryGenerator {
.iter()
.map(|i| {
quote! {
std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i);
core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i);
}
})
.collect::<Vec<_>>();
Expand Down
22 changes: 11 additions & 11 deletions codegen/src/generators/in_memory/table/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl InMemoryGenerator {
#row_fields_ident>
where
#primary_key_type: From<Pk>,
R: std::ops::RangeBounds<Pk> + 'a,
R: core::ops::RangeBounds<Pk> + 'a,
Pk: Clone + 'a,
{
let converted_range = (
Expand All @@ -118,7 +118,7 @@ impl InMemoryGenerator {
);
// Delay the grace-period guard until the returned iterator is
// consumed so an idle query builder cannot pin reclamation.
let rows = std::iter::once_with(move || {
let rows = core::iter::once_with(move || {
let read_guard = self.0.data.read_guard();
self.0.primary_index.pk_map
.range_links(converted_range)
Expand Down Expand Up @@ -302,7 +302,7 @@ impl InMemoryGenerator {
let exponent = core::cmp::min(backoff_spins - 8, 8);
let micros = core::cmp::min(1u64 << exponent, 256);
backoff_spins = backoff_spins.saturating_add(1);
tokio::time::sleep(std::time::Duration::from_micros(micros)).await;
tokio::time::sleep(core::time::Duration::from_micros(micros)).await;
}
}
}
Expand Down Expand Up @@ -343,7 +343,7 @@ impl InMemoryGenerator {
/// assigned contiguous keys before `insert_many`. Interleaved
/// `get_next_pk` calls keep working and never overlap a
/// reservation.
pub fn reserve_pks(&self, count: usize) -> std::ops::Range<#pk_inner_type> {
pub fn reserve_pks(&self, count: usize) -> core::ops::Range<#pk_inner_type> {
self.0.reserve_pks(count)
}
}
Expand Down Expand Up @@ -375,7 +375,7 @@ impl InMemoryGenerator {
quote! {
pub async fn iter_with_async<
F: Fn(#row_type) -> Fut,
Fut: std::future::Future<Output = core::result::Result<(), WorkTableError>>
Fut: core::future::Future<Output = core::result::Result<(), WorkTableError>>
>(&self, f: F) -> core::result::Result<(), WorkTableError> {
#inner
}
Expand Down Expand Up @@ -436,8 +436,8 @@ impl InMemoryGenerator {
let lock_type = name_generator.get_lock_type_ident();

quote! {
pub fn vacuum(&self) -> std::sync::Arc<dyn WorkTableVacuum + std::marker::Send + Sync> {
std::sync::Arc::new(EmptyDataVacuum::<
pub fn vacuum(&self) -> worktable::prelude::Arc<dyn WorkTableVacuum + core::marker::Send + Sync> {
worktable::prelude::Arc::new(EmptyDataVacuum::<
_,
_,
_,
Expand All @@ -448,10 +448,10 @@ impl InMemoryGenerator {
_
>::new(
#table_name,
std::sync::Arc::clone(&self.0.data),
std::sync::Arc::clone(&self.0.lock_manager),
std::sync::Arc::clone(&self.0.primary_index),
std::sync::Arc::clone(&self.0.indexes),
worktable::prelude::Arc::clone(&self.0.data),
worktable::prelude::Arc::clone(&self.0.lock_manager),
worktable::prelude::Arc::clone(&self.0.primary_index),
worktable::prelude::Arc::clone(&self.0.indexes),
))
}
}
Expand Down
12 changes: 6 additions & 6 deletions codegen/src/generators/in_memory/table/index_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl InMemoryGenerator {
if current_link == Some(link) {
return None;
}
std::hint::spin_loop();
core::hint::spin_loop();
}
None
};
Expand Down Expand Up @@ -140,7 +140,7 @@ impl InMemoryGenerator {
#column_range_type,
#row_fields_ident>
{
let rows = std::iter::once_with(move || {
let rows = core::iter::once_with(move || {
let read_guard = self.0.data.read_guard();
self.0.indexes.#field_ident
.get(#by)
Expand Down Expand Up @@ -173,7 +173,7 @@ impl InMemoryGenerator {

let (range_bounds, range_arg) = if is_float(type_.to_string().as_str()) {
(
quote! { std::ops::RangeBounds<#type_> },
quote! { core::ops::RangeBounds<#type_> },
quote! {
(
predicate_range.0.as_ref().map(|v| OrderedFloat(*v)),
Expand All @@ -183,7 +183,7 @@ impl InMemoryGenerator {
)
} else {
(
quote! { std::ops::RangeBounds<#type_> },
quote! { core::ops::RangeBounds<#type_> },
quote! { predicate_range.clone() },
)
};
Expand Down Expand Up @@ -216,7 +216,7 @@ impl InMemoryGenerator {
};
let predicate_filter = quote! {
.filter(move |row| {
std::ops::RangeBounds::contains(&predicate_range, &row.#row_field_ident)
core::ops::RangeBounds::contains(&predicate_range, &row.#row_field_ident)
})
};

Expand All @@ -231,7 +231,7 @@ impl InMemoryGenerator {
#predicate_setup
// Query construction is not an active read. Pin the grace
// period on the first row lookup instead.
let rows = std::iter::once_with(move || {
let rows = core::iter::once_with(move || {
let read_guard = self.0.data.read_guard();
#index_range
.filter_map(#select_row)
Expand Down
12 changes: 6 additions & 6 deletions codegen/src/generators/in_memory/table/select_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl InMemoryGenerator {
);
let range_ident = Ident::new(&format!("Range{variant}"), Span::call_site());
quote! {
#variant_ident(std::ops::#range_ident<#ty_ident>),
#variant_ident(core::ops::#range_ident<#ty_ident>),
}
})
.collect();
Expand All @@ -65,8 +65,8 @@ impl InMemoryGenerator {
);
let range_ident = Ident::new(&format!("Range{variant}"), Span::call_site());
quote! {
impl From<std::ops::#range_ident<#ty_ident>> for #column_range_type {
fn from(range: std::ops::#range_ident<#ty_ident>) -> Self {
impl From<core::ops::#range_ident<#ty_ident>> for #column_range_type {
fn from(range: core::ops::#range_ident<#ty_ident>) -> Self {
Self::#variant_ident(range)
}
}
Expand Down Expand Up @@ -100,8 +100,8 @@ impl InMemoryGenerator {
let col_ident = Ident::new(&column.to_string(), Span::call_site());
quote! {
#row_fields_ident::#column_variant => {
let cmp = a.#col_ident.partial_cmp(&b.#col_ident).unwrap_or(std::cmp::Ordering::Equal);
if cmp != std::cmp::Ordering::Equal {
let cmp = a.#col_ident.partial_cmp(&b.#col_ident).unwrap_or(core::cmp::Ordering::Equal);
if cmp != core::cmp::Ordering::Equal {
return match order {
Order::Asc => cmp,
Order::Desc => cmp.reverse(),
Expand Down Expand Up @@ -165,7 +165,7 @@ impl InMemoryGenerator {
_ => continue,
}
}
std::cmp::Ordering::Equal
core::cmp::Ordering::Equal
});
iter = Box::new(items.into_iter());
};
Expand Down
Loading
Loading