helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject [helix] branch master updated: Remove resource from customized state if all partitions are gone (#1411)
Date Mon, 28 Sep 2020 19:55:15 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new dbd88a5   Remove resource from customized state if all partitions are gone (#1411)
dbd88a5 is described below

commit dbd88a50b69f0db92597f6428b346dd6d98a2763
Author: Meng Zhang <mnzhang@linkedin.com>
AuthorDate: Mon Sep 28 12:55:01 2020 -0700

     Remove resource from customized state if all partitions are gone (#1411)
    
    Remove resource from customized state if all partitions are gone
---
 .../customizedstate/CustomizedStateProvider.java   | 18 +++++++++--------
 .../helix/manager/zk/ZKHelixDataAccessor.java      | 23 +++++++++++-----------
 .../paticipant/TestCustomizedStateUpdate.java      |  5 +++++
 3 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/helix-core/src/main/java/org/apache/helix/customizedstate/CustomizedStateProvider.java
b/helix-core/src/main/java/org/apache/helix/customizedstate/CustomizedStateProvider.java
index 0abf4a1..8b25fbc 100644
--- a/helix-core/src/main/java/org/apache/helix/customizedstate/CustomizedStateProvider.java
+++ b/helix-core/src/main/java/org/apache/helix/customizedstate/CustomizedStateProvider.java
@@ -19,7 +19,9 @@ package org.apache.helix.customizedstate;
  * under the License.
  */
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.helix.HelixDataAccessor;
@@ -28,7 +30,7 @@ import org.apache.helix.HelixManager;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.model.CustomizedState;
 import org.apache.helix.zookeeper.datamodel.ZNRecord;
-import org.apache.helix.zookeeper.zkclient.DataUpdater;
+import org.apache.helix.zookeeper.datamodel.ZNRecordDelta;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -110,12 +112,12 @@ public class CustomizedStateProvider {
     PropertyKey propertyKey =
         keyBuilder.customizedState(_instanceName, customizedStateName, resourceName);
     CustomizedState existingState = getCustomizedState(customizedStateName, resourceName);
-    _helixDataAccessor.updateProperty(propertyKey, new DataUpdater<ZNRecord>() {
-      @Override
-      public ZNRecord update(ZNRecord current) {
-        current.getMapFields().remove(partitionName);
-        return current;
-      }
-    }, existingState);
+    ZNRecord rec = new ZNRecord(existingState.getId());
+    rec.getMapFields().put(partitionName, null);
+    ZNRecordDelta delta = new ZNRecordDelta(rec, ZNRecordDelta.MergeOperation.SUBTRACT);
+    List<ZNRecordDelta> deltaList = new ArrayList<ZNRecordDelta>();
+    deltaList.add(delta);
+    existingState.setDeltaList(deltaList);
+    _helixDataAccessor.updateProperty(propertyKey, existingState);
   }
 }
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 d2b6077..35cc663 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
@@ -185,17 +185,18 @@ public class ZKHelixDataAccessor implements HelixDataAccessor {
 
     boolean success = false;
     switch (type) {
-    case CURRENTSTATES:
-      success = _groupCommit.commit(_baseDataAccessor, options, path, value.getRecord(),
true);
-      break;
-    case STATUSUPDATES:
-      if (LOG.isTraceEnabled()) {
-        LOG.trace("Update status. path: " + key.getPath() + ", record: " + value.getRecord());
-      }
-      break;
-    default:
-      success = _baseDataAccessor.update(path, updater, options);
-      break;
+      case CURRENTSTATES:
+      case CUSTOMIZEDSTATES:
+        success = _groupCommit.commit(_baseDataAccessor, options, path, value.getRecord(),
true);
+        break;
+      case STATUSUPDATES:
+        if (LOG.isTraceEnabled()) {
+          LOG.trace("Update status. path: " + key.getPath() + ", record: " + value.getRecord());
+        }
+        break;
+      default:
+        success = _baseDataAccessor.update(path, updater, options);
+        break;
     }
     return success;
   }
diff --git a/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestCustomizedStateUpdate.java
b/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestCustomizedStateUpdate.java
index ed1338a..c9b741c 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestCustomizedStateUpdate.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/paticipant/TestCustomizedStateUpdate.java
@@ -161,6 +161,11 @@ public class TestCustomizedStateUpdate extends ZkStandAloneCMTestBase
{
     mapView = customizedState.getRecord().getMapFields();
     Assert.assertEquals(mapView.keySet().size(), 1);
     Assert.assertEquals(mapView.keySet().iterator().next(), PARTITION_NAME2);
+
+    _mockProvider
+        .deletePerPartitionCustomizedState(CUSTOMIZE_STATE_NAME, RESOURCE_NAME, PARTITION_NAME2);
+    customizedState = _mockProvider.getCustomizedState(CUSTOMIZE_STATE_NAME, RESOURCE_NAME);
+    Assert.assertNull(customizedState);
   }
 
   @Test


Mime
View raw message