Denovo1998 commented on code in PR #26108:
URL: https://github.com/apache/pulsar/pull/26108#discussion_r3499017161


##########
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:
   Agreed. The exceptional schema future path now keeps the replicator in the 
cursor-rewinding wait state and schedules doRewindCursor(true) after 
MESSAGE_RATE_BACKOFF_MS. Successful schema fetches still rewind immediately.



##########
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:
   Good point. I narrowed the catch to ExecutionException and normalize that 
synchronous schema lookup failure into a failed future, so unexpected 
exceptions are no longer converted into schema retry loops while the existing 
schema future cleanup path is reused.



##########
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:
   Extended the regression test to use a multi-entry batch. It now verifies the 
remaining entry is skipped and released, completedEntries reaches the full 
batch size, and cursor rewind/read retry is triggered only by the scheduled 
backoff task.



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