Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Jan 25, 2022

Which issue does this PR close?

Closes #1679

Rationale for this change

  1. Using String for temporary files leaves the files around longer than necessary, and would cause trouble with a long lived DiskManager across plans.
  2. Using the existing tempfile crate in rust is likely to work better across operating systems than DataFusion specific tempfile creation logic

What changes are included in this PR?

  1. DiskManager passes out NamedTempFiles rather than String (when these are dropped they also clean up the temp file immediately)
  2. Update users to use NamedTempFiles

Are there any user-facing changes?

No

@alamb alamb added the api change Changes the API exposed to users of the crate label Jan 25, 2022
@alamb
Copy link
Contributor Author

alamb commented Jan 25, 2022

cc @yjshen

path.push(file_name);
path.to_str().unwrap().to_string()
}
fn create_tmp_file(local_dirs: &[TempDir]) -> Result<NamedTempFile> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

tempfiles are now generated using tempfile rather than string manipulation


fn read_spill_as_stream(
path: String,
path: NamedTempFile,
Copy link
Contributor Author

@alamb alamb Jan 25, 2022

Choose a reason for hiding this comment

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

Since ownership of NamedTempFile is passed into the actual task doing the reading, when it is done, the temp file is cleaned up 🧹

Copy link
Contributor

@liukun4515 liukun4515 left a comment

Choose a reason for hiding this comment

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

nice work and great explanation
LGTM

@alamb alamb merged commit bffa5e4 into apache:master Jan 26, 2022
@alamb alamb removed the api change Changes the API exposed to users of the crate label Feb 10, 2022
@alamb alamb deleted the alamb/clean_up_tempfiles branch August 8, 2023 20:12
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.

DiskManager keeps temporary files around until the manager itself is dropped

4 participants