Skip to content

refactor: replace tempdir with tempfile#1123

Merged
evenyag merged 6 commits intoGreptimeTeam:developfrom
etolbakov:refactor/replace-tempdir-with-tempfile
Mar 8, 2023
Merged

refactor: replace tempdir with tempfile#1123
evenyag merged 6 commits intoGreptimeTeam:developfrom
etolbakov:refactor/replace-tempdir-with-tempfile

Conversation

@etolbakov
Copy link
Copy Markdown
Collaborator

I hereby agree to the terms of the GreptimeDB CLA

What's changed and what's your intention?

  • All usages of tempdir were replaced with tempfile.
  • tempdir has been removed from dependencies.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.

Refer to a related PR or issue link (optional)

#1108

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 3, 2023

Codecov Report

Merging #1123 (f761030) into develop (bd065ea) will increase coverage by 0.03%.
The diff coverage is 100.00%.

❗ Current head f761030 differs from pull request most recent head 5dceed2. Consider uploading reports for the commit 5dceed2 to get more accurate results

@@             Coverage Diff             @@
##           develop    #1123      +/-   ##
===========================================
+ Coverage    85.02%   85.06%   +0.03%     
===========================================
  Files          474      476       +2     
  Lines        69073    69877     +804     
===========================================
+ Hits         58732    59442     +710     
- Misses       10341    10435      +94     

@etolbakov
Copy link
Copy Markdown
Collaborator Author

Hi @evenyag
Could you please take a look when you have time?

Copy link
Copy Markdown
Member

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

Great job, thanks a lot. Prefer moving the tempfile to the workspace's cargo.toml and refer it in every crate.

Comment thread src/common/catalog/Cargo.toml Outdated
@Jay-0331
Copy link
Copy Markdown

Jay-0331 commented Mar 5, 2023

@etolbakov Hey a quick suggestion. Not sure if it is possible but I can see you have created a single function in some files can't we have a global file for the function and import it to other files and won't it be easier to modify in the future?

@etolbakov
Copy link
Copy Markdown
Collaborator Author

Hey @Jay-0331
Thanks for your feedback!
When I was working on this issue I had the same idea.
However, I'm relatively new to the codebase so if you could suggest what would be the best place for that function to be it would be great!
Maybe somewhere in src/common...

@Jay-0331
Copy link
Copy Markdown

Jay-0331 commented Mar 5, 2023

@etolbakov I am also new to the code actually 😅 but i was also finding the place where we can put the function came across the same folder src/common maybe @killme2008 could have a better idea on this

@killme2008
Copy link
Copy Markdown
Member

I think we can put the create_tmp_dir in the common/base crate. What do you think? @evenyag

Copy link
Copy Markdown
Member

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

Almost LGTM. Only a little suggestion. Thanks.

Comment thread Cargo.toml Outdated
@waynexia
Copy link
Copy Markdown
Member

waynexia commented Mar 6, 2023

I think we can put the create_tmp_dir in the common/base crate. What do you think? @evenyag

common/base looks good to me. But to do so we need first add a feature gate to common/base, like the test feature in mito/Cargo.toml.

After this we need not depend on tempfile for every sub-crate but refer to the function in common/base.

Copy link
Copy Markdown
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

Comment thread src/mito/Cargo.toml Outdated
Comment thread src/mito/Cargo.toml Outdated
@evenyag
Copy link
Copy Markdown
Contributor

evenyag commented Mar 6, 2023

we need first add a feature gate to common/base, like the test feature in mito/Cargo.toml.

+1 for this.

@etolbakov
Copy link
Copy Markdown
Collaborator Author

Thanks for the hint, will give it a. try with test feature today

@etolbakov
Copy link
Copy Markdown
Collaborator Author

@evenyag
In order to reuse the create_tmp_dir function I plan to create the file common/base/src (f.e. temp_dir.rs) and make a corresponding change in common/base/src/lib.rs.
Once I'll make it, I can reference this function in other places like:
use common_base::temp_dir::create_tmp_dir;
Not sure I understood the necessity of the feature gate. Am I missing something?

@evenyag
Copy link
Copy Markdown
Contributor

evenyag commented Mar 6, 2023

@evenyag In order to reuse the create_tmp_dir function I plan to create the file common/base/src (f.e. temp_dir.rs) and make a corresponding change in common/base/src/lib.rs. Once I'll make it, I can reference this function in other places like: use common_base::temp_dir::create_tmp_dir; Not sure I understood the necessity of the feature gate. Am I missing something?

We don't want to

  • import tempfile in non-tests dependencies (only in dev-dependencies)
  • expose test utils in public API

This is similar to the A test-only module method in this answer
https://stackoverflow.com/questions/44539729/what-is-an-idiomatic-way-to-have-shared-utility-functions-for-integration-tests

Another way is adding a new crate (maybe common/test-util) for test utilities. We could pub use tempfile in this crate. Looks like this is a recommended way.

@etolbakov
Copy link
Copy Markdown
Collaborator Author

@evenyag
I decided to go with the common/test-util approach. Could you please take a look when you have time?
Especially at log-store changes.
The only outstanding thing at the moment is mito as it uses the test-util in dependencies. Could you please give me a hint about if anything could be done there?

Copy link
Copy Markdown
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

You could re-export Tempdir in common-test-util. Then most crates don't need to import tempfile anymore.

Especially at log-store changes.

I'm ok with this. @v0y4g3r PTAL

Comment thread src/common/test-util/src/temp_dir.rs Outdated
Comment thread Cargo.toml Outdated
Comment thread src/catalog/Cargo.toml Outdated
Comment thread src/catalog/src/system.rs Outdated
Comment thread src/catalog/src/system.rs Outdated
Comment thread src/mito/Cargo.toml Outdated
Comment thread src/mito/Cargo.toml Outdated
@etolbakov
Copy link
Copy Markdown
Collaborator Author

@evenyag
I've made changes according to your suggestions, could you please have a look?
Btw, do not hesitate to add "nitpick" type of comments, I'm comfortable with that and I'm learning from you guys!

As far as I understood my build failed due to #1136

@killme2008
Copy link
Copy Markdown
Member

@evenyag PTAL

Copy link
Copy Markdown
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

LGTM

@evenyag
Copy link
Copy Markdown
Contributor

evenyag commented Mar 8, 2023

Thanks for your patience! ❤️

Since the failed test should be unrelated to this PR, I plan to merge it now. @killme2008

@evenyag evenyag merged commit b31a6cb into GreptimeTeam:develop Mar 8, 2023
@etolbakov etolbakov deleted the refactor/replace-tempdir-with-tempfile branch March 8, 2023 06:49
paomian pushed a commit to paomian/greptimedb that referenced this pull request Oct 19, 2023
* refactor: replace tempdir with tempfile

* refactor(query): move tempfile dependency under the workspace's Cargo.toml

* refactor(tempfile): create common-test-util

* refactor(tempfile): fix toml format

* refactor(tempfile): remove tempfile out of dependencies

* refactor(tempfile): fix incorrect toml
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.

5 participants