kvserver: read lease under mutex when switching lease type
A race could occur when a replica queue and post lease application both attempted to switch the lease type. This race would cause the queue to not process the replica because the lease type had already changed. As a result, lease preference violations might not have been quickly resolved by the lease queue.
Read the lease under the same mutex used for requesting the lease, when possibly switching the lease type.
Resolves: #123998 Release note: None
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?
:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.
This passes 10/10 tests for lease-preferences/manual-violating-transfer. Previously, it would fail 1/3 of the time.
bors r=nvanbenschoten