You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jclouds.apache.org by Zack Shoylev <no...@github.com> on 2014/07/25 22:06:57 UTC

[jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

You can merge this Pull Request by running:

  git pull https://github.com/rackspace/jclouds filesystem-windows-fixes

Or you can view, comment on it, or merge it online at:

  https://github.com/jclouds/jclouds/pull/454

-- Commit Summary --

  * Fixes issues with deleting files and cleanup on windows.

-- File Changes --

    M apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java (16)
    M apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java (16)
    M apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java (40)
    M apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java (8)

-- Patch Links --

https://github.com/jclouds/jclouds/pull/454.patch
https://github.com/jclouds/jclouds/pull/454.diff

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Zack Shoylev <no...@github.com>.
Tests run: 121, Failures: 2, Errors: 0, Skipped: 81, Time elapsed: 5.004 sec <<< FAILURE! - in TestSuite
testDeleteContainer(org.jclouds.filesystem.FilesystemAsyncBlobStoreTest)  Time elapsed: 0.053 sec  <<< FAILURE!
java.lang.RuntimeException: java.io.IOException: Could not delete: .\target\basedir\fun-blobstore-test\ab123s
        at org.jclouds.filesystem.util.Utils.deleteRecursively(Utils.java:42)
        at org.jclouds.filesystem.util.Utils.deleteRecursively(Utils.java:37)
        at org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl.deleteDirectory(FilesystemStorageStrategyImpl.java:297)
        at org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl.deleteContainer(FilesystemStorageStrategyImpl.java:114)
        at org.jclouds.blobstore.LocalAsyncBlobStore.deleteAndVerifyContainerGone(LocalAsyncBlobStore.java:536)
        at org.jclouds.blobstore.LocalAsyncBlobStore.deleteContainer(LocalAsyncBlobStore.java:255)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.google.inject.internal.DelegatingInvocationHandler.invoke(DelegatingInvocationHandler.java:37)
        at com.sun.proxy.$Proxy43.deleteContainer(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.google.common.reflect.Invokable$MethodInvokable.invokeInternal(Invokable.java:197)
        at com.google.common.reflect.Invokable.invoke(Invokable.java:102)
        at org.jclouds.rest.internal.InvokeAndCallGetOnFutures.apply(InvokeAndCallGetOnFutures.java:67)
        at org.jclouds.rest.internal.InvokeAndCallGetOnFutures.apply(InvokeAndCallGetOnFutures.java:39)
        at org.jclouds.rest.internal.DelegatesToInvocationFunction.handle(DelegatesToInvocationFunction.java:156)
        at org.jclouds.rest.internal.DelegatesToInvocationFunction.invoke(DelegatesToInvocationFunction.java:123)
        at com.sun.proxy.$Proxy44.deleteContainer(Unknown Source)
        at org.jclouds.filesystem.FilesystemAsyncBlobStoreTest.testDeleteContainer(FilesystemAsyncBlobStoreTest.java:665)

tearDown(org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImplTest)  Time elapsed: 0.015 sec  <<< FAILURE!
java.io.IOException: Could not delete: .\target\basedir\funambol-test\clean_container-f776fcab-5262-421c-b4db-3f5714618d27.jpg
        at org.jclouds.filesystem.util.Utils.deleteRecursively(Utils.java:42)
        at org.jclouds.filesystem.util.Utils.deleteRecursively(Utils.java:37)
        at org.jclouds.filesystem.utils.TestUtils.cleanDirectoryContent(TestUtils.java:174)
        at org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImplTest.tearDown(FilesystemStorageStrategyImplTest.java:87)


Results :

Failed tests:
  FilesystemAsyncBlobStoreTest.testDeleteContainer:665 ╗ Runtime java.io.IOExcep...
  FilesystemStorageStrategyImplTest.tearDown:87 ╗ IO Could not delete: .\target\...

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50222211

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Gaul <no...@github.com>.
> @@ -38,8 +43,18 @@ public static void deleteRecursively(File file) throws IOException {
>              }
>           }
>        }
> -      if (!file.delete()) {
> -         throw new IOException("Could not delete: " + file);
> +
> +      /**
> +       * Java-6 Compatible version of handling non-empty directories and access-denied on windows.
> +       */
> +      if(!file.delete()){
> +         if(file.isDirectory() && file.listFiles().length > 0) {
> +            deleteRecursively(file);
> +         } else {
> +            Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
> +            if(!file.delete())
> +               file.deleteOnExit();

Why do you believe we need sleeps in our code?  Which test fails without this?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454/files#r15430004

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Phillips <no...@github.com>.
> @@ -30,6 +33,8 @@ private Utils() {
>  
>     /** Delete a file or a directory recursively. */
>     public static void deleteRecursively(File file) throws IOException {
> +      if(!file.exists())

[minor] Space before `(`

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454/files#r15473491

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Gaul <no...@github.com>.
I ran `mvn integration-test -pl :filesystem` on master 100 times without issue.  I used a Windows Server 2012 VM with Java 8 on an EC2 t2.micro instance.  Do you have a virus checker installed on your system?  These often hold handles on newly created files and I do not believe we should try to work around them this way.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50282414

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Gaul <no...@github.com>.
> @@ -293,6 +293,8 @@ public void createDirectory(String container, String directory) {
>     public void deleteDirectory(String container, String directory) {
>        // create complete dir path
>        String fullDirPath = buildPathStartingFromBaseDir(container, directory);
> +      if(!new File(fullDirPath).exists())
> +         throw new RuntimeException("Container does not exist");

Throw `ContainerNotFoundException` instead.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454/files#r15429990

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Zack Shoylev <no...@github.com>.
> since it improves the IOException by including the cause.
Exactly!

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50412983

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Zack Shoylev <no...@github.com>.
Hmm right. This does need Java 7.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50201401

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Zack Shoylev <no...@github.com>.
I have a pretty good idea of what the problems are, but not so much what is causing them.

1. Directory not empty exceptions (threading?)
2. Access denied exceptions (handle)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50222239

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Phillips <no...@github.com>.
> @@ -38,8 +43,18 @@ public static void deleteRecursively(File file) throws IOException {
>              }
>           }
>        }
> -      if (!file.delete()) {
> -         throw new IOException("Could not delete: " + file);
> +
> +      /**
> +       * Java-6 Compatible version of handling non-empty directories and access-denied on windows.

[minor] "Java 6-compatible"...?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454/files#r15473512

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-pull-requests #1030](https://jclouds.ci.cloudbees.com/job/jclouds-pull-requests/1030/) FAILURE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50201164

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-java-7-pull-requests #1504](https://jclouds.ci.cloudbees.com/job/jclouds-java-7-pull-requests/1504/) SUCCESS
This pull request looks good

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50213183

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds #1424](https://buildhive.cloudbees.com/job/jclouds/job/jclouds/1424/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50216405

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Gaul <no...@github.com>.
> Traced down to windows McAfee. My older AV didn't seem to cause this.
> I still would like to refactor this by switching to NIO, but will wait for after 1.8 is released.

We should replace all uses of `File.delete` with nio `Files.delete` since it improves the IOException by including the cause.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50382194

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Gaul <no...@github.com>.
> @@ -38,8 +43,18 @@ public static void deleteRecursively(File file) throws IOException {
>              }
>           }
>        }
> -      if (!file.delete()) {
> -         throw new IOException("Could not delete: " + file);
> +
> +      /**
> +       * Java-6 Compatible version of handling non-empty directories and access-denied on windows.
> +       */
> +      if(!file.delete()){
> +         if(file.isDirectory() && file.listFiles().length > 0) {

Not in Java 6.  Java 7 nio will allow us to improve the filesystem provider in a number of ways, including access to partial readdir.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454/files#r15482544

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Gaul <no...@github.com>.
This pull request reintroduces the hack from #217 where we sleep for some interval which I removed in #444.  I addressed a leaked file handle in #445 which caused previous failures; @zack-shoylev which symptom do you believe that sleeping addresses?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50216789

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Zack Shoylev <no...@github.com>.
Traced down to windows McAfee. My older AV didn't seem to cause this.
I still would like to refactor this by switching to NIO, but will wait for after 1.8 is released.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50377339

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Phillips <no...@github.com>.
> @@ -58,7 +58,7 @@
>  
>      /**
>       * Generate a random blob key simple name (with no path in the key)
> -     * @return 
> +     * @return

If we're going to change this...remove the line entirely, or add a valid comment? ;-)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454/files#r15473647

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Gaul <no...@github.com>.
Please share the exact test failures that you experienced.  I do not believe that we should commit fixes for problems that we do not understand.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50218563

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-java-7-pull-requests #1502](https://jclouds.ci.cloudbees.com/job/jclouds-java-7-pull-requests/1502/) UNSTABLE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50206177

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Zack Shoylev <no...@github.com>.
Closed #454.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#event-146372683

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Phillips <no...@github.com>.
> @@ -38,8 +43,18 @@ public static void deleteRecursively(File file) throws IOException {
>              }
>           }
>        }
> -      if (!file.delete()) {
> -         throw new IOException("Could not delete: " + file);
> +
> +      /**
> +       * Java-6 Compatible version of handling non-empty directories and access-denied on windows.
> +       */
> +      if(!file.delete()){
> +         if(file.isDirectory() && file.listFiles().length > 0) {

I'm guessing there's no cheaper way to determine if a directory is non-empty?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454/files#r15473617

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Zack Shoylev <no...@github.com>.
I will run some more tests first on different machines. Interesting idea about the virus scanner, will have to verify.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50359917

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds #1422](https://buildhive.cloudbees.com/job/jclouds/job/jclouds/1422/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50203834

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Phillips <no...@github.com>.
> @@ -38,8 +43,18 @@ public static void deleteRecursively(File file) throws IOException {
>              }
>           }
>        }
> -      if (!file.delete()) {
> -         throw new IOException("Could not delete: " + file);
> +
> +      /**
> +       * Java-6 Compatible version of handling non-empty directories and access-denied on windows.
> +       */
> +      if(!file.delete()){

On all these `if`s: space before `(`

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454/files#r15473547

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-pull-requests #1032](https://jclouds.ci.cloudbees.com/job/jclouds-pull-requests/1032/) UNSTABLE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50212813

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Zack Shoylev <no...@github.com>.
Most likely windows keeps a handle opened for a bit longer after a file is closed, or something similar.
Unfortunately without the fix I keep experiencing the issue on windows.

Note however, that no wait interval is needed with the nio fix (check the first commit). Once we switch to Java 7, we can refactor this code. Do you think this is a good workaround in the meantime?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454#issuecomment-50217587

Re: [jclouds] Fixes issues with deleting files and cleanup on windows. (#454)

Posted by Andrew Phillips <no...@github.com>.
>       * @param directoryName
>       * @throws IOException
>       */
>      public static void cleanDirectoryContent(String directoryName) throws IOException {
>          File parentDirectory = new File(directoryName);
> +       if(!parentDirectory.exists())

Space before `(`?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/454/files#r15473657