helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject git commit: [HELIX-10] znode bucketize bugs: when drop a resource, bucketized externalView is not cleaned up
Date Thu, 15 Nov 2012 23:58:10 GMT
Updated Branches:
  refs/heads/master 0ddcc274f -> 69d96c642


[HELIX-10] znode bucketize bugs: when drop a resource, bucketized externalView is not cleaned
up


Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/69d96c64
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/69d96c64
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/69d96c64

Branch: refs/heads/master
Commit: 69d96c642cb435fb6060508c7113a16cfc33540c
Parents: 0ddcc27
Author: zzhang <zzhang@apache.org>
Authored: Thu Nov 15 15:58:02 2012 -0800
Committer: zzhang <zzhang@apache.org>
Committed: Thu Nov 15 15:58:02 2012 -0800

----------------------------------------------------------------------
 .../stages/ExternalViewComputeStage.java           |   28 +++++---
 .../apache/helix/manager/zk/CallbackHandler.java   |   57 ++++++++-------
 .../helix/manager/zk/ZKHelixDataAccessor.java      |    6 +-
 3 files changed, 55 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/69d96c64/helix-core/src/main/java/org/apache/helix/controller/stages/ExternalViewComputeStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/ExternalViewComputeStage.java
b/helix-core/src/main/java/org/apache/helix/controller/stages/ExternalViewComputeStage.java
index 296ffe5..a691a25 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/ExternalViewComputeStage.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/stages/ExternalViewComputeStage.java
@@ -34,7 +34,6 @@ import org.apache.helix.model.Resource;
 import org.apache.helix.monitoring.mbeans.ClusterStatusMonitor;
 import org.apache.log4j.Logger;
 
-
 public class ExternalViewComputeStage extends AbstractBaseStage
 {
   private static Logger log = Logger.getLogger(ExternalViewComputeStage.class);
@@ -63,13 +62,23 @@ public class ExternalViewComputeStage extends AbstractBaseStage
 
     List<ExternalView> newExtViews = new ArrayList<ExternalView>();
     List<PropertyKey> keys = new ArrayList<PropertyKey>();
-    
+
     for (String resourceName : resourceMap.keySet())
     {
       ExternalView view = new ExternalView(resourceName);
-      view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
-      
+      // view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
+      // if resource ideal state has bucket size, set it
+      // otherwise resource has been dropped, use bucket size from current state instead
       Resource resource = resourceMap.get(resourceName);
+      if (resource.getBucketSize() > 0)
+      {
+        view.setBucketSize(resource.getBucketSize());
+      }
+      else
+      {
+        view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
+      }
+
       for (Partition partition : resource.getPartitions())
       {
         Map<String, String> currentStateMap =
@@ -97,12 +106,12 @@ public class ExternalViewComputeStage extends AbstractBaseStage
         clusterStatusMonitor.onExternalViewChange(view,
                                                   cache._idealStateMap.get(view.getResourceName()));
       }
-      
+
       // compare the new external view with current one, set only on different
       Map<String, ExternalView> curExtViews =
           dataAccessor.getChildValuesMap(manager.getHelixDataAccessor()
-                                             .keyBuilder()
-                                             .externalViews());
+                                                .keyBuilder()
+                                                .externalViews());
 
       ExternalView curExtView = curExtViews.get(resourceName);
       if (curExtView == null || !curExtView.getRecord().equals(view.getRecord()))
@@ -118,9 +127,10 @@ public class ExternalViewComputeStage extends AbstractBaseStage
     {
       dataAccessor.setChildren(keys, newExtViews);
     }
-    
+
     long endTime = System.currentTimeMillis();
-    log.info("END ExternalViewComputeStage.process(). took: " + (endTime - startTime) + "
ms");
+    log.info("END ExternalViewComputeStage.process(). took: " + (endTime - startTime)
+        + " ms");
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/69d96c64/helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java b/helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java
index a8a9bfe..bc77b48 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java
@@ -38,15 +38,15 @@ import org.apache.helix.ControllerChangeListener;
 import org.apache.helix.CurrentStateChangeListener;
 import org.apache.helix.ExternalViewChangeListener;
 import org.apache.helix.HealthStateChangeListener;
+import org.apache.helix.HelixConstants.ChangeType;
 import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.HelixManager;
 import org.apache.helix.IdealStateChangeListener;
 import org.apache.helix.LiveInstanceChangeListener;
 import org.apache.helix.MessageListener;
 import org.apache.helix.NotificationContext;
-import org.apache.helix.PropertyPathConfig;
-import org.apache.helix.HelixConstants.ChangeType;
 import org.apache.helix.PropertyKey.Builder;
+import org.apache.helix.PropertyPathConfig;
 import org.apache.helix.model.CurrentState;
 import org.apache.helix.model.ExternalView;
 import org.apache.helix.model.HealthStat;
@@ -57,24 +57,27 @@ import org.apache.helix.model.Message;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.Watcher.Event.EventType;
 
-
 public class CallbackHandler implements IZkChildListener, IZkDataListener
 
 {
 
-  private static Logger logger = Logger.getLogger(CallbackHandler.class);
+  private static Logger           logger = Logger.getLogger(CallbackHandler.class);
 
-  private final String _path;
-  private final Object _listener;
-  private final EventType[] _eventTypes;
+  private final String            _path;
+  private final Object            _listener;
+  private final EventType[]       _eventTypes;
   private final HelixDataAccessor _accessor;
-  private final ChangeType _changeType;
-  private final ZkClient _zkClient;
-  private final AtomicLong lastNotificationTimeStamp;
-  private final HelixManager _manager;
-
-  public CallbackHandler(HelixManager manager, ZkClient client, String path,
-                         Object listener, EventType[] eventTypes, ChangeType changeType)
+  private final ChangeType        _changeType;
+  private final ZkClient          _zkClient;
+  private final AtomicLong        lastNotificationTimeStamp;
+  private final HelixManager      _manager;
+
+  public CallbackHandler(HelixManager manager,
+                         ZkClient client,
+                         String path,
+                         Object listener,
+                         EventType[] eventTypes,
+                         ChangeType changeType)
   {
     this._manager = manager;
     this._accessor = manager.getHelixDataAccessor();
@@ -231,15 +234,19 @@ public class CallbackHandler implements IZkChildListener, IZkDataListener
                                    boolean watchChild)
   {
     NotificationContext.Type type = context.getType();
-    if (watchParent && type == NotificationContext.Type.INIT)
+    if (watchParent)
     {
-      logger.info(_manager.getInstanceName() + " subscribe child change@" + path);
-      _zkClient.subscribeChildChanges(path, this);
-    }
-    else if (watchParent && type == NotificationContext.Type.FINALIZE)
-    {
-      logger.info(_manager.getInstanceName() + " UNsubscribe child change@" + path);
-      _zkClient.unsubscribeChildChanges(path, this);
+      if (type == NotificationContext.Type.INIT
+          || type == NotificationContext.Type.CALLBACK)
+      {
+        logger.info(_manager.getInstanceName() + " subscribe child change@" + path);
+        _zkClient.subscribeChildChanges(path, this);
+      }
+      else if (watchParent && type == NotificationContext.Type.FINALIZE)
+      {
+        logger.info(_manager.getInstanceName() + " UNsubscribe child change@" + path);
+        _zkClient.unsubscribeChildChanges(path, this);
+      }
     }
 
     if (watchChild)
@@ -260,14 +267,14 @@ public class CallbackHandler implements IZkChildListener, IZkDataListener
           {
             if (logger.isDebugEnabled())
             {
-              logger.debug(_manager.getInstanceName() + " subscribe data change@" + path);
+              logger.debug(_manager.getInstanceName() + " subscribe data change@" + childPath);
             }
             _zkClient.subscribeDataChanges(childPath, this);
 
           }
           else if (type == NotificationContext.Type.FINALIZE)
           {
-            logger.info(_manager.getInstanceName() + " UNsubscribe data change@" + path);
+            logger.info(_manager.getInstanceName() + " UNsubscribe data change@" + childPath);
             _zkClient.unsubscribeDataChanges(childPath, this);
           }
 
@@ -276,7 +283,7 @@ public class CallbackHandler implements IZkChildListener, IZkDataListener
       }
       catch (ZkNoNodeException e)
       {
-        logger.warn("fail to subscribe data change@" + path);
+        logger.warn("fail to subscribe child data change@" + path);
       }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/69d96c64/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixDataAccessor.java
b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixDataAccessor.java
index 5608557..f3d5946 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixDataAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixDataAccessor.java
@@ -36,15 +36,15 @@ import org.apache.helix.HelixProperty;
 import org.apache.helix.InstanceType;
 import org.apache.helix.NotificationContext;
 import org.apache.helix.PropertyKey;
+import org.apache.helix.PropertyKey.Builder;
 import org.apache.helix.PropertyType;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.ZNRecordAssembler;
 import org.apache.helix.ZNRecordBucketizer;
 import org.apache.helix.ZNRecordUpdater;
-import org.apache.helix.PropertyKey.Builder;
 import org.apache.helix.controller.restlet.ZNRecordUpdate;
-import org.apache.helix.controller.restlet.ZkPropertyTransferClient;
 import org.apache.helix.controller.restlet.ZNRecordUpdate.OpCode;
+import org.apache.helix.controller.restlet.ZkPropertyTransferClient;
 import org.apache.helix.model.LiveInstance;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.data.Stat;
@@ -498,6 +498,8 @@ public class ZKHelixDataAccessor implements HelixDataAccessor, ControllerChangeL
         }
         else
         {
+          _baseDataAccessor.remove(path, options);
+
           ZNRecord metaRecord = new ZNRecord(value.getId());
           metaRecord.setSimpleFields(value.getRecord().getSimpleFields());
           records.add(metaRecord);


Mime
View raw message