<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Josh Slocum on Medium]]></title>
        <description><![CDATA[Stories by Josh Slocum on Medium]]></description>
        <link>https://medium.com/@jmslocum16?source=rss-2d96250be267------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*dA_e_yr5a-wz42Bg</url>
            <title>Stories by Josh Slocum on Medium</title>
            <link>https://medium.com/@jmslocum16?source=rss-2d96250be267------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 12:58:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jmslocum16/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Idempotent Fault-Tolerant Writes in Curator 5.2.0]]></title>
            <link>https://medium.com/@jmslocum16/idempotent-fault-tolerant-writes-in-curator-5-2-0-eadf7c12c814?source=rss-2d96250be267------2</link>
            <guid isPermaLink="false">https://medium.com/p/eadf7c12c814</guid>
            <category><![CDATA[apache-zookeeper]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[distributed-computing]]></category>
            <category><![CDATA[apache-curator]]></category>
            <dc:creator><![CDATA[Josh Slocum]]></dc:creator>
            <pubDate>Tue, 03 Aug 2021 22:05:02 GMT</pubDate>
            <atom:updated>2021-08-03T22:05:02.168Z</atom:updated>
            <content:encoded><![CDATA[<p>The Apache Curator 5.2.0 Release adds the <em>idempotent</em> modifier for write operations (Create, SetData, Delete). With this modifier, writes will succeed for multiple writers if they all perform the same operation on the same ZNode, and can be retried appropriately on ConnectionLoss/Timeout. This allows Curator users to build higher-level recipes and applications that use zookeeper without having to deal with the transient errors inherent in ZooKeeper’s data model.</p><p><a href="https://issues.apache.org/jira/browse/CURATOR-584">JIRA Issue</a></p><p><a href="https://github.com/apache/curator/pull/376">Pull Request</a></p><p><a href="https://zookeeper.apache.org/doc/r3.7.0/zookeeperProgrammers.html">Guide on ZooKeeper’s Data and Connection model</a></p><h3>Multiple Clients</h3><p>Consider the case where two clients want to create the same ZNode with the same data.</p><p>If each client issued these writes normally, because zookeeper has versioned and totally ordered operations, one client’s request would successfully create the node, and the other client’s request would fail with a <em>NODE_EXISTS</em> error.</p><p>If the clients didn’t care about which one successfully created the node, just that it was created with the given data, then they could use idempotent mode. In this mode, the second client’s request would, upon getting the <em>NODE_EXISTS</em> error, check the state of the znode. If the version of the created znode was 0, and the node’s data was equivalent to the data the client passed to create(), it would return success instead of <em>NODE_EXISTS</em>.</p><h3>Retrying Writes</h3><p>Consider the case where a single client wants to create a node with specified data, but due to network connectivity issues, the initial request returns with a CONNECTION_LOSS or TIMEOUT error. When this happens, the client can’t know if the request succeeded or not.</p><p>So, the client retries the create again.</p><p>If it succeeds, it’s possible the initial write didn’t go through, and the second one succeeded. But it’s also possible that someone else created the node, deleted it, and the second write succeeded.</p><p>If it fails due to NODE_EXISTS, it’s possible that someone else created the node, but it’s also possible its initial write succeeded, and the retried one failed because the node already existed after the initial write.</p><p>So again, in this case, idempotent writes can help. If all this client cares about is that the node <em>ends up in the state</em> where the node exists with the data it passed to create, and doesn’t care what happened before, then using the idempotent mode would succeed either if the retried write was successful, or if the retried write got NODE_EXISTS, the znode version was zero, and the data in the znode matched the data in the create request.</p><h3>A Practical Example (Distributed Locks)</h3><p>Imagine we want to use zookeeper to implement a distributed lock or distributed lease.</p><p>We do this by having each client create a zookeeper ephemeral node for the lock at a pre-agreed upon path, with its processId as the data in the node (so that each client has a unique write value).</p><p>Process A does create(lockNode, “A”). Its initial write fails due to CONNECTION_LOSS, so it retries.</p><p>Process B does create(lockNode, “B”).</p><p>If process A’s first write succeeded on the server but returned CONNECTION_LOSS to the client, both process A and process B would get a NODE_EXISTS exception on their last write. This causes a distributed deadlock, because each process thinks some other process acquired the lock, even though process A actually acquired the lock.</p><p>If we instead used idempotent creates, process A’s write would be successful, and it would realize that it successfully acquired the lock, even though the outcome of one of its writes was unknown.</p><h3>Code Examples</h3><p>Although the previous examples only discussed creating a node, idempotent writes also support SetData and Delete. They also all work in both foreground and background mode.</p><pre>// This will create the given ZNode with the given data idempotently, meaning that as long as the end state is that the znode exists at version 0 and the node data == payload, the request will succeed.</pre><pre>client.create().idempotent().forPath(path, payload);</pre><pre>// This will update the data of the given ZNode idempotently, meaning that if currentVersion == X and payload = P, this will return success if the znode ends up in the state {version == X+1 &amp;&amp; data == P}.</pre><pre>client.setData().idempotent().withVersion(currentVersion).forPath(path, payload);</pre><pre>// If withVersion is not specified, it will end up with success so long as the data == P, no matter the znode version.</pre><pre>client.setData().idempotent().forPath(path, payload);</pre><pre>// This will delete the given ZNode idempotently, meaning that if currentVersion == X, this will return success if the ZNode ends up deleted and the client did not observe a version of the ZNode &gt; X before it observed deletion.</pre><pre>client.delete().idempotent().withVersion(currentVersion).forPath(path);</pre><pre>// If withVersion is not specified, it will end up with success so long as the node is deleted eventually.</pre><pre>client.delete().idempotent().forPath(path);</pre><pre>// This idempotent() behavior for deletes is equivalent to the quietly behavior, but is also provided under idempotent() for compatibility with create/setData.</pre><h3>Corner Cases</h3><p>Idempotent behavior is not compatible with several of the other zookeeper/curator modifiers, and should be used with caution.</p><p>Idempotency is disabled with <em>sequential</em> create mode, or if the client sets one of the other curator create modifiers that changes retry behavior on error, like <em>orSetData</em>, <em>createParents</em>, and <em>protected.</em></p><p>In the “multiple creating clients” case with the <em>ephemeral</em> create mode, a client that failed the create but returned success because someone else created it could have the node disappear out from under them, if the other writer that succeeded at the create lost its zookeeper session. In other words, in the idempotent case, the caller needs to be aware that an ephemeral idempotent node may not belong to its session.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eadf7c12c814" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>