Skip to content

[feat] Introduce cacheManager in session ctx and make StatisticsCache share in session - #7570

Merged
Ted-Jiang merged 15 commits into
apache:mainfrom
Ted-Jiang:cache
Sep 18, 2023
Merged

[feat] Introduce cacheManager in session ctx and make StatisticsCache share in session#7570
Ted-Jiang merged 15 commits into
apache:mainfrom
Ted-Jiang:cache

Conversation

@Ted-Jiang

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes#7556 .

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actionsgithub-actionsBot added the core Core DataFusion crate label Sep 15, 2023
Comment threaddatafusion/core/src/datasource/listing/table.rs

#[tokio::test]
async fn load_table_stats_with_session_level_cache() -> Result<()> {
let testdata = crate::test_util::parquet_test_data();

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Add test to check cache share in session level

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice -- thank you. Since this is an end to end test, I recommend moving it to somewhere in core_integration: datafusion/core/tests/core_integration.rs perhaps

Comment threaddatafusion/execution/src/cache/cache_manager.rs Outdated
Comment threaddatafusion/execution/src/cache/cache_unit.rs

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @Ted-Jiang -- this is looking really nice. I left some various clean up comments but I think this PR looks very nice and is well commented and structured 🏆

Comment threaddatafusion/execution/src/cache/mod.rs Outdated
// The cache accessor, users usually working on this interface while manipulating caches
pub trait CacheAccessor<K, V>: Send + Sync {
// Extra info but not part of the cache key or cache value.
type Extra: Clone;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you explain what the usecase for Extra is? Specifically I wonder why such information could not be added as a field to the Value

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Like in default FileStatisticsCache, get func need check last_modified from ObjectMeta which not impl Hash so can not be part of the key, we need put this info in Extra.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see -- that makes sense -- it might help to document the rationale in statistics

}

/// Get `Statistics` for file location. Returns None if file has changed or not found.
fn get_with_extra(&self, k: &Path, e: &Self::Extra) -> Option<Statistics> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as written this is going to copy the statistics (though I realize that is what this PR did previously) -- maybe we could use something like Arc<Statistics> to store the statistics.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes , thanks for point this out

Comment threaddatafusion/core/src/datasource/listing/table.rs Outdated

#[tokio::test]
async fn load_table_stats_with_session_level_cache() -> Result<()> {
let testdata = crate::test_util::parquet_test_data();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice -- thank you. Since this is an end to end test, I recommend moving it to somewhere in core_integration: datafusion/core/tests/core_integration.rs perhaps

Comment threaddatafusion/execution/src/cache/cache_manager.rs Outdated
}

impl CacheManagerConfig {
pub fn enable_table_files_statistics_cache(mut self, cache: FileStaticCache) -> Self {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we possibly have the field names match -- here it is called table_files_statistics_cache but on the CacheManager it is called file_statistics_cache -- I think they should be the same in both places (I like file_statistics_cache best as it matches the type name)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

ops, this make sense

pub mod cache_unit;

// The cache accessor, users usually working on this interface while manipulating caches
pub trait CacheAccessor<K, V>: Send + Sync {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another classic API to add here would be "clear()" to clear all the values

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

need this

Comment threaddatafusion/execution/src/cache/mod.rs Outdated
.with_schema(resolved_schema);
let table =
ListingTable::try_new(config)?.with_definition(cmd.definition.clone());
let provider;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you implement the with_cache API, this can look like

let provider = ListingTable::try_new(config)?
.with_cache(state.runtime_env().cache_manager.get_file_statistic_cache())

@Ted-JiangTed-JiangSep 16, 2023

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

More clear way ! 👍

Ted-Jiangand others added 4 commits September 16, 2023 09:08
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
@Ted-Jiang

Copy link
Copy Markdown
MemberAuthor

@alamb PTAL

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @Ted-Jiang -- I think this looks great -- I had a suggestion to improve the comments but I think we can do that as a follow on PR as well. Nice work!

Comment threaddatafusion/core/src/datasource/listing/table.rs Outdated
use tempfile::NamedTempFile;

mod custom_reader;
mod file_statistics;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@alamb

alamb commented Sep 17, 2023

Copy link
Copy Markdown
Contributor

cc @Dandandan / @thinkharderdev@liukun4515 and @mateuszkj who appears to have added this feature originally in 85c11c1 / #3649

Comment threaddatafusion/execution/src/cache/mod.rs

@liukun4515liukun4515 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM for file statistics trait api

Ted-Jiangand others added 2 commits September 18, 2023 10:33
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
@Ted-Jiang
Ted-Jiang merged commit 678d27a into apache:mainSep 18, 2023
@Ted-Jiang

Copy link
Copy Markdown
MemberAuthor

@alamb@liukun4515 Thanks for the review.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coreCore DataFusion crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make StatisticsCache share in session level

3 participants

@Ted-Jiang@alamb@liukun4515