Skip to content

Commit

Permalink
remove superfluous guards
Browse files Browse the repository at this point in the history
  • Loading branch information
density215 committed Oct 23, 2024
1 parent 20c4b03 commit cd56fca
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 135 deletions.
169 changes: 83 additions & 86 deletions src/local_array/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,96 +48,94 @@ macro_rules! insert_match {
// this counts the number of retry_count for this loop only,
// but ultimately we will return the accumulated count of all
// retry_count from this macro.


// std::sync::atomic::fence(Ordering::SeqCst);
let local_retry_count = 0;
// loop {
// retrieve_node_mut_with_guard updates the bitmap index if necessary.
if let Some(current_node) = $self.store.retrieve_node_mut_with_guard($cur_i, $record.multi_uniq_id, $guard) {
match current_node {
$(
SizedStrideRef::$variant(current_node) => {
// eval_node_or_prefix_at mutates the node to reflect changes
// in the ptrbitarr & pfxbitarr.
match current_node.eval_node_or_prefix_at(
$nibble,
$nibble_len,
// All the bits of the search prefix, but with a length set to
// the start of the current stride.
StrideNodeId::dangerously_new_with_id_as_is($pfx.get_net(), $truncate_len),
// the length of THIS stride
$stride_len,
// the length of the next stride
$self.store.get_stride_sizes().get(($level + 1) as usize),
$is_last_stride,
) {
(NewNodeOrIndex::NewNode(n), retry_count) => {
// Stride3 logs to stats[0], Stride4 logs to stats[1], etc.
// $self.stats[$stats_level].inc($level);
// retrieve_node_mut_with_guard updates the bitmap index if necessary.
if let Some(current_node) = $self.store.retrieve_node_mut_with_guard($cur_i, $record.multi_uniq_id) {
match current_node {
$(
SizedStrideRef::$variant(current_node) => {
// eval_node_or_prefix_at mutates the node to reflect changes
// in the ptrbitarr & pfxbitarr.
match current_node.eval_node_or_prefix_at(
$nibble,
$nibble_len,
// All the bits of the search prefix, but with a length set to
// the start of the current stride.
StrideNodeId::dangerously_new_with_id_as_is($pfx.get_net(), $truncate_len),
// the length of THIS stride
$stride_len,
// the length of the next stride
$self.store.get_stride_sizes().get(($level + 1) as usize),
$is_last_stride,
) {
(NewNodeOrIndex::NewNode(n), retry_count) => {
// Stride3 logs to stats[0], Stride4 logs to stats[1], etc.
// $self.stats[$stats_level].inc($level);

// get a new identifier for the node we're going to create.
let new_id = $self.store.acquire_new_node_id(($pfx.get_net(), $truncate_len + $nibble_len));
// get a new identifier for the node we're going to create.
let new_id = $self.store.acquire_new_node_id(($pfx.get_net(), $truncate_len + $nibble_len));

// store the new node in the global
// store. It returns the created id
// and the number of retries before
// success.
match $self.store.store_node(new_id, $record.multi_uniq_id, n, $guard) {
Ok((node_id, s_retry_count)) => {
Ok((node_id, $acc_retry_count + s_retry_count + retry_count))
},
Err(err) => {
Err(err)
}
// store the new node in the global
// store. It returns the created id
// and the number of retries before
// success.
match $self.store.store_node(new_id, $record.multi_uniq_id, n) {
Ok((node_id, s_retry_count)) => {
Ok((node_id, $acc_retry_count + s_retry_count + retry_count))
},
Err(err) => {
Err(err)
}
}
(NewNodeOrIndex::ExistingNode(node_id), retry_count) => {
// $self.store.update_node($cur_i,SizedStrideRefMut::$variant(current_node));
if log_enabled!(log::Level::Trace) {
if local_retry_count > 0 {
trace!("{} contention: Node already exists {}",
std::thread::current().name().unwrap(), node_id
)
}
}
(NewNodeOrIndex::ExistingNode(node_id), retry_count) => {
// $self.store.update_node($cur_i,SizedStrideRefMut::$variant(current_node));
if log_enabled!(log::Level::Trace) {
if local_retry_count > 0 {
trace!("{} contention: Node already exists {}",
std::thread::current().name().unwrap(), node_id
)
}
Ok((node_id, $acc_retry_count + local_retry_count + retry_count))
},
(NewNodeOrIndex::NewPrefix, retry_count) => {
return $self.store.upsert_prefix($pfx, $record, $update_path_selections, $guard)
.and_then(|mut r| {
r.cas_count += $acc_retry_count as usize + local_retry_count as usize + retry_count as usize;
Ok(r)
})
// Log
// $self.stats[$stats_level].inc_prefix_count($level);
}
(NewNodeOrIndex::ExistingPrefix, retry_count) => {
return $self.store.upsert_prefix($pfx, $record, $update_path_selections, $guard)
.and_then(|mut r| {
r.cas_count += $acc_retry_count as usize + local_retry_count as usize + retry_count as usize;
Ok(r)
})
}
} // end of eval_node_or_prefix_at
}
)*,
}
} else {
// if log_enabled!(log::Level::Trace) {
// debug!("{} contention: Retrying id {} from store l{}. attempt {}",
// std::thread::current().name().unwrap(),
// $cur_i,
// $self.store.get_stride_sizes()[$level as usize],
// local_retry_count
// );
// }
// local_retry_count += 1;
// // THIS IS A FAIRLY ARBITRARY NUMBER.
// // We're giving up after a number of tries.
// if local_retry_count >= 8 {
// if log_enabled!(log::Level::Trace) {
// debug!("{} contention: Max. retry count reached. Giving up for id {} from store l{} after {} attempts.",
// std::thread::current().name().unwrap(),
Ok((node_id, $acc_retry_count + local_retry_count + retry_count))
},
(NewNodeOrIndex::NewPrefix, retry_count) => {
return $self.store.upsert_prefix($pfx, $record, $update_path_selections, $guard)
.and_then(|mut r| {
r.cas_count += $acc_retry_count as usize + local_retry_count as usize + retry_count as usize;
Ok(r)
})
// Log
// $self.stats[$stats_level].inc_prefix_count($level);
}
(NewNodeOrIndex::ExistingPrefix, retry_count) => {
return $self.store.upsert_prefix($pfx, $record, $update_path_selections, $guard)
.and_then(|mut r| {
r.cas_count += $acc_retry_count as usize + local_retry_count as usize + retry_count as usize;
Ok(r)
})
}
} // end of eval_node_or_prefix_at
}
)*,
}
} else {
// if log_enabled!(log::Level::Trace) {
// debug!("{} contention: Retrying id {} from store l{}. attempt {}",
// std::thread::current().name().unwrap(),
// $cur_i,
// $self.store.get_stride_sizes()[$level as usize],
// local_retry_count
// );
// }
// local_retry_count += 1;
// // THIS IS A FAIRLY ARBITRARY NUMBER.
// // We're giving up after a number of tries.
// if local_retry_count >= 8 {
// if log_enabled!(log::Level::Trace) {
// debug!("{} contention: Max. retry count reached. Giving up for id {} from store l{} after {} attempts.",
// std::thread::current().name().unwrap(),
// $cur_i,
// $self.store.get_stride_sizes()[$level as usize],
// local_retry_count
Expand All @@ -146,10 +144,9 @@ macro_rules! insert_match {
// return Err(PrefixStoreError::NodeCreationMaxRetryError);
// }
// $back_off.spin();
Err(PrefixStoreError::NodeCreationMaxRetryError)
}
Err(PrefixStoreError::NodeCreationMaxRetryError)
}
// }
}
}
}

Expand Down
27 changes: 9 additions & 18 deletions src/local_array/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,9 @@ where

let root_node_id = self.get_root_node_id();
let mut node = match self.store.get_stride_for_id(root_node_id) {
3 => self
.store
.retrieve_node_with_guard(root_node_id, guard)
.unwrap(),
4 => self
.store
.retrieve_node_with_guard(root_node_id, guard)
.unwrap(),
_ => self
.store
.retrieve_node_with_guard(root_node_id, guard)
.unwrap(),
3 => self.store.retrieve_node_with_guard(root_node_id).unwrap(),
4 => self.store.retrieve_node_with_guard(root_node_id).unwrap(),
_ => self.store.retrieve_node_with_guard(root_node_id).unwrap(),
};

let mut nibble;
Expand Down Expand Up @@ -438,7 +429,7 @@ where
match_prefix_idx = Some(pfx_idx);
node = self
.store
.retrieve_node_with_guard(n, guard)
.retrieve_node_with_guard(n)
.unwrap();

if last_stride {
Expand All @@ -460,7 +451,7 @@ where
(Some(n), None) => {
node = self
.store
.retrieve_node_with_guard(n, guard)
.retrieve_node_with_guard(n)
.unwrap();

if last_stride {
Expand Down Expand Up @@ -562,7 +553,7 @@ where
match_prefix_idx = Some(pfx_idx);
node = self
.store
.retrieve_node_with_guard(n, guard)
.retrieve_node_with_guard(n)
.unwrap();

if last_stride {
Expand All @@ -584,7 +575,7 @@ where
(Some(n), None) => {
node = self
.store
.retrieve_node_with_guard(n, guard)
.retrieve_node_with_guard(n)
.unwrap();

if last_stride {
Expand Down Expand Up @@ -675,7 +666,7 @@ where
match_prefix_idx = Some(pfx_idx);
node = self
.store
.retrieve_node_with_guard(n, guard)
.retrieve_node_with_guard(n)
.unwrap();

if last_stride {
Expand All @@ -697,7 +688,7 @@ where
(Some(n), None) => {
node = self
.store
.retrieve_node_with_guard(n, guard)
.retrieve_node_with_guard(n)
.unwrap();

if last_stride {
Expand Down
1 change: 0 additions & 1 deletion src/local_array/store/atomic_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ impl<AF: AddressFamily, S: Stride> NodeSet<AF, S> {
pub fn update_rbm_index(
&self,
multi_uniq_id: u32,
_guard: &crate::epoch::Guard,
) -> Result<u32, crate::prelude::multi::PrefixStoreError>
where
S: crate::local_array::atomic_stride::Stride,
Expand Down
16 changes: 8 additions & 8 deletions src/local_array/store/custom_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl<
StrideNodeId::dangerously_new_with_id_as_is(AF::zero(), 0),
0_u32,
root_node,
guard,
// guard,
)?;

Ok(store)
Expand All @@ -383,7 +383,7 @@ impl<
id: StrideNodeId<AF>,
multi_uniq_id: u32,
next_node: SizedStrideNode<AF>,
guard: &Guard,
// guard: &Guard,
) -> Result<(StrideNodeId<AF>, u32), PrefixStoreError> {
struct SearchLevel<'s, AF: AddressFamily, S: Stride> {
f: &'s dyn Fn(
Expand Down Expand Up @@ -449,7 +449,7 @@ impl<
pub(crate) fn retrieve_node_with_guard(
&'a self,
id: StrideNodeId<AF>,
_guard: &'a Guard,
// _guard: &'a Guard,
) -> Option<SizedStrideRef<'a, AF>> {
struct SearchLevel<'s, AF: AddressFamily, S: Stride> {
f: &'s dyn for<'a> Fn(
Expand Down Expand Up @@ -557,15 +557,15 @@ impl<
&'a self,
id: StrideNodeId<AF>,
multi_uniq_id: u32,
guard: &'a Guard,
// guard: &'a Guard,
) -> Option<SizedStrideRef<AF>> {
struct SearchLevel<'s, AF: AddressFamily, S: Stride> {
f: &'s dyn for<'a> Fn(
&SearchLevel<AF, S>,
&'a NodeSet<AF, S>,
// [u8; 10],
u8,
&'a Guard,
// &'a Guard,
)
-> Option<SizedStrideRef<'a, AF>>,
}
Expand All @@ -588,20 +588,20 @@ impl<
&search_level_3,
self.buckets.get_store3(id),
0,
guard,
// guard,
),

4 => (search_level_4.f)(
&search_level_4,
self.buckets.get_store4(id),
0,
guard,
// guard,
),
_ => (search_level_5.f)(
&search_level_5,
self.buckets.get_store5(id),
0,
guard,
// guard,
),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/local_array/store/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl<

if let Some(next_ptr) = next_ptr {
let node = if self.mui.is_none() {
self.store.retrieve_node_with_guard(next_ptr, self.guard)
self.store.retrieve_node_with_guard(next_ptr)
} else {
self.store.retrieve_node_for_mui(
next_ptr,
Expand Down Expand Up @@ -762,7 +762,7 @@ impl<
let node = if let Some(mui) = mui {
self.retrieve_node_for_mui(start_node_id, mui)
} else {
self.retrieve_node_with_guard(start_node_id, guard)
self.retrieve_node_with_guard(start_node_id)
};

if let Some(node) = node {
Expand Down
Loading

0 comments on commit cd56fca

Please sign in to comment.