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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions bucket_map/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ edition = { workspace = true }
crate-type = ["lib"]
name = "solana_bucket_map"

[features]
dev-context-only-utils = []

[dependencies]
bv = { workspace = true, features = ["serde"] }
bytemuck = { workspace = true }
Expand All @@ -30,6 +33,7 @@ tempfile = { workspace = true }
[dev-dependencies]
fs_extra = { workspace = true }
rayon = { workspace = true }
solana-bucket-map = { path = ".", features = ["dev-context-only-utils"] }
solana-logger = { workspace = true }
solana-pubkey = { workspace = true, features = ["rand"] }

Expand Down
24 changes: 10 additions & 14 deletions bucket_map/src/bucket.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(feature = "dev-context-only-utils")]
use crate::bucket_item::BucketItem;
use {
crate::{
bucket_item::BucketItem,
bucket_map::BucketMapError,
bucket_stats::BucketMapStats,
bucket_storage::{
Expand All @@ -22,7 +23,6 @@ use {
fs,
hash::{Hash, Hasher},
num::NonZeroU64,
ops::RangeBounds,
path::PathBuf,
sync::{
atomic::{AtomicU64, AtomicUsize, Ordering},
Expand Down Expand Up @@ -191,10 +191,8 @@ impl<'b, T: Clone + Copy + PartialEq + std::fmt::Debug + 'static> Bucket<T> {
rv
}

pub fn items_in_range<R>(&self, range: &Option<&R>) -> Vec<BucketItem<T>>
where
R: RangeBounds<Pubkey>,
{
#[cfg(feature = "dev-context-only-utils")]
pub fn items(&self) -> Vec<BucketItem<T>> {
let mut result = Vec::with_capacity(self.index.count.load(Ordering::Relaxed) as usize);
for i in 0..self.index.capacity() {
let ii = i % self.index.capacity();
Expand All @@ -203,14 +201,12 @@ impl<'b, T: Clone + Copy + PartialEq + std::fmt::Debug + 'static> Bucket<T> {
}
let ix = IndexEntryPlaceInBucket::new(ii);
let key = ix.key(&self.index);
if range.map(|r| r.contains(key)).unwrap_or(true) {
let (v, ref_count) = ix.read_value(&self.index, &self.data);
result.push(BucketItem {
pubkey: *key,
ref_count,
slot_list: v.to_vec(),
});
}
let (v, ref_count) = ix.read_value(&self.index, &self.data);
result.push(BucketItem {
pubkey: *key,
ref_count,
slot_list: v.to_vec(),
});
}
result
}
Expand Down
15 changes: 7 additions & 8 deletions bucket_map/src/bucket_api.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#[cfg(feature = "dev-context-only-utils")]
use crate::bucket_item::BucketItem;
use {
crate::{
bucket::Bucket, bucket_item::BucketItem, bucket_map::BucketMapError,
bucket_stats::BucketMapStats, restart::RestartableBucket, MaxSearch, RefCount,
bucket::Bucket, bucket_map::BucketMapError, bucket_stats::BucketMapStats,
restart::RestartableBucket, MaxSearch, RefCount,
},
solana_pubkey::Pubkey,
std::{
ops::RangeBounds,
path::PathBuf,
sync::{
atomic::{AtomicU64, Ordering},
Expand Down Expand Up @@ -47,15 +48,13 @@ impl<T: Clone + Copy + PartialEq + std::fmt::Debug> BucketApi<T> {
}

/// Get the items for bucket
pub fn items_in_range<R>(&self, range: &Option<&R>) -> Vec<BucketItem<T>>
where
R: RangeBounds<Pubkey>,
{
#[cfg(feature = "dev-context-only-utils")]
pub fn items(&self) -> Vec<BucketItem<T>> {
Copy link
Copy Markdown
Author

@HaoranYi HaoranYi Jul 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this fn is only used in test. And we don't need to filter by range. so we can refactor it and put it in "dev-context-only-utils".

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like theres one usage left? How hard would that be to remove?

Copy link
Copy Markdown
Author

@HaoranYi HaoranYi Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine to keep it. It is only used in test and has been marked as "dev-context-only-utils". It won't be affecting validator binary.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking is more along the lines of:
If there is only one usage of this API and type, and it's in a test: Why is it needed at all?
Is the test in the end just in effect testing the API? Or if the test is testing something else, is there a better API it should be using.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. no, the test code, where it is used, is not testing this API. fn items() is a test utility API. It is used as a way to assert the content of bucketmap is expected in testing other APIs, such as assert, delete etc.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

self.bucket
.read()
.unwrap()
.as_ref()
.map(|bucket| bucket.items_in_range(range))
.map(|bucket| bucket.items())
.unwrap_or_default()
}

Expand Down
1 change: 1 addition & 0 deletions bucket_map/src/bucket_item.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "dev-context-only-utils")]
use {crate::RefCount, solana_pubkey::Pubkey};

#[derive(Debug, Default, Clone)]
Expand Down
5 changes: 1 addition & 4 deletions bucket_map/src/bucket_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,7 @@ mod tests {
assert_eq!(total_entries, expected_count);
let mut r = vec![];
for bin in 0..map.num_buckets() {
r.append(
&mut map.buckets[bin]
.items_in_range(&None::<&std::ops::RangeInclusive<Pubkey>>),
);
r.append(&mut map.buckets[bin].items());
}
r
})
Expand Down
Loading