This is an automated email from the ASF dual-hosted git repository. xiangfu pushed a commit to branch winedepot-0.10 in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
commit 09ce670935dd32eaf215f83de4c5fff6cbf32229 Author: Jialiang Li <[email protected]> AuthorDate: Wed Aug 14 10:41:17 2019 -0700 Handle NPE from getting live instance (#4528) --- .../java/org/apache/pinot/common/utils/ServiceStatus.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pinot-common/src/main/java/org/apache/pinot/common/utils/ServiceStatus.java b/pinot-common/src/main/java/org/apache/pinot/common/utils/ServiceStatus.java index 6f00981..2079dbe 100644 --- a/pinot-common/src/main/java/org/apache/pinot/common/utils/ServiceStatus.java +++ b/pinot-common/src/main/java/org/apache/pinot/common/utils/ServiceStatus.java @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import javax.annotation.Nullable; import org.apache.helix.HelixAdmin; import org.apache.helix.HelixDataAccessor; import org.apache.helix.HelixManager; @@ -209,6 +210,7 @@ public class ServiceStatus { getResourceListAsString(), _instanceName); } + @Nullable protected abstract T getState(String resourceName); protected abstract Map<String, String> getPartitionStateMap(T state); @@ -381,12 +383,21 @@ public class ServiceStatus { super(helixManager, clusterName, instanceName, resourcesToMonitor, minResourcesStartPercent); } + /** + * Returns the current state for the given resource, or {@code null} if instance is not live or current state does + * not exist. + */ + @Nullable @Override protected CurrentState getState(String resourceName) { PropertyKey.Builder keyBuilder = _helixDataAccessor.keyBuilder(); LiveInstance liveInstance = _helixDataAccessor.getProperty(keyBuilder.liveInstance(_instanceName)); - String sessionId = liveInstance.getSessionId(); - return _helixDataAccessor.getProperty(keyBuilder.currentState(_instanceName, sessionId, resourceName)); + if (liveInstance == null) { + return null; + } else { + String sessionId = liveInstance.getSessionId(); + return _helixDataAccessor.getProperty(keyBuilder.currentState(_instanceName, sessionId, resourceName)); + } } @Override --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
