You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by si...@apache.org on 2019/05/20 02:58:14 UTC

[pulsar] branch master updated: Fixed record latency before recycling in broker-side producer handler (#4309)

This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new cacb16a  Fixed record latency before recycling in broker-side producer handler (#4309)
cacb16a is described below

commit cacb16abfdf84c1347536301e456bf1f43bc9bac
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Sun May 19 19:58:09 2019 -0700

    Fixed record latency before recycling in broker-side producer handler (#4309)
    
    ### Motivation
    
    In #4290 the latency was collected after the context object is triggered in a separate thread. By the time we try to use the producer object it might have been already recycled.
---
 .../src/main/java/org/apache/pulsar/broker/service/Producer.java        | 2 +-
 .../org/apache/pulsar/broker/service/persistent/PersistentTopic.java    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
index fa839a6..c3fe420 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java
@@ -307,8 +307,8 @@ public class Producer {
 
                 this.ledgerId = ledgerId;
                 this.entryId = entryId;
-                producer.cnx.ctx().channel().eventLoop().execute(this);
                 producer.topic.recordAddLatency(TimeUnit.NANOSECONDS.toMicros(System.nanoTime() - startTimeNs));
+                producer.cnx.ctx().channel().eventLoop().execute(this);
             }
         }
 
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
index c8e5c7e..4cbcf11 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
@@ -188,7 +188,7 @@ public class PersistentTopic implements Topic, AddEntryCallback {
         SchemaCompatibilityStrategy.FULL;
     // schema validation enforced flag
     private volatile boolean schemaValidationEnforced = false;
-    private StatsBuckets addEntryLatencyStatsUsec = new StatsBuckets(ENTRY_LATENCY_BUCKETS_USEC);
+    private final StatsBuckets addEntryLatencyStatsUsec = new StatsBuckets(ENTRY_LATENCY_BUCKETS_USEC);
 
     private static final FastThreadLocal<TopicStatsHelper> threadLocalTopicStats = new FastThreadLocal<TopicStatsHelper>() {
         @Override