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 2022/05/07 18:19:53 UTC

[GitHub] [pulsar] merlimat commented on a diff in pull request #15488: [enh] Exclusive Producer: ability to fence out an existing Producer (ExclusiveWithFencing mode)

merlimat commented on code in PR #15488:
URL: https://github.com/apache/pulsar/pull/15488#discussion_r867379604


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ExclusiveProducerTest.java:
##########
@@ -118,7 +120,22 @@ private void simpleTest(String topic) throws Exception {
                 .topic(topic)
                 .accessMode(ProducerAccessMode.Exclusive)
                 .create();
-        p2.close();
+
+        Producer<String> p3 = pulsarClient.newProducer(Schema.STRING)
+                .topic(topic)
+                .accessMode(ProducerAccessMode.ExclusiveWithFencing)
+                .create();
+
+        try {
+            p2.send("test");
+            fail("Should have failed");
+        } catch (ProducerFencedException expected) {
+        }
+
+        // this should work
+        p3.send("test");
+        p3.close();

Review Comment:
   I'd also add a test to verify that any queued up producer is also immediately fenced. eg: mixing up `WaitForExclusive` & `ExclusiveWithFencing`



##########
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerAccessMode.java:
##########
@@ -33,6 +33,11 @@ public enum ProducerAccessMode {
      */
     Exclusive,
 
+    /**
+     * Require exclusive access for producer. Fence out the old producer.

Review Comment:
   I think many people might not be super familiar with the word "fencing" :)
   
   ```suggestion
        * Acquire exclusive access for the producer. Any existing producer will be immediately
        * fenced off and will not be able to publish anymore.
   ```



##########
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerBuilder.java:
##########
@@ -133,6 +133,8 @@
      * <li>{@link ProducerAccessMode#Shared}: By default multiple producers can publish on a topic
      * <li>{@link ProducerAccessMode#Exclusive}: Require exclusive access for producer. Fail immediately if there's
      * already a producer connected.
+     * <li>{@link ProducerAccessMode#ExclusiveWithFencing}: Require exclusive access for producer. Fence out any
+     * producer that is connected.

Review Comment:
   ```suggestion
        * <li>{@link ProducerAccessMode#ExclusiveWithFencing}: Acquire exclusive access for the producer. 
        * Any existing producer will be immediately fenced off and will not be able to publish anymore.
   ```



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org