This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch branch-3.6
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/branch-3.6 by this push:
     new 6495a7a  ZOOKEEPER-1936: Server exits when unable to create data 
directory due to race
6495a7a is described below

commit 6495a7afd2e69056331c2327585be3baff711013
Author: Andor Molnar <[email protected]>
AuthorDate: Thu Jan 23 16:46:28 2020 +0100

    ZOOKEEPER-1936: Server exits when unable to create data directory due to 
race
    
    Resurrecting an ancient ticket which could be fixed with a simple patch.
    
    Jira mentions a scenario when auto purging tool is in use and Zookeeper 
server could have a race condition when creating snapshot and data directories. 
(directory auto creating is enabled by default)
    
    Double checking the directory existence might help with it.
    
    Author: Andor Molnar <[email protected]>
    
    Reviewers: Enrico Olivelli <[email protected]>
    
    Closes #1225 from anmolnar/ZOOKEEPER-1936
    
    (cherry picked from commit 689c8b2c4ed264f1dd75db7cbde1f86fe4408f50)
    Signed-off-by: Enrico Olivelli <[email protected]>
---
 .../java/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
 
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
index 661beb2..b6014ef 100644
--- 
a/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
+++ 
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
@@ -132,7 +132,7 @@ public class FileTxnSnapLog {
                     ZOOKEEPER_DATADIR_AUTOCREATE));
             }
 
-            if (!this.dataDir.mkdirs()) {
+            if (!this.dataDir.mkdirs() && !this.dataDir.exists()) {
                 throw new DatadirException("Unable to create data directory " 
+ this.dataDir);
             }
         }
@@ -151,7 +151,7 @@ public class FileTxnSnapLog {
                     ZOOKEEPER_DATADIR_AUTOCREATE));
             }
 
-            if (!this.snapDir.mkdirs()) {
+            if (!this.snapDir.mkdirs() && !this.snapDir.exists()) {
                 throw new DatadirException("Unable to create snap directory " 
+ this.snapDir);
             }
         }

Reply via email to