Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: update toolchain to nightly-2024-04-18 #3740

Merged
merged 9 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 12 additions & 9 deletions src/common/meta/src/state_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use common_procedure::store::util::multiple_value_stream;
use common_procedure::Result as ProcedureResult;
use futures::future::try_join_all;
use futures::StreamExt;
use itertools::Itertools;
use snafu::ResultExt;

use crate::error::Result;
Expand Down Expand Up @@ -79,19 +80,21 @@ fn decode_kv(kv: KeyValue) -> Result<(String, Vec<u8>)> {
Ok((key, value))
}

// Override warnings that those fields are not accessed.
#[allow(dead_code)]
enum SplitValue<'a> {
Single(&'a [u8]),
Multiple(Vec<&'a [u8]>),
enum SplitValue {
Single(Vec<u8>),
Multiple(Vec<Vec<u8>>),
}

fn split_value(value: &[u8], max_value_size: Option<usize>) -> SplitValue<'_> {
fn split_value(value: Vec<u8>, max_value_size: Option<usize>) -> SplitValue {
if let Some(max_value_size) = max_value_size {
if value.len() <= max_value_size {
SplitValue::Single(value)
} else {
SplitValue::Multiple(value.chunks(max_value_size).collect::<Vec<_>>())
let mut values = vec![];
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
for chunk in value.into_iter().chunks(max_value_size).into_iter() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@WenyXu Will this introduce additional allocations? The original SplitValue holds Vec<&[u8]>.

Copy link
Contributor

@tisonkun tisonkun Apr 19, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

We move the bytes here. Previously it uses a ref but we can actually take the ownership. This calls delegate to itertools IntoChunks, not the slice's chunks that may clone.

values.push(chunk.collect());
}
SplitValue::Multiple(values)
}
} else {
SplitValue::Single(value)
Expand All @@ -101,10 +104,10 @@ fn split_value(value: &[u8], max_value_size: Option<usize>) -> SplitValue<'_> {
#[async_trait]
impl StateStore for KvStateStore {
async fn put(&self, key: &str, value: Vec<u8>) -> ProcedureResult<()> {
let split = split_value(&value, self.max_value_size);
let split = split_value(value, self.max_value_size);
let key = with_prefix(key);
match split {
SplitValue::Single(_) => {
SplitValue::Single(value) => {
self.kv_backend
.put(
PutRequest::new()
Expand Down
10 changes: 4 additions & 6 deletions src/common/procedure/src/local/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@ use std::sync::{Arc, Mutex};

use tokio::sync::{OwnedRwLockReadGuard, OwnedRwLockWriteGuard, RwLock};

// Override warnings that those fields are not accessed.
#[allow(dead_code)]
pub enum OwnedKeyRwLockGuard {
Read(OwnedRwLockReadGuard<()>),
Write(OwnedRwLockWriteGuard<()>),
Read { _guard: OwnedRwLockReadGuard<()> },
Write { _guard: OwnedRwLockWriteGuard<()> },
}

impl From<OwnedRwLockReadGuard<()>> for OwnedKeyRwLockGuard {
fn from(guard: OwnedRwLockReadGuard<()>) -> Self {
OwnedKeyRwLockGuard::Read(guard)
OwnedKeyRwLockGuard::Read { _guard: guard }
}
}

impl From<OwnedRwLockWriteGuard<()>> for OwnedKeyRwLockGuard {
fn from(guard: OwnedRwLockWriteGuard<()>) -> Self {
OwnedKeyRwLockGuard::Write(guard)
OwnedKeyRwLockGuard::Write { _guard: guard }
}
}

Expand Down