Skip to content

Commit

Permalink
*: upgrade drain_filter
Browse files Browse the repository at this point in the history
See rust-lang/rust/pull/104455

Signed-off-by: Neil Shen <[email protected]>
  • Loading branch information
overvenus committed Dec 15, 2023
1 parent bb5f31e commit cb56470
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion components/engine_traits/src/flush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl SstApplyState {
for sst in ssts {
let cf_index = data_cf_offset(sst.get_cf_name());
if let Some(metas) = sst_list.get_mut(cf_index) {
metas.drain_filter(|entry| entry.sst.get_uuid() == sst.get_uuid());
metas.retain(|entry| entry.sst.get_uuid() != sst.get_uuid());
}
}
}
Expand Down
1 change: 0 additions & 1 deletion components/engine_traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@
#![feature(linked_list_cursors)]
#![feature(let_chains)]
#![feature(str_split_as_str)]
#![feature(drain_filter)]

#[macro_use(fail_point)]
extern crate fail;
Expand Down
2 changes: 1 addition & 1 deletion components/raftstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![feature(div_duration)]
#![feature(min_specialization)]
#![feature(box_patterns)]
#![feature(hash_drain_filter)]
#![feature(hash_extract_if)]
#![feature(let_chains)]
#![feature(assert_matches)]
#![feature(type_alias_impl_trait)]
Expand Down
2 changes: 1 addition & 1 deletion components/raftstore/src/store/snap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@ impl TabletSnapManager {
.stats
.lock()
.unwrap()
.drain_filter(|_, (_, stat)| stat.get_region_id() > 0)
.extract_if(|_, (_, stat)| stat.get_region_id() > 0)
.map(|(_, (_, stat))| stat)
.filter(|stat| stat.get_total_duration_sec() > 1)
.collect();
Expand Down
4 changes: 2 additions & 2 deletions components/raftstore/src/store/txn_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub struct PeerPessimisticLocks {
/// likely to be proposed successfully, while the leader will need at
/// least another round to receive the transfer leader message from the
/// transferee.
///
///
/// - Split region The lock with the deleted mark SHOULD be moved to new
/// regions on region split. Considering the following cases with
/// different orders: 1. Propose write -> propose split -> apply write ->
Expand Down Expand Up @@ -244,7 +244,7 @@ impl PeerPessimisticLocks {
// Locks that are marked deleted still need to be moved to the new regions,
// and the deleted mark should also be cleared.
// Refer to the comment in `PeerPessimisticLocks` for details.
let removed_locks = self.map.drain_filter(|key, _| {
let removed_locks = self.map.extract_if(|key, _| {
let key = &**key.as_encoded();
let (start_key, end_key) = (derived.get_start_key(), derived.get_end_key());
key < start_key || (!end_key.is_empty() && key >= end_key)
Expand Down
2 changes: 1 addition & 1 deletion components/resource_metering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// TODO(mornyx): crate doc.

#![feature(hash_drain_filter)]
#![feature(hash_extract_if)]
#![feature(core_intrinsics)]

use std::{
Expand Down
2 changes: 1 addition & 1 deletion components/resource_metering/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl RawRecords {
pdqselect::select_by(&mut buf, k, |a, b| b.cmp(a));
let kth = buf[k];
// Evict records with cpu time less or equal than `kth`
let evicted_records = self.records.drain_filter(|_, r| r.cpu_time <= kth);
let evicted_records = self.records.extract_if(|_, r| r.cpu_time <= kth);
// Record evicted into others
for (_, record) in evicted_records {
others.merge(&record);
Expand Down
16 changes: 8 additions & 8 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ impl<T: ConfigurableDb + Send + Sync> ConfigManager for DbConfigManger<T> {
self.cfg.update(change.clone())?;
let change_str = format!("{:?}", change);
let mut change: Vec<(String, ConfigValue)> = change.into_iter().collect();
let cf_config = change.drain_filter(|(name, _)| name.ends_with("cf"));
let cf_config = change.extract_if(|(name, _)| name.ends_with("cf"));
for (cf_name, cf_change) in cf_config {
if let ConfigValue::Module(mut cf_change) = cf_change {
// defaultcf -> default
Expand Down Expand Up @@ -2098,7 +2098,7 @@ impl<T: ConfigurableDb + Send + Sync> ConfigManager for DbConfigManger<T> {
}

if let Some(rate_bytes_config) = change
.drain_filter(|(name, _)| name == "rate_bytes_per_sec")
.extract_if(|(name, _)| name == "rate_bytes_per_sec")
.next()
{
let rate_bytes_per_sec: ReadableSize = rate_bytes_config.1.into();
Expand All @@ -2107,7 +2107,7 @@ impl<T: ConfigurableDb + Send + Sync> ConfigManager for DbConfigManger<T> {
}

if let Some(rate_bytes_config) = change
.drain_filter(|(name, _)| name == "rate_limiter_auto_tuned")
.extract_if(|(name, _)| name == "rate_limiter_auto_tuned")
.next()
{
let rate_limiter_auto_tuned: bool = rate_bytes_config.1.into();
Expand All @@ -2116,30 +2116,30 @@ impl<T: ConfigurableDb + Send + Sync> ConfigManager for DbConfigManger<T> {
}

if let Some(size) = change
.drain_filter(|(name, _)| name == "write_buffer_limit")
.extract_if(|(name, _)| name == "write_buffer_limit")
.next()
{
let size: ReadableSize = size.1.into();
self.db.set_flush_size(size.0 as usize)?;
}

if let Some(f) = change
.drain_filter(|(name, _)| name == "write_buffer_flush_oldest_first")
.extract_if(|(name, _)| name == "write_buffer_flush_oldest_first")
.next()
{
self.db.set_flush_oldest_first(f.1.into())?;
}

if let Some(background_jobs_config) = change
.drain_filter(|(name, _)| name == "max_background_jobs")
.extract_if(|(name, _)| name == "max_background_jobs")
.next()
{
let max_background_jobs: i32 = background_jobs_config.1.into();
self.update_background_cfg(max_background_jobs, self.cfg.max_background_flushes)?;
}

if let Some(background_subcompactions_config) = change
.drain_filter(|(name, _)| name == "max_sub_compactions")
.extract_if(|(name, _)| name == "max_sub_compactions")
.next()
{
let max_subcompactions: u32 = background_subcompactions_config.1.into();
Expand All @@ -2148,7 +2148,7 @@ impl<T: ConfigurableDb + Send + Sync> ConfigManager for DbConfigManger<T> {
}

if let Some(background_flushes_config) = change
.drain_filter(|(name, _)| name == "max_background_flushes")
.extract_if(|(name, _)| name == "max_background_flushes")
.next()
{
let max_background_flushes: i32 = background_flushes_config.1.into();
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#![feature(proc_macro_hygiene)]
#![feature(min_specialization)]
#![feature(box_patterns)]
#![feature(drain_filter)]
#![feature(extract_if)]
#![feature(deadline_api)]
#![feature(let_chains)]
#![feature(read_buf)]
Expand Down

0 comments on commit cb56470

Please sign in to comment.