cinchapi / concourse

Distributed database warehouse for transactions, search and analytics across time.
http://concoursedb.com
Apache License 2.0
315 stars 235 forks source link

RangeLocks coalesce connected ranges and therefore can remove too much protection when unlocked #491

Closed jtnelson closed 1 year ago

jtnelson commented 1 year ago

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));
    }