From b5bc194314865cc8dcb3816ccd79b6ce27a92256 Mon Sep 17 00:00:00 2001 From: Grant Palau Spencer Date: Thu, 5 Sep 2024 14:58:37 -0700 Subject: [PATCH 1/2] fix partitionAssignment NPE due to empty cache --- .../dataproviders/BaseControllerDataProvider.java | 4 ++++ .../src/main/java/org/apache/helix/util/HelixUtil.java | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java b/helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java index 885e789f6b..997f0f8aae 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java +++ b/helix-core/src/main/java/org/apache/helix/controller/dataproviders/BaseControllerDataProvider.java @@ -950,6 +950,10 @@ public Map getStateModelDefMap() { return _stateModelDefinitionCache.getPropertyMap(); } + public void setStateModelDefMap(Map stateModelDefMap) { + _stateModelDefinitionCache.setPropertyMap(stateModelDefMap); + } + /** * Provides the idealstate for a given resource * @param resourceName diff --git a/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java b/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java index 70269a746e..1d81d8c34a 100644 --- a/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java +++ b/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java @@ -382,13 +382,15 @@ public static Map> getIdealAssignmentForFullAuto( allNodes.add(instanceConfig.getInstanceName()); instanceConfigMap.put(instanceConfig.getInstanceName(), instanceConfig); } - ResourceControllerDataProvider cache = new ResourceControllerDataProvider(); - cache.setClusterConfig(clusterConfig); - cache.setInstanceConfigMap(instanceConfigMap); StateModelDefinition stateModelDefinition = BuiltInStateModelDefinitions.valueOf(idealState.getStateModelDefRef()) .getStateModelDefinition(); + ResourceControllerDataProvider cache = new ResourceControllerDataProvider(clusterConfig.getClusterName()); + cache.setClusterConfig(clusterConfig); + cache.setInstanceConfigMap(instanceConfigMap); + cache.setIdealStates(Collections.singletonList(idealState)); + cache.setStateModelDefMap(Collections.singletonMap(stateModelDefinition.getId(), stateModelDefinition)); RebalanceStrategy strategy = RebalanceStrategy.class.cast(loadClass(HelixUtil.class, strategyClassName).newInstance()); From 819f12709279e10db1e51d92dad86284d2c7b314 Mon Sep 17 00:00:00 2001 From: Grant Palau Spencer Date: Thu, 5 Sep 2024 15:35:14 -0700 Subject: [PATCH 2/2] add todo --- helix-core/src/main/java/org/apache/helix/util/HelixUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java b/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java index 1d81d8c34a..6a77167321 100644 --- a/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java +++ b/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java @@ -383,6 +383,7 @@ public static Map> getIdealAssignmentForFullAuto( instanceConfigMap.put(instanceConfig.getInstanceName(), instanceConfig); } + // TODO: Consider full cache refresh to prevent needing to manually set necessary fields StateModelDefinition stateModelDefinition = BuiltInStateModelDefinitions.valueOf(idealState.getStateModelDefRef()) .getStateModelDefinition();