concourse
concourse copied to clipboard
RangeLocks coalesce connected ranges and therefore can remove too much protection when unlocked
The isRangeBlocked
logic relies on a collection that does not keep track of distinct locked ranges when they are connected. As a result, when a range lock is released, protection is removed from the intersection of ranges protected by other held range locks.
In RangeLockServiceTest.java
@Test
public void testRangeLocksKeepTrackOfDistinctRangesEvenWhenConnected() {
String key = "foo";
Lock a = rangeLockService.getReadLock(key, Operator.LESS_THAN_OR_EQUALS,
Convert.javaToThrift(10));
Lock b = rangeLockService.getReadLock(key, Operator.GREATER_THAN,
Convert.javaToThrift(5));
a.lock();
b.lock();
RangeToken token = RangeToken.forWriting(Text.wrap(key),
Value.wrap(Convert.javaToThrift(7)));
Assert.assertTrue(
rangeLockService.isRangeBlocked(LockType.WRITE, token));
b.unlock();
Assert.assertTrue(
rangeLockService.isRangeBlocked(LockType.WRITE, token));
}