runzhiwang opened a new pull request #102:
URL: https://github.com/apache/incubator-ratis/pull/102


   **What's the problem  ?**
   
   
![](https://issues.apache.org/jira/secure/attachment/13003174/13003174_screenshot-1.png)
   
   **What's the reason ?**
   One server was elected as leader twice. Every time leader will try to 
[addNumPendingRequestsByteSize {registry.gauge(REQUEST_BYTE_SIZE, () -> 
byteSize) } 
](https://github.com/apache/incubator-ratis/blob/master/ratis-server/src/main/java/org/apache/ratis/server/impl/PendingRequests.java#L91)
 with a new `RequestLimits`. 
   But in the second time, it can not re-guage again, because the gauge in 
metrics was implemented by `getOrAdd` as the following code shows. So it will 
first check whether `REQUEST_BYTE_SIZE` exist, if exist, it will not `gauge` it 
again. So the `byteSize` is the old RequestLimits's,  and can not update when 
`addPendingRequest`, so assert failed.
   ```
       public Gauge gauge(String name, final MetricSupplier<Gauge> supplier) {
           return getOrAdd(name, new MetricBuilder<Gauge>() {
               @Override
               public Gauge newMetric() {
                   return supplier.newMetric();
               }
               @Override
               public boolean isInstance(Metric metric) {
                   return Gauge.class.isInstance(metric);
               }
           });
       }
   ```


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

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


Reply via email to