You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by GitBox <gi...@apache.org> on 2021/07/02 12:58:41 UTC

[GitHub] [jackrabbit-oak] averma21 opened a new pull request #311: OAK-9480 - Log a warning for improper usage of an index with valueRege…

averma21 opened a new pull request #311:
URL: https://github.com/apache/jackrabbit-oak/pull/311


   …x set


-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] averma21 merged pull request #311: OAK-9480 - Log a warning for improper usage of an index with valueRege…

Posted by GitBox <gi...@apache.org>.
averma21 merged pull request #311:
URL: https://github.com/apache/jackrabbit-oak/pull/311


   


-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] averma21 commented on a change in pull request #311: OAK-9480 - Log a warning for improper usage of an index with valueRege…

Posted by GitBox <gi...@apache.org>.
averma21 commented on a change in pull request #311:
URL: https://github.com/apache/jackrabbit-oak/pull/311#discussion_r667886850



##########
File path: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndex.java
##########
@@ -353,6 +356,10 @@ default boolean logWarningForPathFilterMismatch() {
             return false;
         }
 
+        default Map<Level, List<String>> getAdditionalMessages() {

Review comment:
       done.

##########
File path: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndex.java
##########
@@ -491,6 +510,17 @@ public IndexPlan build() {
                     private final boolean deprecated =
                             Builder.this.deprecated;
                     private final boolean logWarningForPathFilterMismatch = Builder.this.logWarningForPathFilterMismatch;
+                    private final Map<Level, List<String>> additionalMessages = Builder.this.additionalMessages;
+
+                    private String getAdditionalMessageString() {
+                        StringBuilder stringBuilder = new StringBuilder();

Review comment:
       Fixed. thanks!

##########
File path: oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
##########
@@ -290,13 +292,31 @@ public static void setUseActualEntryCount(boolean useActualEntryCount) {
 
             IndexPlan.Builder plan = defaultPlan();
 
+            if (plan == null) {
+                return null;
+            }
+
             if (filter.getQueryLimits().getStrictPathRestriction().equals(StrictPathRestriction.WARN.name()) && !isPlanWithValidPathFilter()) {
                 plan.setLogWarningForPathFilterMismatch(true);
             }
 
-            if (plan == null) {
-                return null;
+            Pattern queryFilterPattern = definition.getQueryFilterRegex() != null ? definition.getQueryFilterRegex() :
+                    definition.getPropertyRegex();
+
+            if (queryFilterPattern != null) {
+                if (ft != null && !queryFilterPattern.matcher(ft.toString()).find()) {
+                    plan.addAdditionalMessage(Level.WARN, "Potentially improper use of index " + definition.getIndexPath() + " with valueRegex "

Review comment:
       done.

##########
File path: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndex.java
##########
@@ -491,6 +510,17 @@ public IndexPlan build() {
                     private final boolean deprecated =
                             Builder.this.deprecated;
                     private final boolean logWarningForPathFilterMismatch = Builder.this.logWarningForPathFilterMismatch;
+                    private final Map<Level, List<String>> additionalMessages = Builder.this.additionalMessages;
+
+                    private String getAdditionalMessageString() {
+                        StringBuilder stringBuilder = new StringBuilder();
+                        for (Map.Entry<Level, List<String>> messages : additionalMessages.entrySet()) {
+                            stringBuilder.append(messages.getKey()).append(" : ").append(messages.getValue()).append(", ");

Review comment:
       Fixed, thanks!




-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] fabriziofortino commented on a change in pull request #311: OAK-9480 - Log a warning for improper usage of an index with valueRege…

Posted by GitBox <gi...@apache.org>.
fabriziofortino commented on a change in pull request #311:
URL: https://github.com/apache/jackrabbit-oak/pull/311#discussion_r663995765



##########
File path: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndex.java
##########
@@ -491,6 +510,17 @@ public IndexPlan build() {
                     private final boolean deprecated =
                             Builder.this.deprecated;
                     private final boolean logWarningForPathFilterMismatch = Builder.this.logWarningForPathFilterMismatch;
+                    private final Map<Level, List<String>> additionalMessages = Builder.this.additionalMessages;
+
+                    private String getAdditionalMessageString() {
+                        StringBuilder stringBuilder = new StringBuilder();

Review comment:
       I don't think this is completely safe. If there are no additional messages, the StringBuilder would call `deleteCharAt` with a negative value. You could make it more concise and functional using streams
   
   ```java
   private String getAdditionalMessageString() {
       return additionalMessages.entrySet().stream()
               .map(e -> e.getKey() + " : " + e.getValue())
               .collect(Collectors.joining(", "));
   }
   ```

##########
File path: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndex.java
##########
@@ -353,6 +356,10 @@ default boolean logWarningForPathFilterMismatch() {
             return false;
         }
 
+        default Map<Level, List<String>> getAdditionalMessages() {

Review comment:
       can you add some javadoc 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.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] thomasmueller commented on a change in pull request #311: OAK-9480 - Log a warning for improper usage of an index with valueRege…

Posted by GitBox <gi...@apache.org>.
thomasmueller commented on a change in pull request #311:
URL: https://github.com/apache/jackrabbit-oak/pull/311#discussion_r665395725



##########
File path: oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
##########
@@ -290,13 +292,31 @@ public static void setUseActualEntryCount(boolean useActualEntryCount) {
 
             IndexPlan.Builder plan = defaultPlan();
 
+            if (plan == null) {
+                return null;
+            }
+
             if (filter.getQueryLimits().getStrictPathRestriction().equals(StrictPathRestriction.WARN.name()) && !isPlanWithValidPathFilter()) {
                 plan.setLogWarningForPathFilterMismatch(true);
             }
 
-            if (plan == null) {
-                return null;
+            Pattern queryFilterPattern = definition.getQueryFilterRegex() != null ? definition.getQueryFilterRegex() :
+                    definition.getPropertyRegex();
+
+            if (queryFilterPattern != null) {
+                if (ft != null && !queryFilterPattern.matcher(ft.toString()).find()) {
+                    plan.addAdditionalMessage(Level.WARN, "Potentially improper use of index " + definition.getIndexPath() + " with valueRegex "

Review comment:
       It would use " with queryFilterRegex "

##########
File path: oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
##########
@@ -290,13 +292,31 @@ public static void setUseActualEntryCount(boolean useActualEntryCount) {
 
             IndexPlan.Builder plan = defaultPlan();
 
+            if (plan == null) {
+                return null;
+            }
+
             if (filter.getQueryLimits().getStrictPathRestriction().equals(StrictPathRestriction.WARN.name()) && !isPlanWithValidPathFilter()) {
                 plan.setLogWarningForPathFilterMismatch(true);
             }
 
-            if (plan == null) {
-                return null;
+            Pattern queryFilterPattern = definition.getQueryFilterRegex() != null ? definition.getQueryFilterRegex() :
+                    definition.getPropertyRegex();
+
+            if (queryFilterPattern != null) {
+                if (ft != null && !queryFilterPattern.matcher(ft.toString()).find()) {
+                    plan.addAdditionalMessage(Level.WARN, "Potentially improper use of index " + definition.getIndexPath() + " with valueRegex "
+                            + queryFilterPattern + " to search for value " + ft.toString());
+                }
+                 for (PropertyRestriction pr : filter.getPropertyRestrictions()) {
+                    if (!queryFilterPattern.matcher(pr.toString()).find()) {
+                        plan.addAdditionalMessage(Level.WARN, "Potentially improper use of index " + definition.getIndexPath() + " with valueRegex "

Review comment:
       It would use " with queryFilterRegex "

##########
File path: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndex.java
##########
@@ -491,6 +510,17 @@ public IndexPlan build() {
                     private final boolean deprecated =
                             Builder.this.deprecated;
                     private final boolean logWarningForPathFilterMismatch = Builder.this.logWarningForPathFilterMismatch;
+                    private final Map<Level, List<String>> additionalMessages = Builder.this.additionalMessages;
+
+                    private String getAdditionalMessageString() {
+                        StringBuilder stringBuilder = new StringBuilder();
+                        for (Map.Entry<Level, List<String>> messages : additionalMessages.entrySet()) {
+                            stringBuilder.append(messages.getKey()).append(" : ").append(messages.getValue()).append(", ");

Review comment:
       Fabrizios approach is fine... if you want to use a loop, it would have to be like this (I didn't test):
   
       StringBuilder buff = new StringBuilder();
       for (Map.Entry<Level, List<String>> messages : additionalMessages.entrySet()) {
           if (!buff.isEmpty()) {
               buff.append(", ");
           }
           buff.append(messages.getKey() + " : " + messages.getValue());
       }
       return buff.toString();
   
   I'm not saying it's better that Fabrizios approach... just that this would be the "common" approach when using a loop.




-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] fabriziofortino commented on a change in pull request #311: OAK-9480 - Log a warning for improper usage of an index with valueRege…

Posted by GitBox <gi...@apache.org>.
fabriziofortino commented on a change in pull request #311:
URL: https://github.com/apache/jackrabbit-oak/pull/311#discussion_r663995765



##########
File path: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndex.java
##########
@@ -491,6 +510,17 @@ public IndexPlan build() {
                     private final boolean deprecated =
                             Builder.this.deprecated;
                     private final boolean logWarningForPathFilterMismatch = Builder.this.logWarningForPathFilterMismatch;
+                    private final Map<Level, List<String>> additionalMessages = Builder.this.additionalMessages;
+
+                    private String getAdditionalMessageString() {
+                        StringBuilder stringBuilder = new StringBuilder();

Review comment:
       I don't think this is completely safe. If there are no additional messages, the StringBuilder would call `deleteCharAt` with a negative value. You could make it more concise and functional using streams
   
   ```java
   private String getAdditionalMessageString() {
       return additionalMessages.entrySet().stream()
               .map(e -> e.getKey() + " : " + e.getValue())
               .collect(Collectors.joining(", "));
   }
   ```

##########
File path: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndex.java
##########
@@ -353,6 +356,10 @@ default boolean logWarningForPathFilterMismatch() {
             return false;
         }
 
+        default Map<Level, List<String>> getAdditionalMessages() {

Review comment:
       can you add some javadoc 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.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] averma21 merged pull request #311: OAK-9480 - Log a warning for improper usage of an index with valueRege…

Posted by GitBox <gi...@apache.org>.
averma21 merged pull request #311:
URL: https://github.com/apache/jackrabbit-oak/pull/311


   


-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] averma21 merged pull request #311: OAK-9480 - Log a warning for improper usage of an index with valueRege…

Posted by GitBox <gi...@apache.org>.
averma21 merged pull request #311:
URL: https://github.com/apache/jackrabbit-oak/pull/311


   


-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

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