Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This page is meant as a template for writing a KIP. To create a KIP choose Tools->Copy on this page and modify with your content and replace the heading with the next KIP number and a description of your issue. Replace anything in italics with your own description.

Status

Current state: [One of "Under Discussion", "Accepted", "Rejected"]

Discussion thread: here

JIRA: SensorAccess.getOrCreate should be more efficient 

...

There's no public interfaces to be defined. The change proposed here is to remove a read lock which is completely unnecessary. The read lock is called for each request (at least) from producer, which is really expensive

Proposed Changes

The getOrCreate of SensorAccess class under this folder: core\src\main\scala\kafka\server is using a read like this: 

lock.readLock().lock()

The lock is used to prevent race condition: when a new sensor is created by a writer thread, and the "sensor" variable is not null more, but the initialization of the new sensor object is not finished, if at this moment another thread may gets the sensor object and use it before the sensor initialization is finished. 

But this read lock can be avoided by firstly assigning the new sensor to a temporary variable say "tmp", and then initialized tmp, finally assign temp to the "sensor" variable. By doing this, we can get rid of the read lock. 


Below code and screen shows the code change: 

View file
namecodechange.zip
height250

Describe the new thing you want to do in appropriate detail. This may be fairly extensive and have large subsections of its own. Or it may be a few sentences. Use judgement based on the scope of the change.Image Added


Compatibility, Deprecation, and Migration Plan

...

N/A

Rejected Alternatives

If there are alternative ways of accomplishing the same thing, what were they? The purpose of this section is to motivate why the design is the way it is and not some other way.