sercanCyberVision commented on code in PR #4293:
URL: https://github.com/apache/hive/pull/4293#discussion_r1219660255


##########
ql/src/test/org/apache/hadoop/hive/ql/cleanup/TestCleanupService.java:
##########
@@ -77,6 +83,54 @@ public void 
testEventualCleanupService_finishesCleanupBeforeExit() throws IOExce
     assertTrue(cleanupService.await(1, TimeUnit.MINUTES));
   }
 
+  /**
+   * Testing behaviour of ClearDanglingScratchDir service over local tmp 
files/dirs
+   * @throws Exception
+   */
+  @Test
+  public void localDanglingFilesCleaning() throws Exception {
+    HiveConf conf = new HiveConf();
+    conf.set("fs.default.name", "file:///");
+    FileSystem fs = FileSystem.get(conf);
+
+    // constants
+    String appId = "appId_" + System.currentTimeMillis();
+    String userName = System.getProperty("user.name");
+    String hdfs = "hdfs";
+    String inuse = "inuse.lck";
+    String l = File.separator;
+
+    // simulating hdfs dangling dir and its inuse.lck file
+    Path hdfsRootDir = new Path( HiveConf.getVar(conf, 
HiveConf.ConfVars.SCRATCHDIR) + l + userName + l + hdfs);
+    Path hdfsSessionDir = new Path(hdfsRootDir + l + userName + l + appId);
+    Path hdfsSessionLock = new Path(hdfsSessionDir + l + inuse);
+    fs.create(hdfsSessionLock);
+
+    // simulating local dangling files
+    String localTmpDir = HiveConf.getVar(conf, 
HiveConf.ConfVars.LOCALSCRATCHDIR);
+    Path localSessionDir = new Path(localTmpDir + l + appId);
+    Path localPipeOutFileRemove = new Path(localTmpDir + l
+            + appId + "-started-with-session-name.pipeout");
+    Path localPipeOutFileNotRemove = new Path(localTmpDir + l
+            + "not-started-with-session-name" + appId + ".pipeout");
+    fs.mkdirs(localSessionDir);
+    fs.create(localPipeOutFileRemove);
+    fs.create(localPipeOutFileNotRemove);
+
+    // running only the new method, the main service will be identifying which 
session files/dirs are dangling
+    ClearDanglingScratchDir clearDanglingScratchDirMain = new 
ClearDanglingScratchDir(false,
+            false, true, hdfsRootDir.toString(), conf);
+    clearDanglingScratchDirMain.run();
+
+    // should remove all except localPipeOutFileNotRemove, because it does not 
start with session name
+    Assert.assertFalse("Local session dir '" + localSessionDir
+            + "' still exists, should have been removed!", 
fs.exists(localSessionDir));
+    Assert.assertFalse("Local .pipeout file '" + localPipeOutFileRemove
+            + "' still exists, should have been removed!", 
fs.exists(localPipeOutFileRemove));
+    Assert.assertTrue("Local .pipeout file '" + localPipeOutFileNotRemove
+            + "' does not exist, should have not been removed!", 
fs.exists(localPipeOutFileNotRemove));

Review Comment:
   So, now we have in total 3 files/dirs;
   1. Local scratch dir belongs to session (starts with session name).
   2. `.pipeout` file belongs to session (starts with session name).
   3. `.pipeout` file does not belong to session (does not start with session 
name).
   
   Before the service is executed;
   
![before](https://github.com/apache/hive/assets/73108963/62fac8df-4886-4c14-9743-4016a7ff1608)
   After the service is executed;
   
![after](https://github.com/apache/hive/assets/73108963/478a5b34-3b5b-4dda-8542-1640a33fa6f8)
   
   At the end, we check all three files, assert if file/dir #1 and #2 still 
exist, or #3 does not exist.
   Is this sufficient?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to