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

HIVE-27317: Temporary (local) session files cleanup improvements #4403

Merged
merged 1 commit into from Jun 22, 2023

Conversation

sercanCyberVision
Copy link
Contributor

@sercanCyberVision sercanCyberVision commented Jun 10, 2023

Unit test in the initial solution caused regression to the successors unit tests as it creates scratch dirs without all writable permission. So the solution #4293 has been reverted here #4399.

What changes were proposed in this pull request?

Along with original solution, the unit test has been modified. Now, both scratch dirs have all writable permissions.

> ll ql/target/tmp
total 24
drwxrwxrwx  3 sercan sercan 4096 Jun 10 17:32 localscratchdir/
drwxrwxrwx  3 sercan sercan 4096 Jun 10 17:32 scratchdir/

How was this patch tested?

Unit test.

@deniskuzZ Could you please review?

// Note: Give scratch dirs all the write permissions
FsPermission allPermissions = new FsPermission((short)00777);
Path scratchDir = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.SCRATCHDIR));
Utilities.createDirsWithPermission(conf, scratchDir, allPermissions, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hdfs scratch dir is all writable.

Copy link
Member

Choose a reason for hiding this comment

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

could we please not use the default scratch dir in a test? create some temp one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@deniskuzZ good idea to avoid all the possible conflicts. The test has its own HiveConf, so I have set scratchdir properties as below;

String tmpDir = System.getProperty("test.tmp.dir");
conf.set("hive.exec.scratchdir", tmpDir + "/hive-27317-hdfsscratchdir");
conf.set("hive.exec.local.scratchdir", tmpDir + "/hive-27317-localscratchdir");

@veghlaci05 about deleting the files/dirs; as the both tmp dirs are specific to the test now, I have deleted the both of them after the test;

fs.delete(localTmpDir, true);
fs.delete(scratchDir, true);

The result is as expected, it creates specified tmp dirs;

> ll target/tmp/
drwxrwxrwx  3 sercan sercan 4096 Jun 12 09:22 hive-27317-hdfsscratchdir/
drwxrwxrwx  3 sercan sercan 4096 Jun 12 09:22 hive-27317-localscratchdir/

and deletes both of them after the test.

+ appId + "-started-with-session-name-but-fail-delete.pipeout");

// Create dirs/files
Utilities.createDirsWithPermission(conf, localSessionDir, allPermissions, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Local scratchdir is all writable.

@veghlaci05
Copy link
Contributor

Considering the previous issue, you should also add a teardown method to the test and delete all the created files and folders including the file with -r--r--r-- permissions (after restoring the permisson)

+ "' does not exist, should have not been removed!", fs.exists(localPipeOutFileFailRemove));

// Clean-up
fs.delete(localTmpDir, true);
Copy link
Member

Choose a reason for hiding this comment

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

should it be called within finally or in @after method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@deniskuzZ, I have declared the custom scratchdirs out of the test, and delete them in @AfterClass which is already existed.

Executed the whole test class, looks good;

[INFO] Running org.apache.hadoop.hive.ql.session.TestClearDanglingScratchDir
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 18.943 s - in org.apache.hadoop.hive.ql.session.TestClearDanglingScratchDir
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

@sonarcloud
Copy link

sonarcloud bot commented Jun 14, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@deniskuzZ deniskuzZ left a comment

Choose a reason for hiding this comment

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

+1 LGTM

@deniskuzZ deniskuzZ merged commit d31086c into apache:master Jun 22, 2023
5 checks passed
@sercanCyberVision sercanCyberVision deleted the HIVE-27317 branch June 24, 2023 04:54
yeahyung pushed a commit to yeahyung/hive that referenced this pull request Jul 20, 2023
tarak271 pushed a commit to tarak271/hive-1 that referenced this pull request Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants