Versions Compared

Key

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

...

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

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.