You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/05/03 03:02:57 UTC

[GitHub] [geode] kohlmu-pivotal opened a new pull request #6423: GEODE-9227: Performance improvements in the loading of CommandMarkers…

kohlmu-pivotal opened a new pull request #6423:
URL: https://github.com/apache/geode/pull/6423


   … and Converters
   
   Thank you for submitting a contribution to Apache Geode.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   - [ ] Does `gradlew build` run cleanly?
   
   - [ ] Have you written or updated unit tests to verify your changes?
   
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   
   ### Note:
   Please ensure that once the PR is submitted, check Concourse for build issues and
   submit an update to your PR as soon as possible. If you need help, please send an
   email to dev@geode.apache.org.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] jinmeiliao commented on a change in pull request #6423: GEODE-9227: Performance improvements in the loading of CommandMarkers…

Posted by GitBox <gi...@apache.org>.
jinmeiliao commented on a change in pull request #6423:
URL: https://github.com/apache/geode/pull/6423#discussion_r626113167



##########
File path: geode-core/src/main/java/org/apache/geode/management/internal/util/ClasspathScanLoadHelper.java
##########
@@ -41,6 +41,12 @@ public ClasspathScanLoadHelper(Collection<String> packagesToScan) {
         .enableAnnotationInfo().scan(1);
   }
 
+  public ClasspathScanLoadHelper(String... packagesToScan) {
+    scanResult = new ClassGraph().whitelistPackages(packagesToScan)

Review comment:
       use the non-deprecated method `acceptPackage` instead

##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -128,15 +134,17 @@ private static void raiseExceptionIfEmpty(Set<?> foundClasses, String errorFor)
     return userCommandPackages;
   }
 
-  private void loadUserCommands(ClasspathScanLoadHelper scanner, Set<String> restrictedToPackages) {
-    if (restrictedToPackages.size() == 0) {
+  private void loadUserDefinedCommands() {
+    String[] userCommandPackages = getUserCommandPackages().toArray(new String[] {});
+
+    if (userCommandPackages.length == 0) {
       return;
     }
 
     // Load commands found in all of the packages
-    try {
+    try (ClasspathScanLoadHelper scanner = new ClasspathScanLoadHelper(userCommandPackages)) {
       Set<Class<?>> foundClasses = scanner.scanPackagesForClassesImplementing(CommandMarker.class,
-          restrictedToPackages.toArray(new String[] {}));
+          userCommandPackages);

Review comment:
       I believe you don't need to pass in the 2nd parameter if scanning from all packages

##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -157,59 +165,38 @@ private void loadUserCommands(ClasspathScanLoadHelper scanner, Set<String> restr
    *
    * @since GemFire 8.1
    */
-  private void loadPluginCommands() {
-    ServiceLoader<CommandMarker> loader =
+  private void loadGeodeCommands() {
+    ServiceLoader<CommandMarker> commandMarkers =
         ServiceLoader.load(CommandMarker.class, ClassPathLoader.getLatest().asClassLoader());
-    Iterator<CommandMarker> iterator = loader.iterator();
-    try {
-      while (iterator.hasNext()) {
-        try {
-          add(iterator.next());
-        } catch (Throwable t) {
-          logWrapper.warning("Could not load plugin command: " + t.getMessage());
-        }
-      }
-    } catch (Throwable th) {
-      logWrapper.severe("Could not load plugin commands in the latest classLoader.", th);
+
+    boolean loadedAtLeastOneCommand = false;
+    for (CommandMarker commandMarker : commandMarkers) {
+      add(commandMarker);
+      loadedAtLeastOneCommand = true;
+    }
+    if (!loadedAtLeastOneCommand) {
+      throw new IllegalStateException(
+          "Required Command classes were not loaded. Check logs for errors.");
     }
   }
 
-  private void loadCommands() {
-    Set<String> userCommandPackages = getUserCommandPackages();
-    Set<String> packagesToScan = new HashSet<>(userCommandPackages);
-    packagesToScan.add("org.springframework.shell.converters");
-    // packagesToScan.add(GfshCommand.class.getPackage().getName());
-    // packagesToScan.add(VersionCommand.class.getPackage().getName());
-
-    // Create one scanner to be used everywhere
-    try (ClasspathScanLoadHelper scanner = new ClasspathScanLoadHelper(packagesToScan)) {
-      loadUserCommands(scanner, userCommandPackages);
-      loadPluginCommands();
-      // loadGeodeCommands(scanner);
-      loadConverters(scanner);
-    }
+  private void loadConverters() {
+    loadGeodeDefinedConverters();
+    loadSpringDefinedConverters();
   }
 
-  private void loadConverters(ClasspathScanLoadHelper scanner) {
-    Set<Class<?>> foundClasses;
-    // Converters
-    try {
-      ServiceLoader<Converter> load =
-          ServiceLoader.load(Converter.class, ClassPathLoader.getLatestAsClassLoader());
-      AtomicInteger count = new AtomicInteger(0);
-      load.forEach(converter -> {
-        add(converter);
-        count.incrementAndGet();
-      });
-      if (count.get() == 0) {
-        raiseExceptionIfEmpty(Collections.EMPTY_SET, "Converters");
-      }
+  private void loadCommands() {
+    loadGeodeCommands();
+    loadUserDefinedCommands();
+  }
 
+  private void loadSpringDefinedConverters() {
+    try (ClasspathScanLoadHelper scanner = new ClasspathScanLoadHelper(SPRING_CONVERTER_PACKAGE)) {
       // Spring shell's converters
-      foundClasses = scanner.scanPackagesForClassesImplementing(Converter.class,
-          "org.springframework.shell.converters");
+      Set<Class<?>> foundClasses = scanner.scanPackagesForClassesImplementing(Converter.class,
+          SPRING_CONVERTER_PACKAGE);

Review comment:
       same here, no need for the 2nd parameter

##########
File path: geode-core/src/main/java/org/apache/geode/management/internal/util/ClasspathScanLoadHelper.java
##########
@@ -41,6 +41,12 @@ public ClasspathScanLoadHelper(Collection<String> packagesToScan) {
         .enableAnnotationInfo().scan(1);

Review comment:
       have this call the other constructor instead `this(packagesToScan.toArray(new String[] {}))`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] kohlmu-pivotal merged pull request #6423: GEODE-9227: Performance improvements in the loading of CommandMarkers…

Posted by GitBox <gi...@apache.org>.
kohlmu-pivotal merged pull request #6423:
URL: https://github.com/apache/geode/pull/6423


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] jinmeiliao commented on a change in pull request #6423: GEODE-9227: Performance improvements in the loading of CommandMarkers…

Posted by GitBox <gi...@apache.org>.
jinmeiliao commented on a change in pull request #6423:
URL: https://github.com/apache/geode/pull/6423#discussion_r625849420



##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -176,16 +177,15 @@ private void loadPluginCommands() {
   private void loadCommands() {
     Set<String> userCommandPackages = getUserCommandPackages();
     Set<String> packagesToScan = new HashSet<>(userCommandPackages);
-    packagesToScan.add("org.apache.geode");
     packagesToScan.add("org.springframework.shell.converters");
-    packagesToScan.add(GfshCommand.class.getPackage().getName());
-    packagesToScan.add(VersionCommand.class.getPackage().getName());
+    // packagesToScan.add(GfshCommand.class.getPackage().getName());
+    // packagesToScan.add(VersionCommand.class.getPackage().getName());
 
     // Create one scanner to be used everywhere
     try (ClasspathScanLoadHelper scanner = new ClasspathScanLoadHelper(packagesToScan)) {
       loadUserCommands(scanner, userCommandPackages);

Review comment:
       we can just pass in the `userCommandsPackages` for this method, and create the scanner inside the method, we don't need all the previous lines.

##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -176,16 +177,15 @@ private void loadPluginCommands() {
   private void loadCommands() {
     Set<String> userCommandPackages = getUserCommandPackages();
     Set<String> packagesToScan = new HashSet<>(userCommandPackages);
-    packagesToScan.add("org.apache.geode");
     packagesToScan.add("org.springframework.shell.converters");
-    packagesToScan.add(GfshCommand.class.getPackage().getName());
-    packagesToScan.add(VersionCommand.class.getPackage().getName());
+    // packagesToScan.add(GfshCommand.class.getPackage().getName());
+    // packagesToScan.add(VersionCommand.class.getPackage().getName());
 
     // Create one scanner to be used everywhere
     try (ClasspathScanLoadHelper scanner = new ClasspathScanLoadHelper(packagesToScan)) {
       loadUserCommands(scanner, userCommandPackages);
       loadPluginCommands();
-      loadGeodeCommands(scanner);
+      // loadGeodeCommands(scanner);
       loadConverters(scanner);

Review comment:
       since we are using service loader to load all the geode converters, we don't need to pass in the scanner here anymore. Inside the `loadConverters` we can create a scanner only for `"org.springframework.shell.converters"` package and add those converters.

##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -176,16 +177,15 @@ private void loadPluginCommands() {
   private void loadCommands() {
     Set<String> userCommandPackages = getUserCommandPackages();
     Set<String> packagesToScan = new HashSet<>(userCommandPackages);
-    packagesToScan.add("org.apache.geode");
     packagesToScan.add("org.springframework.shell.converters");
-    packagesToScan.add(GfshCommand.class.getPackage().getName());
-    packagesToScan.add(VersionCommand.class.getPackage().getName());
+    // packagesToScan.add(GfshCommand.class.getPackage().getName());
+    // packagesToScan.add(VersionCommand.class.getPackage().getName());
 
     // Create one scanner to be used everywhere
     try (ClasspathScanLoadHelper scanner = new ClasspathScanLoadHelper(packagesToScan)) {
       loadUserCommands(scanner, userCommandPackages);
       loadPluginCommands();

Review comment:
       this code actually loads all geode commands, right? let's rename it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] agingade commented on a change in pull request #6423: GEODE-9227: Performance improvements in the loading of CommandMarkers…

Posted by GitBox <gi...@apache.org>.
agingade commented on a change in pull request #6423:
URL: https://github.com/apache/geode/pull/6423#discussion_r626982618



##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -112,12 +121,10 @@ private static void raiseExceptionIfEmpty(Set<Class<?>> foundClasses, String err
     }
 
     // Find by packages specified in the distribution config
-    if (this.cacheProperties != null) {
-      String cacheUserCmdPackages =
-          this.cacheProperties.getProperty(ConfigurationProperties.USER_COMMAND_PACKAGES);
-      if (cacheUserCmdPackages != null && !cacheUserCmdPackages.isEmpty()) {
-        userCommandSources.add(cacheUserCmdPackages);
-      }
+    String cacheUserCmdPackages =

Review comment:
       I am not sure how the cacheProperties are initialized, will there be a case "cacheUserCmdPackages" could be null.

##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -80,16 +88,17 @@ public CommandManager() {
    * this is used when getting the instance in a cache server. We are getting the
    * user-command-package from distribution properties. used by OnlineCommandProcessor.
    */
-  public CommandManager(final Properties cacheProperties, InternalCache cache) {
-    if (cacheProperties != null) {
-      this.cacheProperties = cacheProperties;
+  public CommandManager(final Properties newCacheProperties, InternalCache cache) {
+    if (newCacheProperties != null) {
+      this.cacheProperties.putAll(newCacheProperties);

Review comment:
       If you are planning to do code cleanup; reference to "this" can be removed in many places :)

##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -127,15 +134,17 @@ private static void raiseExceptionIfEmpty(Set<Class<?>> foundClasses, String err
     return userCommandPackages;
   }
 
-  private void loadUserCommands(ClasspathScanLoadHelper scanner, Set<String> restrictedToPackages) {
-    if (restrictedToPackages.size() == 0) {
+  private void loadUserDefinedCommands() {
+    String[] userCommandPackages = getUserCommandPackages().toArray(new String[] {});
+
+    if (userCommandPackages.length == 0) {
       return;
     }
 
     // Load commands found in all of the packages
-    try {
-      Set<Class<?>> foundClasses = scanner.scanPackagesForClassesImplementing(CommandMarker.class,
-          restrictedToPackages.toArray(new String[] {}));
+    try (ClasspathScanLoadHelper scanner = new ClasspathScanLoadHelper(userCommandPackages)) {
+      Set<Class<?>> foundClasses =
+          scanner.scanPackagesForClassesImplementing(CommandMarker.class, userCommandPackages);

Review comment:
       Not sure if there will be any perf benefits, just thought of bringing it here...It looks like we are instantiating the command classed found (below line); can this initialization be done lazily, when the command is used/executed, will this help.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] kohlmu-pivotal commented on a change in pull request #6423: GEODE-9227: Performance improvements in the loading of CommandMarkers…

Posted by GitBox <gi...@apache.org>.
kohlmu-pivotal commented on a change in pull request #6423:
URL: https://github.com/apache/geode/pull/6423#discussion_r627734665



##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -112,12 +121,10 @@ private static void raiseExceptionIfEmpty(Set<Class<?>> foundClasses, String err
     }
 
     // Find by packages specified in the distribution config
-    if (this.cacheProperties != null) {
-      String cacheUserCmdPackages =
-          this.cacheProperties.getProperty(ConfigurationProperties.USER_COMMAND_PACKAGES);
-      if (cacheUserCmdPackages != null && !cacheUserCmdPackages.isEmpty()) {
-        userCommandSources.add(cacheUserCmdPackages);
-      }
+    String cacheUserCmdPackages =
+        this.cacheProperties.getProperty(ConfigurationProperties.USER_COMMAND_PACKAGES, "");
+    if (!cacheUserCmdPackages.isEmpty()) {

Review comment:
       There is a default on the property look up. So if there is no property by that name, it returns empty String.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] kohlmu-pivotal commented on a change in pull request #6423: GEODE-9227: Performance improvements in the loading of CommandMarkers…

Posted by GitBox <gi...@apache.org>.
kohlmu-pivotal commented on a change in pull request #6423:
URL: https://github.com/apache/geode/pull/6423#discussion_r626987156



##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -80,16 +88,17 @@ public CommandManager() {
    * this is used when getting the instance in a cache server. We are getting the
    * user-command-package from distribution properties. used by OnlineCommandProcessor.
    */
-  public CommandManager(final Properties cacheProperties, InternalCache cache) {
-    if (cacheProperties != null) {
-      this.cacheProperties = cacheProperties;
+  public CommandManager(final Properties newCacheProperties, InternalCache cache) {
+    if (newCacheProperties != null) {
+      this.cacheProperties.putAll(newCacheProperties);

Review comment:
       the removal of the keyword 'this' does not make code any cleaner... in actual fact, it makes it harder to read, as we are spoilt with IDE's that indicate fields and properties in different colors. As for reading this as text, makes it evident that we are referring to the field defined on the CommandManager.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] kohlmu-pivotal commented on a change in pull request #6423: GEODE-9227: Performance improvements in the loading of CommandMarkers…

Posted by GitBox <gi...@apache.org>.
kohlmu-pivotal commented on a change in pull request #6423:
URL: https://github.com/apache/geode/pull/6423#discussion_r626989001



##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -127,15 +134,17 @@ private static void raiseExceptionIfEmpty(Set<Class<?>> foundClasses, String err
     return userCommandPackages;
   }
 
-  private void loadUserCommands(ClasspathScanLoadHelper scanner, Set<String> restrictedToPackages) {
-    if (restrictedToPackages.size() == 0) {
+  private void loadUserDefinedCommands() {
+    String[] userCommandPackages = getUserCommandPackages().toArray(new String[] {});
+
+    if (userCommandPackages.length == 0) {
       return;
     }
 
     // Load commands found in all of the packages
-    try {
-      Set<Class<?>> foundClasses = scanner.scanPackagesForClassesImplementing(CommandMarker.class,
-          restrictedToPackages.toArray(new String[] {}));
+    try (ClasspathScanLoadHelper scanner = new ClasspathScanLoadHelper(userCommandPackages)) {
+      Set<Class<?>> foundClasses =
+          scanner.scanPackagesForClassesImplementing(CommandMarker.class, userCommandPackages);

Review comment:
       Yes, you are correct that the preemptive initialization of the command, without actually using it, would be slightly faster. But also, given that the number of "userCommandPackages" are unknown here and most likely never going to be populated is a safe bet to do this. In addition I don't think this feature has been documented (but I might be wrong, but I'm not going to go through 1000+ pages of documentation to prove it right/wrong), I doubt this path is ever used. BUT I am keeping it here, just in case a user might actually be using this functionality.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] kohlmu-pivotal commented on a change in pull request #6423: GEODE-9227: Performance improvements in the loading of CommandMarkers…

Posted by GitBox <gi...@apache.org>.
kohlmu-pivotal commented on a change in pull request #6423:
URL: https://github.com/apache/geode/pull/6423#discussion_r626986611



##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -112,12 +121,10 @@ private static void raiseExceptionIfEmpty(Set<Class<?>> foundClasses, String err
     }
 
     // Find by packages specified in the distribution config
-    if (this.cacheProperties != null) {
-      String cacheUserCmdPackages =
-          this.cacheProperties.getProperty(ConfigurationProperties.USER_COMMAND_PACKAGES);
-      if (cacheUserCmdPackages != null && !cacheUserCmdPackages.isEmpty()) {
-        userCommandSources.add(cacheUserCmdPackages);
-      }
+    String cacheUserCmdPackages =

Review comment:
       `cacheProperties` is initialized to empty Properties on line 75




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] agingade commented on a change in pull request #6423: GEODE-9227: Performance improvements in the loading of CommandMarkers…

Posted by GitBox <gi...@apache.org>.
agingade commented on a change in pull request #6423:
URL: https://github.com/apache/geode/pull/6423#discussion_r627685135



##########
File path: geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java
##########
@@ -112,12 +121,10 @@ private static void raiseExceptionIfEmpty(Set<Class<?>> foundClasses, String err
     }
 
     // Find by packages specified in the distribution config
-    if (this.cacheProperties != null) {
-      String cacheUserCmdPackages =
-          this.cacheProperties.getProperty(ConfigurationProperties.USER_COMMAND_PACKAGES);
-      if (cacheUserCmdPackages != null && !cacheUserCmdPackages.isEmpty()) {
-        userCommandSources.add(cacheUserCmdPackages);
-      }
+    String cacheUserCmdPackages =
+        this.cacheProperties.getProperty(ConfigurationProperties.USER_COMMAND_PACKAGES, "");
+    if (!cacheUserCmdPackages.isEmpty()) {

Review comment:
       Is there a null check requirement here...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org