You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by dr...@apache.org on 2016/05/26 03:35:16 UTC
curator git commit: Fix race condition in TreeCache.
Repository: curator
Updated Branches:
refs/heads/master 4473c6b6c -> b4da5f5ca
Fix race condition in TreeCache.
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/b4da5f5c
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/b4da5f5c
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/b4da5f5c
Branch: refs/heads/master
Commit: b4da5f5ca279905097b1fe7d5eb9710c6dc8bdd2
Parents: 4473c6b
Author: Scott Blum <dr...@apache.org>
Authored: Wed May 25 21:49:29 2016 -0400
Committer: Scott Blum <dr...@apache.org>
Committed: Wed May 25 23:21:43 2016 -0400
----------------------------------------------------------------------
.../framework/recipes/cache/TreeCache.java | 20 +++++++++++++++++---
.../recipes/cache/TestEventOrdering.java | 4 +++-
2 files changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/b4da5f5c/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
index 2dbe699..914d336 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
@@ -446,12 +446,26 @@ public class TreeCache implements Closeable
oldChildData = childData.getAndSet(new ChildData(event.getPath(), newStat, null));
}
- NodeState oldState = nodeState.getAndSet(NodeState.LIVE);
- if ( oldState == NodeState.PENDING || (oldState == NodeState.DEAD && parent == null))
+ boolean added;
+ if (parent == null) {
+ // We're the singleton root.
+ added = nodeState.getAndSet(NodeState.LIVE) != NodeState.LIVE;
+ } else {
+ added = nodeState.compareAndSet(NodeState.PENDING, NodeState.LIVE);
+ if (!added) {
+ // Ordinary nodes are not allowed to transition from dead -> live;
+ // make sure this isn't a delayed response that came in after death.
+ if (nodeState.get() != NodeState.LIVE) {
+ return;
+ }
+ }
+ }
+
+ if ( added )
{
publishEvent(TreeCacheEvent.Type.NODE_ADDED, toPublish);
}
- else if ( oldState == NodeState.LIVE )
+ else
{
if ( oldChildData == null || oldChildData.getStat().getMzxid() != newStat.getMzxid() )
{
http://git-wip-us.apache.org/repos/asf/curator/blob/b4da5f5c/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
index 5f294cf..216c07c 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
@@ -166,10 +166,12 @@ public abstract class TestEventOrdering<T extends Closeable> extends BaseClassFo
private String asString(List<Event> events)
{
+ int qty = 0;
StringBuilder str = new StringBuilder();
for ( Event event : events )
{
- str.append(event.eventType).append(" ").append(event.path).append(" @ ").append(event.time - start);
+ qty += (event.eventType == EventType.ADDED) ? 1 : -1;
+ str.append(event.eventType).append(" ").append(event.path).append(" @ ").append(event.time - start).append(' ').append(qty);
str.append("\n");
}
return str.toString();