Skip to content

Commit 2e72638

Browse files
authored
chore(ddtelemetry): migrate from RawTable to HashTable API (#1009)
* chore(ddtelemetry): migrate from RawTable to HashTable API Update the QueueHashMap implementation to use the newer, more stable HashTable API from hashbrown. This change maintains the same functionality while using the recommended API. * chore(ddtelemetry): update hashbrown to v0.15 Update hashbrown dependency to v0.15 and fix DefaultHashBuilder import path. The raw feature is no longer needed since we migrated to the hash_table module. * style(ddtelemetry): fix typos in module name * docs(ddtelemetry): restore deleted comment
1 parent b14e541 commit 2e72638

File tree

4 files changed

+57
-19
lines changed

4 files changed

+57
-19
lines changed

Cargo.lock

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE-3rdparty.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11924,6 +11924,32 @@ third_party_libraries:
1192411924
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
1192511925
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1192611926
DEALINGS IN THE SOFTWARE.
11927+
- package_name: foldhash
11928+
package_version: 0.1.5
11929+
repository: https://github.com/orlp/foldhash
11930+
license: Zlib
11931+
licenses:
11932+
- license: Zlib
11933+
text: |-
11934+
Copyright (c) 2024 Orson Peters
11935+
11936+
This software is provided 'as-is', without any express or implied warranty. In
11937+
no event will the authors be held liable for any damages arising from the use of
11938+
this software.
11939+
11940+
Permission is granted to anyone to use this software for any purpose, including
11941+
commercial applications, and to alter it and redistribute it freely, subject to
11942+
the following restrictions:
11943+
11944+
1. The origin of this software must not be misrepresented; you must not claim
11945+
that you wrote the original software. If you use this software in a product,
11946+
an acknowledgment in the product documentation would be appreciated but is
11947+
not required.
11948+
11949+
2. Altered source versions must be plainly marked as such, and must not be
11950+
misrepresented as being the original software.
11951+
11952+
3. This notice may not be removed or altered from any source distribution.
1192711953
- package_name: form_urlencoded
1192811954
package_version: 1.2.1
1192911955
repository: https://github.com/servo/rust-url

ddtelemetry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tokio-util = { version = "0.7", features = ["codec"] }
3232

3333
tracing = { version = "0.1", default-features = false }
3434
uuid = { version = "1.3", features = ["v4"] }
35-
hashbrown = { version = "0.14", features = ["raw"] }
35+
hashbrown = "0.15"
3636

3737
[dev-dependencies]
3838
tracing-subscriber = "0.3.18"

ddtelemetry/src/worker/store.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
use std::{collections::VecDeque, hash::Hash};
55

6-
mod queuehasmpap {
7-
use hashbrown::{hash_map::DefaultHashBuilder, raw::RawTable};
6+
mod queuehashmap {
7+
use hashbrown::{hash_table::HashTable, DefaultHashBuilder};
88
use std::{
99
collections::VecDeque,
1010
hash::{BuildHasher, Hash},
1111
};
1212

1313
pub struct QueueHashMap<K, V> {
14-
table: RawTable<usize>,
14+
table: HashTable<usize>,
1515
hash_builder: DefaultHashBuilder,
1616
items: VecDeque<(K, V)>,
1717
popped: usize,
@@ -41,8 +41,9 @@ mod queuehasmpap {
4141
pub fn pop_front(&mut self) -> Option<(K, V)> {
4242
let (k, v) = self.items.pop_front()?;
4343
let hash = make_hash(&self.hash_builder, &k);
44-
let found = self.table.remove_entry(hash, |other| *other == self.popped);
45-
debug_assert!(found.is_some());
44+
if let Ok(entry) = self.table.find_entry(hash, |&other| other == self.popped) {
45+
entry.remove();
46+
}
4647
debug_assert!(self.items.len() == self.table.len());
4748
self.popped += 1;
4849
Some((k, v))
@@ -52,8 +53,8 @@ mod queuehasmpap {
5253
let hash = make_hash(&self.hash_builder, k);
5354
let idx = self
5455
.table
55-
.get(hash, |other| &self.items[other - self.popped].0 == k)?;
56-
Some(&self.items[idx - self.popped].1)
56+
.find(hash, |other| &self.items[other - self.popped].0 == k)?;
57+
Some(&self.items[*idx - self.popped].1)
5758
}
5859

5960
pub fn get_idx(&self, idx: usize) -> Option<&(K, V)> {
@@ -62,11 +63,11 @@ mod queuehasmpap {
6263

6364
pub fn get_mut_or_insert(&mut self, key: K, default: V) -> (&mut V, bool) {
6465
let hash = make_hash(&self.hash_builder, &key);
65-
if let Some(&idx) = self
66+
if let Some(idx) = self
6667
.table
67-
.get(hash, |other| self.items[other - self.popped].0 == key)
68+
.find(hash, |other| self.items[other - self.popped].0 == key)
6869
{
69-
return (&mut self.items[idx - self.popped].1, false);
70+
return (&mut self.items[*idx - self.popped].1, false);
7071
}
7172
self.insert_nocheck(hash, key, default);
7273

@@ -79,12 +80,12 @@ mod queuehasmpap {
7980
// If the key already exists, replace the previous value
8081
pub fn insert(&mut self, key: K, value: V) -> (usize, bool) {
8182
let hash = make_hash(&self.hash_builder, &key);
82-
if let Some(&idx) = self
83+
if let Some(idx) = self
8384
.table
84-
.get(hash, |other| self.items[other - self.popped].0 == key)
85+
.find(hash, |other| self.items[other - self.popped].0 == key)
8586
{
86-
self.items[idx - self.popped].1 = value;
87-
(idx, false)
87+
self.items[*idx - self.popped].1 = value;
88+
(*idx, false)
8889
} else {
8990
(self.insert_nocheck(hash, key, value), true)
9091
}
@@ -108,7 +109,7 @@ mod queuehasmpap {
108109
hash_builder,
109110
..
110111
} = self;
111-
table.insert(hash, item_index, |i| {
112+
table.insert_unique(hash, item_index, |i| {
112113
make_hash(hash_builder, &items[i - *popped].0)
113114
});
114115
self.items.push_back((key, value));
@@ -119,7 +120,7 @@ mod queuehasmpap {
119120
impl<K, V> Default for QueueHashMap<K, V> {
120121
fn default() -> Self {
121122
Self {
122-
table: RawTable::new(),
123+
table: HashTable::new(),
123124
hash_builder: DefaultHashBuilder::default(),
124125
items: VecDeque::new(),
125126
popped: 0,
@@ -132,7 +133,7 @@ mod queuehasmpap {
132133
}
133134
}
134135

135-
pub use queuehasmpap::QueueHashMap;
136+
pub use queuehashmap::QueueHashMap;
136137

137138
#[derive(Default)]
138139
/// Stores telemetry data item, like dependencies and integrations

0 commit comments

Comments
 (0)