Skip to content

Conversation

@yjshen
Copy link
Member

@yjshen yjshen commented Aug 31, 2023

Which issue does this PR close?

re #7424.

Rationale for this change

Find the memory pool size setting string in datafusion-cli during performance testing, and we could make the byte string more flexible.

What changes are included in this PR?

Parse the pool byte string as the number of bytes.

Are these changes tested?

Add unit test and tested locally.

Are there any user-facing changes?

No.

"-100",
Err("Negative memory pool size value is not allowed '-100'".to_string()),
);

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert_conversion(
"12k12k",
Err("Invalid memory pool size '12k12k'".to_string()),
);

Copy link
Member

Choose a reason for hiding this comment

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

This case should have failed, but it passed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if I understand you correctly. Do you mean the case "-100" shouldn't fail with the Err "Negative memory pool size value is not allowed '-100'"?

Copy link
Member

Choose a reason for hiding this comment

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

No, we should add a test for cases like 12k12k .

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! Fixed in the latest commit.

Comment on lines 256 to 275
#[derive(Debug, Clone, Copy)]
enum ByteUnit {
Byte,
KiB,
MiB,
GiB,
TiB,
}

impl ByteUnit {
fn multiplier(&self) -> usize {
match self {
ByteUnit::Byte => 1,
ByteUnit::KiB => 1 << 10,
ByteUnit::MiB => 1 << 20,
ByteUnit::GiB => 1 << 30,
ByteUnit::TiB => 1 << 40,
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Nice refactor 👍

Comment on lines 303 to 313
if num_str.starts_with('-') {
return Err(format!(
"Negative memory pool size value is not allowed '{}'",
size
));
}

let num = num_str.parse::<usize>().map_err(|_| {
format!("Invalid numeric value in memory pool size '{}'", size)
})?;

Copy link
Member

Choose a reason for hiding this comment

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

Can we simplify this? If num is of type usize, then it is guaranteed to be a positive value.

Copy link
Member Author

@yjshen yjshen Aug 31, 2023

Choose a reason for hiding this comment

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

We need to guard against values larger than usize::MAX?

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if num_str.starts_with('-') {
return Err(format!(
"Negative memory pool size value is not allowed '{}'",
size
));
}
let num = num_str.parse::<usize>().map_err(|_| {
format!("Invalid numeric value in memory pool size '{}'", size)
})?;
let num = num_str.parse::<usize>().map_err(|_| {
format!("Negative memory pool size value is not allowed '{}'", size)
})?;

Sorry for the confusion, could we test for negative numbers like this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no strong opinion on this.
I changed the code above to parse numeric directly to usize for simplicity as suggested, but the caveat is the new error message is less informative, which I suppose should be fine in this case.

Copy link
Member

@Weijun-H Weijun-H left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks really nice to me -- thank you @yjshen and @Weijun-H ❤️

@alamb alamb merged commit c4a6185 into apache:main Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants