void-ptr974 commented on code in PR #26108:
URL: https://github.com/apache/pulsar/pull/26108#discussion_r3492372213


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/GeoPersistentReplicator.java:
##########
@@ -256,7 +256,23 @@ protected boolean replicateEntries(List<Entry> entries, 
final InFlightTask inFli
 
                 headersAndPayload.retain();
 
-                CompletableFuture<SchemaInfo> schemaFuture = 
getSchemaInfo(msg);
+                CompletableFuture<SchemaInfo> schemaFuture;
+                try {
+                    schemaFuture = getSchemaInfo(msg);
+                } catch (Exception e) {

Review Comment:
   Would it be better to narrow this catch to the expected exception type? 
Since `getSchemaInfo` only declares `ExecutionException`, catching all 
`Exception`s could accidentally turn unrelated bugs into schema retry loops. 
Another option might be to normalize `getSchemaInfo` to return a failed future 
and then reuse the existing `schemaFuture.isCompletedExceptionally()` path.



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/GeoPersistentReplicatorTest.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.persistent;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Answers.RETURNS_SELF;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.apache.bookkeeper.mledger.Entry;
+import org.apache.bookkeeper.mledger.ManagedCursor;
+import org.apache.bookkeeper.mledger.Position;
+import org.apache.bookkeeper.mledger.PositionFactory;
+import org.apache.pulsar.broker.PulsarServerException;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.service.BrokerService;
+import 
org.apache.pulsar.broker.service.persistent.PersistentReplicator.InFlightTask;
+import org.apache.pulsar.client.admin.PulsarAdmin;
+import org.apache.pulsar.client.api.ProducerBuilder;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.impl.MessageImpl;
+import org.apache.pulsar.client.impl.ProducerImpl;
+import org.apache.pulsar.client.impl.PulsarClientImpl;
+import org.apache.pulsar.common.api.proto.MessageMetadata;
+import org.apache.pulsar.common.protocol.Commands;
+import org.apache.pulsar.common.schema.SchemaInfo;
+import org.testng.annotations.Test;
+
+@Test(groups = "broker-replication")
+public class GeoPersistentReplicatorTest {
+
+    @Test
+    public void testSchemaInfoSynchronousFailureCompletesCurrentEntry() throws 
Exception {
+        ThrowingSchemaReplicator replicator = new ThrowingSchemaReplicator();
+        replicator.forceStarted();
+
+        Position position = PositionFactory.create(1, 2);
+        ByteBuf headersAndPayload = newMessageWithSchemaVersion();
+        Entry entry = mock(Entry.class);
+        when(entry.getLength()).thenReturn(headersAndPayload.readableBytes());
+        when(entry.getDataBuffer()).thenReturn(headersAndPayload);
+        when(entry.getPosition()).thenReturn(position);
+        when(entry.getLedgerId()).thenReturn(position.getLedgerId());
+        when(entry.getEntryId()).thenReturn(position.getEntryId());
+        doAnswer(invocation -> {
+            headersAndPayload.release();
+            return null;
+        }).when(entry).release();
+
+        List<Entry> entries = List.of(entry);

Review Comment:
   This test only covers the current entry cleanup. It does not verify the 
batch behavior after `skipRemainingMessages` is set.
   
   Please extend it to use a multi-entry batch and verify that the remaining 
entries are skipped/released, `completedEntries` reaches the full batch size, 
and the cursor is rewound.



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/GeoPersistentReplicator.java:
##########
@@ -256,7 +256,23 @@ protected boolean replicateEntries(List<Entry> entries, 
final InFlightTask inFli
 
                 headersAndPayload.retain();
 
-                CompletableFuture<SchemaInfo> schemaFuture = 
getSchemaInfo(msg);
+                CompletableFuture<SchemaInfo> schemaFuture;
+                try {
+                    schemaFuture = getSchemaInfo(msg);
+                } catch (Exception e) {
+                    log.warn()
+                            .attr("position", entry.getPosition())
+                            .exception(e)
+                            .log("Failed to get schema from local cluster, 
will try in the next loop");
+                    
beforeTerminateOrCursorRewinding(ReasonOfWaitForCursorRewinding.Fetching_Schema);
+                    inFlightTask.incCompletedEntries();
+                    entry.release();
+                    headersAndPayload.release();
+                    msg.recycle();
+                    skipRemainingMessages = true;
+                    doRewindCursor(false);

Review Comment:
   This path can immediately rewind and re-read the same entry if the 
synchronous schema lookup failure persists. `replicateEntries()` returns false, 
so `readEntriesComplete()` may call `readMoreEntries()` right away.
   
   One way to avoid a tight retry loop is to keep the replicator in the 
cursor-rewinding wait state and schedule `doRewindCursor(true)` after a small 
backoff instead of rewinding immediately.



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