[ 
https://issues.apache.org/jira/browse/ARTEMIS-2617?focusedWorklogId=384663&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-384663
 ]

ASF GitHub Bot logged work on ARTEMIS-2617:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 10/Feb/20 19:21
            Start Date: 10/Feb/20 19:21
    Worklog Time Spent: 10m 
      Work Description: tabish121 commented on pull request #2975: ARTEMIS-2617 
Improve AMQP Journal loading
URL: https://github.com/apache/activemq-artemis/pull/2975#discussion_r377264471
 
 

 ##########
 File path: 
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java
 ##########
 @@ -1183,8 +1219,126 @@ public Object getCorrelationID() {
       return this;
    }
 
+   /**
+    * 
https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm jump 
table
+    */
+   private static int[] createJumpTable(byte[] needle) {
+      final int[] jumpTable = new int[needle.length + 1];
+      int j = 0;
+      for (int i = 1; i < needle.length; i++) {
+         while (j > 0 && needle[j] != needle[i]) {
+            j = jumpTable[j];
+         }
+         if (needle[j] == needle[i]) {
+            j++;
+         }
+         jumpTable[i + 1] = j;
+      }
+      for (int i = 1; i < jumpTable.length; i++) {
+         if (jumpTable[i] != 0) {
+            return jumpTable;
+         }
+      }
+      // optimization over the original algorithm: it would save from 
accessing any jump table
+      return null;
+   }
+
+   /**
+    * 
https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm 
search algorithm
+    */
+   private static int indexOf(ReadableBuffer haystack, int start, int end, 
byte[] needle, int[] jumpTable) {
+      final long length = end - start;
+      int j = 0;
+      final int needleLength = needle.length;
+      for (int i = 0; i < length; i++) {
+         final int index = start + i;
+         final byte value = haystack.get(index);
+         while (j > 0 && needle[j] != value) {
+            j = jumpTable == null ? 0 : jumpTable[j];
+         }
+         if (needle[j] == value) {
+            j++;
+         }
+         if (j == needleLength) {
+            final int startMatch = index - needleLength + 1;
+            return startMatch;
+         }
+      }
+      return -1;
+   }
+
+   @Override
+   public boolean hasScheduledDeliveryTime() {
+      if (scheduledTime >= 0) {
+         return true;
+      }
+      return anyMessageAnnotations(SCHEDULED_DELIVERY_SYMBOLS,
+                                   SCHEDULED_DELIVERY_ENCODED,
+                                   SCHEDULED_DELIVERY_JUMP_TABLES);
+   }
+
+   private static boolean isValidSymbolEncoding(Symbol[] symbols, byte[][] 
encodedSymbols) {
+      for (int i = 0, size = symbols.length; i < size; i++) {
+         final Symbol symbol = symbols[i];
+         final byte[] encoded = encodedSymbols[i];
+         if 
(!Arrays.equals(symbol.toString().getBytes(StandardCharsets.US_ASCII), 
encoded)) {
+            return false;
+         }
+      }
+      return true;
+   }
+
+   private boolean anyMessageAnnotations(Symbol[] symbols, byte[][] 
encodedSymbols, int[][] jumpTables) {
+      assert isValidSymbolEncoding(symbols, encodedSymbols);
+      final int count = symbols.length;
+      if (messageDataScanned == SCANNED) {
+         final MessageAnnotations messageAnnotations = this.messageAnnotations;
+         if (messageAnnotations == null) {
+            return false;
+         }
+         Map<Symbol, Object> map = messageAnnotations.getValue();
+         if (map == null) {
+            return false;
+         }
+         for (int i = 0; i < count; i++) {
+            if (map.containsKey(symbols[i])) {
+               return true;
+            }
+         }
+         return false;
+      }
+      // messageDataScanned != SCANNED;
+      final ReadableBuffer data = this.data;
+      DecoderImpl decoder = TLSEncode.getDecoder();
+      final int position = data.position();
+      decoder.setBuffer(data.rewind());
+      try {
+         while (data.hasRemaining()) {
+            TypeConstructor<?> constructor = decoder.readConstructor();
+            if (MessageAnnotations.class.equals(constructor.getTypeClass())) {
 
 Review comment:
   You should account for the message not having any MessageAnnotations 
otherwise you will scan in every type constructor for the follow on sections if 
present for no reason.  There's no requirement that a message have a Message 
Annotations section.  
 
----------------------------------------------------------------
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:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 384663)
    Time Spent: 2h  (was: 1h 50m)

> Improve AMQP Journal loading
> ----------------------------
>
>                 Key: ARTEMIS-2617
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-2617
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>            Reporter: Francesco Nigro
>            Priority: Major
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> Journal loading AMQP messages always force decoding message data thus 
> creating garbage
> on broker startup.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to