You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/05/21 18:24:01 UTC

[GitHub] [pulsar] merlimat commented on a change in pull request #4329: Moved entries filtering from consumer to dispatcher

merlimat commented on a change in pull request #4329: Moved entries filtering from consumer to dispatcher
URL: https://github.com/apache/pulsar/pull/4329#discussion_r286163074
 
 

 ##########
 File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractBaseDispatcher.java
 ##########
 @@ -0,0 +1,116 @@
+/**
+ * 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
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.pulsar.broker.service;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.util.concurrent.FastThreadLocal;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.bookkeeper.mledger.Entry;
+import org.apache.bookkeeper.mledger.impl.PositionImpl;
+import org.apache.pulsar.common.api.Commands;
+import org.apache.pulsar.common.api.proto.PulsarApi.CommandAck.AckType;
+import org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata;
+
+public abstract class AbstractBaseDispatcher {
+
+    protected final Subscription subscription;
+
+    protected AbstractBaseDispatcher(Subscription subscription) {
+        this.subscription = subscription;
+    }
+
+    /**
+     * Filter messages that are being sent to a consumers.
+     * <p>
+     * Messages can be filtered out for multiple reasons:
+     * <ul>
+     * <li>Checksum or metadata corrupted
+     * <li>Message is an internal marker
+     * <li>Message is not meant to be delivered immediately
+     * </ul>
+     *
+     * @param entries
+     *            a list of entries as read from storage
+     *
+     * @param batchSizes
+     *            an array where the batch size for each entry (the number of messages within an entry) is stored. This
+     *            array needs to be of at least the same size as the entries list
+     *
+     * @param sendMessageInfo
+     *            an object where the total size in messages and bytes will be returned back to the caller
+     * @param subscription
+     *            the subscription object
+     */
+    public void filterEntriesForConsumer(List<Entry> entries, int[] batchSizes, SendMessageInfo sendMessageInfo) {
+        checkArgument(batchSizes.length >= entries.size());
+        int totalMessages = 0;
+        long totalBytes = 0;
+
+        for (int i = 0, entriesSize = entries.size(); i < entriesSize; i++) {
+            Entry entry = entries.get(i);
+            ByteBuf metadataAndPayload = entry.getDataBuffer();
+            PositionImpl pos = (PositionImpl) entry.getPosition();
+
+            MessageMetadata msgMetadata = Commands.peekMessageMetadata(metadataAndPayload, subscription.toString(), -1);
+
+            try {
+                if (msgMetadata == null) {
+                    // Message metadata was corrupted
+                    entries.set(i, null);
+                    entry.release();
+                    subscription.acknowledgeMessage(Collections.singletonList(pos), AckType.Individual,
 
 Review comment:
   This is already logged in the metadata parsing method

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


With regards,
Apache Git Services