You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Bruno Freudensprung (JIRA)" <ji...@apache.org> on 2013/12/14 19:22:06 UTC

[jira] [Commented] (ZOOKEEPER-1835) dynamic configuration file renaming fails on Windows

    [ https://issues.apache.org/jira/browse/ZOOKEEPER-1835?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13848420#comment-13848420 ] 

Bruno Freudensprung commented on ZOOKEEPER-1835:
------------------------------------------------

I've discovered the existing org.apache.zookeeper.common.AtomicFileOutputStream class that precisely does this job (writing a temp file, then rename it, if failure on windows then delete and rename, delete the temp file...).
There is a kind of idiomatic usage described in org.apache.zookeeper.server.quorum.QuorumPeer.writeLongToFile(...), so I've created a org.apache.zookeeper.common.AtomicFileWritingIdiom class (using AtomicFileOutputStream) in order not to miss anything from the idiom, and used it org.apache.zookeeper.server.quorum.QuorumPeerConfig.
You will find attached a patch containing this new AtomicFileWritingIdiom class, a unit test for it, and the existing modified QuorumPeerConfig class.
I've run the ZK junit test suite that did not show any induced problem.
I've also tested the ZOOKEEPER-1691 patch in addition to this one, and I got my dynamic reconfig scenario working like described in https://issues.apache.org/jira/browse/ZOOKEEPER-1691
And I finally tested the configBackwardCompatibilityMode scenario where the dynamic config file gets created and the zoo.cfg file rewritten. It works too.
There is a small bug in the current implementation of the configBackwardCompatibilityMode though: even if the clientPort= line is mentioned the the zoo.cfg file, the port is not appended at the end of the line of the dynamic config. Don't know if it "deserves" a bug though. 

Bruno.

> dynamic configuration file renaming fails on Windows
> ----------------------------------------------------
>
>                 Key: ZOOKEEPER-1835
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1835
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: quorum
>    Affects Versions: 3.5.0
>         Environment: Windows 7 64-bit, Oracle Java  1.6.0_32-b05
>            Reporter: Bruno Freudensprung
>         Attachments: ZOOKEEPER-1835.patch
>
>
> On Windows, reconfig fails to rename the tmp dynamic config file to the real dynamic config filename.
> Javadoc of java.io.File.renameTo says the behavior is highly plateform dependent, so I guess this should not be a big surprise.
> The problem occurs in src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java that could be modified like this:
> + curFile.delete();
> if (!tmpFile.renameTo(curFile)) {
> + configFile.delete();
> if (!tmpFile.renameTo(configFile)) {
> As suggested by Alex in https://issues.apache.org/jira/browse/ZOOKEEPER-1691 (btw there is more information about my test scenario over there) it is a bit "scary" to delete the current configuration file.



--
This message was sent by Atlassian JIRA
(v6.1.4#6159)