eolivelli commented on code in PR #16545:
URL: https://github.com/apache/pulsar/pull/16545#discussion_r932966700


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -17,7 +17,24 @@
  * under the License.
  */
 package org.apache.pulsar.broker.admin.impl;
-
+/**
+ * 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.
+ */

Review Comment:
   oh, I don't know how it happened. removed



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -1569,6 +1590,63 @@ private void 
internalDeleteSubscriptionForNonPartitionedTopic(AsyncResponse asyn
             });
     }
 
+    private void 
internalAnalyzeSubscriptionBacklogForNonPartitionedTopic(AsyncResponse 
asyncResponse,

Review Comment:
   I agree with you, but this whole class is coded this way.
   I am not sure it is worth to change the code style only for one method.
   
   



##########
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java:
##########
@@ -1832,6 +1835,138 @@ void testFindNewestMatching() throws Exception {
                 c1.findNewestMatching(entry -> 
Arrays.equals(entry.getDataAndRelease(), "expired".getBytes(Encoding))));
     }
 
+    @Test(timeOut = 20000)
+    void testScanSingleEntry() throws Exception {
+        testScan(10,1);
+    }
+
+    @Test(timeOut = 30000)
+    void testScanBatchesWithSomeRemainder() throws Exception {
+        testScan(10,3);
+    }
+
+    @Test(timeOut = 30000)
+    void testScanBatches() throws Exception {
+        testScan(10,5);
+    }
+
+    @Test(timeOut = 30000)
+    void testScanBatchWholeLedger() throws Exception {
+        testScan(10,1000);
+    }
+
+    @Test(timeOut = 1000)
+    void testScanBatchEmptyLedger() throws Exception {
+        testScan(0,10);
+    }

Review Comment:
   sure.
   I usually prefer this form while developing tests, because it is easier to 
run single combination of parameters and the method name explains the meaning 
of the test.
   
   I have updated the patch



##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpScan.java:
##########
@@ -0,0 +1,139 @@
+/**
+ * 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.bookkeeper.mledger.impl;
+
+import com.google.common.base.Predicate;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback;
+import org.apache.bookkeeper.mledger.AsyncCallbacks.ScanCallback;
+import org.apache.bookkeeper.mledger.Entry;
+import org.apache.bookkeeper.mledger.ManagedLedgerException;
+import org.apache.bookkeeper.mledger.Position;
+import org.apache.bookkeeper.mledger.ScanOutcome;
+import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.PositionBound;
+
+@Slf4j
+class OpScan implements ReadEntriesCallback {
+    private final ManagedCursorImpl cursor;
+    private final ManagedLedgerImpl ledger;
+    private final PositionImpl startPosition;

Review Comment:
   good catch, removed



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -2382,6 +2460,35 @@ protected void 
internalUpdateSubscriptionProperties(AsyncResponse asyncResponse,
         });
     }
 
+    protected void internalAnalyzeSubscriptionBacklog(AsyncResponse 
asyncResponse, String subName,
+                                                      Optional<Position> 
position,
+                                                      boolean authoritative) {
+        CompletableFuture<Void> future;
+        if (topicName.isGlobal()) {
+            future = validateGlobalNamespaceOwnershipAsync(namespaceName);
+        } else {
+            future = CompletableFuture.completedFuture(null);
+        }
+
+        future.thenCompose(__ -> validateTopicOwnershipAsync(topicName, 
authoritative)).thenAccept(__ -> {
+            if (!topicName.isPartitioned() && 
getPartitionedTopicMetadata(topicName,
+                    authoritative, false).partitions > 0) {
+                throw new RestException(Status.METHOD_NOT_ALLOWED,
+                        "Analyze backlog on a partitioned topic is not 
allowed, "
+                                + "please try do it on specific topic 
partition");
+            }

Review Comment:
   other methods check if the topic is partitioned in this same place.
   if the broker is not the owner we will be redirected to another broker and 
we won't reach this point.
   
   I notice that getPartitionedTopicMetadata is sync, I have reworked this part 
to make it fully async
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to