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

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

                Author: ASF GitHub Bot
            Created on: 13/Jun/22 13:28
            Start Date: 13/Jun/22 13:28
    Worklog Time Spent: 10m 
      Work Description: clebertsuconic commented on code in PR #4101:
URL: https://github.com/apache/activemq-artemis/pull/4101#discussion_r895716470


##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PageReadWriter.java:
##########
@@ -0,0 +1,281 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.core.paging.impl;
+
+import java.nio.ByteBuffer;
+import java.util.function.Consumer;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper;
+import org.apache.activemq.artemis.core.io.SequentialFile;
+import org.apache.activemq.artemis.core.io.SequentialFileFactory;
+import org.apache.activemq.artemis.core.paging.PagedMessage;
+import org.apache.activemq.artemis.core.persistence.StorageManager;
+import org.apache.activemq.artemis.core.server.LargeServerMessage;
+import org.apache.activemq.artemis.utils.DataConstants;
+import org.apache.activemq.artemis.utils.Env;
+import org.jboss.logging.Logger;
+
+public class PageReadWriter {
+
+
+   private static Logger logger = Logger.getLogger(PageReadWriter.class);
+
+   public static final int SIZE_RECORD = DataConstants.SIZE_BYTE + 
DataConstants.SIZE_INT + DataConstants.SIZE_BYTE;
+
+   private static final byte START_BYTE = (byte) '{';
+
+   private static final byte END_BYTE = (byte) '}';
+
+   //sizeOf(START_BYTE) + sizeOf(MESSAGE LENGTH) + sizeOf(END_BYTE)
+   private static final int HEADER_AND_TRAILER_SIZE = DataConstants.SIZE_INT + 
2;
+   private static final int MINIMUM_MSG_PERSISTENT_SIZE = 
HEADER_AND_TRAILER_SIZE;
+   private static final int HEADER_SIZE = HEADER_AND_TRAILER_SIZE - 1;
+   private static final int MIN_CHUNK_SIZE = Env.osPageSize();
+
+   public interface SuspectFileCallback {
+      void onSuspect(String fileName, int position, int msgNumber);
+   }
+
+   public interface PageRecordFilter {
+      boolean skip(ActiveMQBuffer buffer);
+   }
+
+   public interface ReadCallback {
+      void readComple(int size);
+   }
+
+   public static final PageRecordFilter ONLY_LARGE = (buffer) -> 
!PagedMessageImpl.isLargeMessage(buffer);
+
+   public static final PageRecordFilter NO_SKIP = (buffer) -> false;
+
+   public static final PageRecordFilter SKIP_ALL = (buffer) -> true;
+
+   public static int writeMessage(PagedMessage message, SequentialFileFactory 
fileFactory, SequentialFile file) throws Exception {
+      final int messageEncodedSize = message.getEncodeSize();
+      final int bufferSize = messageEncodedSize + SIZE_RECORD;
+      final ByteBuffer buffer = fileFactory.newBuffer(bufferSize);
+      ChannelBufferWrapper activeMQBuffer = new 
ChannelBufferWrapper(Unpooled.wrappedBuffer(buffer));
+      activeMQBuffer.clear();
+      activeMQBuffer.writeByte(START_BYTE);
+      activeMQBuffer.writeInt(messageEncodedSize);
+      message.encode(activeMQBuffer);
+      activeMQBuffer.writeByte(END_BYTE);
+      assert (activeMQBuffer.readableBytes() == bufferSize) : 
"messageEncodedSize is different from expected";
+      //buffer limit and position are the same
+      assert (buffer.remaining() == bufferSize) : "buffer position or limit 
are changed";
+      file.writeDirect(buffer, false);
+      return bufferSize;
+   }
+
+
+

Review Comment:
   I am just moving what was on Page here. not new code!
   
   It's not my original code, but I will see where I would do some spaces.





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

    Worklog Id:     (was: 780819)
    Time Spent: 4h 50m  (was: 4h 40m)

> Add Option to read messages into paging based on sizing and eliminate caching
> -----------------------------------------------------------------------------
>
>                 Key: ARTEMIS-3850
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-3850
>             Project: ActiveMQ Artemis
>          Issue Type: New Feature
>    Affects Versions: 2.22.0
>            Reporter: Clebert Suconic
>            Assignee: Clebert Suconic
>            Priority: Major
>             Fix For: 2.24.0
>
>          Time Spent: 4h 50m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to