You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by eo...@apache.org on 2020/01/23 15:46:33 UTC

[zookeeper] branch master updated: ZOOKEEPER-1936: Server exits when unable to create data directory due to race

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

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


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

commit 689c8b2c4ed264f1dd75db7cbde1f86fe4408f50
Author: Andor Molnar <an...@apache.org>
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 <an...@apache.org>
    
    Reviewers: Enrico Olivelli <eo...@apache.org>
    
    Closes #1225 from anmolnar/ZOOKEEPER-1936
---
 .../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);
             }
         }